效果如下:
- 鼠标划过高亮
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);
}
});
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。