• 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) })
  • 相关阅读:
    19c 新特性: Hint Usage Reports详解
    byte buddy学习笔记
    彻底告别“人工+Excel”低效模式,传统制造业实现“一站式”数据化管理
    有的人想在上班之余做兼职,并且不想投入太多钱
    2019你为什不选择创业?是因为什么原因?
    深入理解pandas读取excel,txt,csv文件等命令
    劳务派遣公司是怎么盈利的?
    为什么穷人大多不敢创业?
    30多岁了仍一事无成,除了去工厂上班还有哪些出路?
    MySQL Change Data Directory
  • 原文地址:https://www.cnblogs.com/mnxxz/p/11601803.html
Copyright © 2020-2023  润新知