import layers from '@/assets/json/layers.json' import graphicSymbol from '@/assets/json/graphicSymbol.json' import queryUtils from "@libs/map/queryUtils"; import {loadModules} from "esri-loader" import {maps} from '@/libs/map/mapUtils' export default { methods:{ getLayerByName(name) { for (var i = 0; i < layers.length; i++) { if (layers[i].layerName == name) { return layers[i]; } } return null; }, addGeoByBsm(bsm, type,viewId) { var self = this; var layer = null; if (type == 'zd') { layer = this.getLayerByName("ZDJBXX"); } else if (type == 'zrz') { layer = this.getLayerByName("ZRZ"); } else { console.log("未定义类型!!"); return; } if (!layer) { console.log("没有找到图层,不能查询"); return; } queryUtils.methods.queryByWhere(layer.layerUrl+"/"+layer.id, {"BSM": bsm }, null, true, null, null, function (res) { var features = res.features; if(features && features.length > 0){ if( !features[0].geometry ){ self.$message.success("暂无图形信息!!"); return; } loadModules([ "esri/layers/GraphicsLayer" ]).then( ([ GraphicsLayer ]) => { var view = maps[viewId]; var layer = view.map.findLayerById("highlightLayer"); if(layer){ layer.removeAll(); }else { layer = new GraphicsLayer({ id:"highlightLayer" }) view.map.add(layer,5); } var symbol = graphicSymbol.fillSymbol.highlightSymbol; var graphic = features[0]; graphic.symbol = symbol; layer.add(graphic); view.center = graphic.geometry.extent.center; }).catch( err => { thow(err); }) }else { self.$message.success("暂无图形信息!!"); return; } }); }, //将查询结果展示在地图上 addSearchResultToMap(searchResult,viewId){ var view = maps[viewId], self = this; loadModules([ "esri/layers/GraphicsLayer" ]).then(([ GraphicsLayer ]) => { if(!searchResult || searchResult.length == 0){ return; } for(var i = 0;i < searchResult.length;i++){ var layer = view.map.findLayerById("searchResult"+searchResult.layerName); if(layer){ layer.removeAll(); }else{ layer = new GraphicsLayer({ id:"searchResult"+searchResult.layerName }) view.map.add(layer); } var symbol = graphicSymbol.fillSymbol.highlightSymbol; var features = searchResult[i].features; for(var j = 0;j < features.length;j++){ features[j].symbol = symbol; layer.add(features[j]); } } }).catch(err=>{ console.log(err); }) }, //缩放至当前对象 extentToGraphic(feature,highlightGraohic,viewId,callBackFunction){ var symbol = graphicSymbol.fillSymbol.highlightSymbol; var highlightSymbol = graphicSymbol.fillSymbol.defaultSymbol; if(highlightGraohic){ highlightGraohic.symbol = symbol; } feature.symbol = highlightSymbol; var view = maps[viewId]; view.center = feature.geometry.type == 'point' ? feature.geometry : feature.geometry.extent.center; if(callBackFunction && typeof callBackFunction == 'function'){ callBackFunction(); } }, clearSearchLayer(viewId){ var view = maps[viewId], layers = view.map.allLayers; layers.filter(function (item) { if(item.id.indexOf("searchResult") != -1){ item.removeAll(); } }); } } }