ArcGIS API for JavaScript(V4.6)图层高亮

效果如下:
鼠标滑动.gif

  • 鼠标划过高亮
let highlightLayer = new GraphicsLayer({id:"testMapServer"});
myMap.add(highlightLayer);

let fillSymbol = {
    type: 'simple-fill',
    color: [30, 159, 255, 0],
    style: 'solid',
    outline: {
        color: [0, 254, 254 , 1],
        width: 2
    }
};
myView.on("pointer-move", function(event){
    highlightLayer.removeAll();
    myView.hitTest(event).then(function(response){
        if (response.results.length) {
            let graphic = response.results.filter(function (result) {
                return result.graphic.layer === xiAn_adminRegionLayer;
            })[0].graphic;
            let geometry = graphic.geometry;
            let highLightSingle = new Graphic(geometry, fillSymbol, null);
            highlightLayer.add(highLightSingle);
        }
    });
});
  • 鼠标点击高亮
myView.on('click', function(event) {
    myView.graphics.removeAll();
    myView.hitTest(event).then(function(response) {
        if(response.results.length > 0 && response.results[0].graphic) {
            selectFeature(response.results[0].graphic.attributes["FID"]);
        }
    });
});

function selectFeature(FID) {
    let selectionSymbol = {
        type: 'simple-fill',
        color: [30, 159, 255, 0],
        style: 'solid',
        outline: {color: [0, 254, 254 , 1], width: 2}
    };
    let query = xiAn_adminRegionLayer.createQuery();
    query.where = "FID" + '=' + FID;
    xiAn_adminRegionLayer.queryFeatures(query).then(function(results) {
        if(results.features.length > 0) {
            let lightFeature = results.features[0];
            lightFeature.symbol = selectionSymbol;
            myView.graphics.add(lightFeature);
        }
    });
}
阅读 170

推荐阅读
WebGIS开发之路
用户专栏

记录地图开发每一天~

0 人关注
1 篇文章
专栏主页