f1ce2b39ec0c57bbfb203d430c3dbf87fbc7b514.svn-base 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const options = {
  2. url: "/arcgisApi/4.7/init.js"
  3. };
  4. import * as esriLoader from 'esri-loader'
  5. import {queryLayer} from '../config/lyrConfig.js'
  6. export function xzqChange(_self,viewObject,mapObject,item,fullExtent){
  7. esriLoader.loadModules(["esri/layers/GraphicsLayer","esri/Graphic","esri/geometry/Polygon",
  8. "esri/tasks/support/Query","esri/tasks/QueryTask","dojo/domReady!"],options).then( (
  9. [GraphicsLayer,Graphic,Polygon,Query,QueryTask,]) => {
  10. var url,where,outFields;
  11. if(_self.currentAdCode.substring(2,12) == '0000000000'){//省级
  12. url = queryLayer.province;
  13. where = "prov_cd = '"+item.adCode+"'";
  14. outFields = ["prov_cd","prov_nm"];
  15. // var proBoundaryGraphicLayer = mapObject.findLayerById("proBoundaryGraphicLayer");
  16. // proBoundaryGraphicLayer.removeAll();
  17. // viewObject.extent = fullExtent;
  18. // return;
  19. }else if(_self.currentAdCode.substring(4,12) == '00000000'){//市级
  20. url = queryLayer.city;
  21. where = "dist_cd = '"+item.adCode+"'";
  22. outFields = ["dist_cd","dist_nm"];
  23. }else if(_self.currentAdCode.substring(6,12) == '000000'){//县级
  24. url = queryLayer.country;
  25. where = "cnty_cd = '"+item.adCode+"'";
  26. outFields = ["cnty_nm","cnty_cd"];
  27. }
  28. if(url){
  29. var queryTask = new QueryTask({
  30. url: url
  31. });
  32. var query = new Query();
  33. query.returnGeometry = true;
  34. query.outFields = outFields;
  35. query.where = where;
  36. queryTask.execute(query).then(function(results){
  37. var feature = results.features[0];
  38. var polygon = new Polygon({
  39. rings: feature.geometry.rings,
  40. spatialReference: { wkid: 4326 }
  41. });
  42. var symbol = {
  43. type: "simple-line", // autocasts as new SimpleLineSymbol()
  44. color: "#f02ee7",
  45. width: "2px",
  46. style: "short-dash-dot"
  47. };
  48. var gra = new Graphic({
  49. geometry:polygon,
  50. attributes:feature.attributes,
  51. symbol:symbol
  52. });
  53. var proBoundaryGraphicLayer = mapObject.findLayerById("proBoundaryGraphicLayer");
  54. proBoundaryGraphicLayer.removeAll();
  55. proBoundaryGraphicLayer.add(gra);
  56. viewObject.goTo(gra);
  57. });
  58. }
  59. }).catch(err => {
  60. console.error(err);
  61. });
  62. }