标签:axios def ril ade int esri div text span
esriLoader.loadModules( [ ‘esri/tasks/FeatureSet‘, ‘esri/layers/FeatureLayer‘, ‘esri/geometry/Point‘, ‘esri/geometry/Polygon‘, ‘esri/geometry/Extent‘, ‘esri/dijit/PopupTemplate‘, ‘esri/dijit/LayerSwipe‘ ], options).then( ([FeatureSet, FeatureLayer, Point, Polygon, Extent, PopupTemplate, LayerSwipe]) => {
//json地址 const jsonUrl = ‘http://Json/‘ + vectorInfo.label + ‘.json‘ axios.get(jsonUrl, { headers: {}, emulateJSON: true }).then((res) => { const layerJson = res.data const layerDefinition = { ‘geometryType‘: layerJson.geometryType, ‘fields‘: layerJson.fields } var featureSet = new FeatureSet(layerJson) var featureCollection = { ‘layerDefinition‘: layerDefinition, ‘featureSet‘: featureSet }
//json转成FeatureLayer
var jsonFeaturelayer = new FeatureLayer(featureCollection) jsonFeaturelayer.id = vectorInfo.vectorId.toString() + ‘_vector‘
//加进图层 self.map.addLayer(jsonFeaturelayer)
//方法一,获取第一个点 var point = new Point(jsonFeaturelayer._graphicsVal[0]._extent.xmin, jsonFeaturelayer._graphicsVal[0]._extent.ymin) self.map.centerAndZoom(point, 8)
//方法二,所有要素的范围合并
// var mapExtent = new Extent() // for (let i = 0; i < jsonFeaturelayer._graphicsVal.length; i++) { // var thisExtent = jsonFeaturelayer._graphicsVal[i].geometry.getExtent() // // 创建范围或先前要素与当前要素的并集 // mapExtent = mapExtent.union(thisExtent) // } // self.map.setExtent(mapExtent) // _extent: {xmin: 119.11746198217094, ymin: 36.89781328847772, xmax: 119.2113266911379, ymax: 36.93355761143819, // self.map.center = [jsonFeaturelayer._graphicsVal[0]._extent.xmin, jsonFeaturelayer._graphicsVal[0]._extent.ymin] // var sGeometry = jsonFeaturelayer.fullExtent // var sGeometry = jsonFeaturelayer._graphicsVal[0]._extent // var ftGeoExt = sGeometry.getExtent() // self.map.setExtent(sGeometry) }) } ).catch(err => { console.error(err) })
arcgis api for js 3.X版本加载矢量json文件,并缩放至图层
标签:axios def ril ade int esri div text span
原文地址:https://www.cnblogs.com/mnxxz/p/11601803.html