如何實現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);
      })
  }

效果如下:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章