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

效果如下:
ArcGIS API for JavaScript(V4.6)图层高亮_第1张图片

  • 鼠标划过高亮
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);
        }
    });
}

你可能感兴趣的:(webgis,前端,gis)