$(function () { console.log("监测评估"); // 添加css var ele = document.createElement("link"); ele.setAttribute("rel", "stylesheet"); ele.setAttribute("href", '/frontweb/js/arcgis_js_api/esri/css/main.css'); document.body.appendChild(ele) $.getScript('/frontweb/js/arcgis_js_api/init.js', function () { // 插入地图绑定元素 var mapEle = document.getElementById('map') if (mapEle) { mapEle.setAttribute("style", "width: 100%;height: 100%;position: absolute;left: 0;right: 0;top: 0;bottom: 0;z-index: 1;"); } else { var ele = document.createElement("div"); ele.setAttribute('id', 'map') ele.setAttribute("style", "width: 100%;height: 100%;position: absolute;left: 0;right: 0;top: 0;bottom: 0;z-index: 1;"); document.body.appendChild(ele) } // iframe 存在 require = window.require || window.parent.require var CONF_FRONT_SERVERURL = window.CONF_FRONT_SERVERURL || window.parent.CONF_FRONT_SERVERURL // let map = window.mapInstance || window.parent.mapInstance // let graphicsLayer = window.graphicsLayerInstance || window.parent.graphicsLayerInstance // let view = window.mapViewInstance || window.parent.mapViewInstance var mapGeom = null require([ "esri/Map", "esri/Basemap", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/layers/TileLayer", "esri/geometry/Extent", // "esri/views/2d/draw/Draw", "esri/Graphic", "esri/geometry/Polyline", "esri/geometry/Polygon", // "esri/geometry/Point", "esri/layers/GraphicsLayer", "esri/layers/MapImageLayer", // "esri/symbols/SimpleLineSymbol", // "esri/symbols/SimpleFillSymbol", // "esri/symbols/TextSymbol", // "esri/Color", // "esri/widgets/Legend", // "esri/widgets/ScaleBar", // "esri/widgets/Search", // "esri/widgets/TimeSlider", "esri/PopupTemplate", "dojo/domReady!" ], function (Map, Basemap, MapView, FeatureLayer, TileLayer, Extent, Graphic, Polyline, Polygon, GraphicsLayer, MapImageLayer, PopupTemplate) { var map = new Map({ basemap: new Basemap({ baseLayers: [new TileLayer({ url: 'http://10.7.120.44:6080/arcgis/rest/services/规划2000/电子地图/MapServer' })] }) }); var view = new MapView({ container: "map", map: map, // center: [108.948024, 34.263161], // longitude, latitude extent: new Extent({ xmin: 438417, ymin: 3725140, xmax: 688512, ymax: 3872165, spatialReference: 4545 }), zoom: 1 }); view.ui.remove('zoom')//清除放大缩小按钮 view.ui.remove('attribution')//清楚底部powered by ESRI // 添加影像地图 // var yxMap = new TileLayer({ // url: 'http://10.6.144.134:6080/arcgis/rest/services/%E5%BD%B1%E5%83%8F%E5%BA%95%E5%9B%BE2000/%E8%A5%BF%E5%AE%89%E5%B8%824/MapServer', // }); // 添加莲湖区地图 // var graphicsLayer = new GraphicsLayer(); // var qxjMap = new FeatureLayer({ // url: "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/区县面/MapServer/0" // }) // map.add(yxMap); // map.add(qxjMap); var listArray = []; $.ajax({ url: 'geojson/allData.json', type: 'GET', async: false, success: function (res) { console.log(res, 'json获取成功') // addPolygon(res); } // }) // view.when(() => { // console.log(123); // // graphicsLayer.graphics.items[6].symbol = new SimpleFillSymbol({ // // color: [118, 255, 0, 1], // // outline: { color: [118, 255, 0, 0.6], width: 3 }, // // }); // }); // // 获取rings path // function getRings(path) { // let rings = [] // path.forEach((item) => { // item.forEach((pathItem) => { // pathItem.forEach((childPathItem) => { // rings.push(childPathItem) // }) // }) // }) // return rings // } // // 增加片区 // function addPolygon(data) { // var fillSymbol = { // type: "simple-fill", // autocasts as new SimpleFillSymbol() // color: [227, 139, 79, 0.8], }) // } window.addEventListener('message', function (res) { const type = res.data.type if (type === 'xzqdm') { const mapGeomData = JSON.parse(mapGeom) let isToggle = false for (let i = 0; i < mapGeomData.length; i++) { let item = mapGeomData[i] if ( item.xzqdm === res.data.data) { if (item.symbol) { isToggle = true break } item.symbol = { // type: "simple-fill", // color: "red", outline: { // autocasts as new SimpleLineSymbol() color: [255, 255, 255], width: 1 } } }; data.forEach(item => { const path = JSON.parse(item.geometry).coordinates; const rings = getRings(path); const polylineAtt = { XZQMC: item.xzqmc, FID: item.gid, type: 'area' }; const polygonGraphic = new Graphic({ geometry: new Polygon({ spatialReference: { wkid: 4545 }, rings: rings }), symbol: fillSymbol }); graphicsLayer.addMany([polygonGraphic]); }) } }; }); }) }) })