如何实现arcgis中MapServer服务要素的高亮

通过添加graphic来实现,代码如下:

  //data为需要高亮的要素信息
  highLight = data => {
    const { view } = this.props.mapView;
    loadModules([ //react中加载arcgis的方式
      'esri/Graphic',
    ], { css: true })
      .then(([
        Graphic,
      ]) => {
        const items = view.graphics.items
        if (items.length > 0) { //清除已存在的,默认一次只高亮一个
          view.graphics.removeMany(items)
        }
        //自定义的高亮符号
        const markerSymbol = {
          type: "simple-marker",  // autocasts as new SimpleMarkerSymbol()
          style: "square",
          color: [51, 204, 51, 0], //r g b a
          size: "24px",  // pixels
          outline: {  // autocasts as new SimpleLineSymbol()
            color: [0, 255, 255],
            width: 2  // points
          }
        };
        const selectedGraphic = new Graphic({
          geometry: data.geometry,
          symbol: markerSymbol
        });
        view.graphics.add(selectedGraphic);
      })
  }

效果如下:
在这里插入图片描述

发布了56 篇原创文章 · 获赞 32 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/hry1243916844/article/details/104697229