Arcgis for js4.x图层高亮

638 阅读1分钟

背景

即上次的点位高亮后,项目上的其它页面需要的是通过地图服务加载出来的图层高亮,通过点位高亮的方法带来的灵感,这次就直接画一个点击图层的边框高亮。

注意: arcgis4.x与3.x其中的不同点之一就是当你使用其中某个api市需要单独引用,而不是3.x中的全部引用

有些图层的坐标打印出来显示的是(wkid: 3857) 的,需要使用webMercatorUtils.webMercatorToGeographic来转成(wkid: 4326)的

    this.view.on('click', this.initIdentify)
    initIdentify(eve){
         var identifyTask = new this.IdentifyTask(this.currentMapUrl)
          var params = new this.IdentifyParameters()
          params.tolerance = 0.0000000001
          params.returnGeometry = true
          params.layerIds = this.Ids
          params.layerOption = this.IdentifyParameters.LAYER_OPTION_ALL
          params.geometry = evt.mapPoint
          params.mapExtent = this.map.extent
          let _this = this
          identifyTask.execute(params).then(function(iset) {
            // 调用区域高亮方法
            let geo = _this.webMercatorUtils.webMercatorToGeographic(
              iset.results[0].feature.geometry
            )
           
            //定位
            _this.map.goTo({
              center: [geo.extent.center.x, geo.extent.center.y],
              zoom: 13
            })
            _this.setRedCicle(geo.rings)
          })
    }
    // 将选中区域高亮显示
        setRedCicle(rings) {
            //清除高亮部分
          this.map.graphics.remove(this.Linegraphic)
          var polygon = {
            type: 'polyline', // autocasts as new Polygon()
            paths: rings
          }
          var fillSymbol = {
            type: 'simple-line', // autocasts as new SimpleFillSymbol()
            color: [255, 0, 0, 0.9],
            width: 2
          }
    
          this.Linegraphic = new this.Graphic({
            geometry: polygon,
            symbol: fillSymbol
          })
    
          this.map.graphics.add(this.Linegraphic)
        },