arcgis api for js 3.X版本加载矢量json文件,并缩放至图层
Posted mnxxz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arcgis api for js 3.X版本加载矢量json文件,并缩放至图层相关的知识,希望对你有一定的参考价值。
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文件,并缩放至图层的主要内容,如果未能解决你的问题,请参考以下文章
Arcgis api for javascript学习笔记-初步尝试(3.2X版本)
ArcGIS API for JavaScript 4.6 版本加载高德地