效果以下:spa
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); } }); }