在 Openlayers3 中突出显示 lineString 或 point
Highlight the lineString or point in Openlayers3
在我的地图应用程序中,当鼠标悬停在多边形上或 select 它时,我可以高亮显示多边形,但是点和线串不能高亮显示,以为我在脚本中添加了样式。
我在网上找到了一些使用ol.featureOverlay
的工作示例,但是现在在新的openlayers3中,ol.featureOverlay
被从库中删除了,有高手知道如何解决吗?
让您的互动阅读您 function
的样式:
var hoverInteraction = new ol.interaction.Select({
condition: ol.events.condition.pointerMove,
style: geometryStyle
});
你的函数将如上所示:
function geometryStyle(feature){
var
style = [],
geometry_type = feature.getGeometry().getType(),
white = [255, 255, 255, 1],
blue = [0, 153, 255, 1],
width = 6
;
style['LineString'] = [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: white, width: width + 2
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue, width: width
})
})
],
style['Polygon'] = [
new ol.style.Style({
fill: new ol.style.Fill({ color: [255, 255, 255, 0.5] })
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: white, width: 3.5
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue, width: 2.5
})
})
],
style['Point'] = [
new ol.style.Style({
image: new ol.style.Circle({
radius: width * 2,
fill: new ol.style.Fill({color: blue}),
stroke: new ol.style.Stroke({
color: white, width: width / 2
})
})
})
];
return style[geometry_type];
}
在我的地图应用程序中,当鼠标悬停在多边形上或 select 它时,我可以高亮显示多边形,但是点和线串不能高亮显示,以为我在脚本中添加了样式。
我在网上找到了一些使用ol.featureOverlay
的工作示例,但是现在在新的openlayers3中,ol.featureOverlay
被从库中删除了,有高手知道如何解决吗?
让您的互动阅读您 function
的样式:
var hoverInteraction = new ol.interaction.Select({
condition: ol.events.condition.pointerMove,
style: geometryStyle
});
你的函数将如上所示:
function geometryStyle(feature){
var
style = [],
geometry_type = feature.getGeometry().getType(),
white = [255, 255, 255, 1],
blue = [0, 153, 255, 1],
width = 6
;
style['LineString'] = [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: white, width: width + 2
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue, width: width
})
})
],
style['Polygon'] = [
new ol.style.Style({
fill: new ol.style.Fill({ color: [255, 255, 255, 0.5] })
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: white, width: 3.5
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: blue, width: 2.5
})
})
],
style['Point'] = [
new ol.style.Style({
image: new ol.style.Circle({
radius: width * 2,
fill: new ol.style.Fill({color: blue}),
stroke: new ol.style.Stroke({
color: white, width: width / 2
})
})
})
];
return style[geometry_type];
}