quhua是自己发布的行政区划的图层,想鼠标经过图层高亮显示,但是失败了
var quhua = new ol.layer.Image({
source: new ol.source.ImageWMS({
url: 'http://localhost:8045/geoserver/DanDong/wms',
params: {
'LAYERS': 'DanDong:quhuamian'
},
ratio: 1,
serverType: 'geoserver'
}),
visible: true
});
map.addLayer(quhua);
quhua.setOpacity(0.25);
var hightStyle = new ol.style.Style({
//填充色
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
//边线颜色
stroke: new ol.style.Stroke({
color: '#FF0000',
width: 5
}),
//形状
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
var lineDedalut = new ol.style.Style({
//填充色
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
//边线颜色
stroke: new ol.style.Stroke({
color: '#1E90FF',
width: 5
}),
//形状
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
var highFeature = null;
map.on('pointermove', function (evt) {
var features = map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
// console.log(feature);
return {
feature: feature,
layer: layer
};
});
if (features) {
highFeature = features.feature;
features.feature.setStyle(hightStyle)
} else {
if (highFeature)
highFeature.setStyle(lineDedalut)
}
})