Highlight text in vector-layer example

This commit is contained in:
Tom Payne
2014-02-03 16:17:52 +01:00
parent 46396ad0f7
commit 1f4ab82210
+21 -6
View File
@@ -60,20 +60,35 @@ var map = new ol.Map({
}) })
}); });
var highlightStyleArray = [new ol.style.Style({ var highlightStyleCache = {};
var featuresOverlay = new ol.render.FeaturesOverlay({
map: map,
styleFunction: function(feature, resolution) {
var text = resolution < 5000 ? feature.get('name') : '';
if (!highlightStyleCache[text]) {
highlightStyleCache[text] = [new ol.style.Style({
stroke: new ol.style.Stroke({ stroke: new ol.style.Stroke({
color: '#f00', color: '#f00',
width: 1 width: 1
}), }),
fill: new ol.style.Fill({ fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.1)' color: 'rgba(255,0,0,0.1)'
}),
text: new ol.style.Text({
font: '12px Calibri,sans-serif',
text: text,
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#f00',
width: 3
})
}) })
})]; })];
}
var featuresOverlay = new ol.render.FeaturesOverlay({ return highlightStyleCache[text];
map: map,
styleFunction: function(feature, resolution) {
return highlightStyleArray;
} }
}); });