Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icholy/9efe1247a1ba43cb1850 to your computer and use it in GitHub Desktop.
Save icholy/9efe1247a1ba43cb1850 to your computer and use it in GitHub Desktop.
var styleFunction = (function () {
var fill = new ol.style.Fill({ color: 'rgba(255, 255, 255, 0.5)' }),
stroke = new ol.style.Stroke({ color: '#319FD3', width: 1 }),
textFill = new ol.style.Fill({ color: '#000' }),
textStroke = new ol.style.Stroke({ color: '#fff', width: 3 }),
cache = {};
return function (feature, resolution) {
var text = resolution < 5000 ? feature.get('name') : '';
if (cache[text]) {
return cache[text]
}
var style = cache[text] = new ol.style.Style({
fill : fill,
stroke : stroke,
text : new ol.style.Text({
font : '12px Calibri,sans-serif',
text : text,
fill : textFill,
stroke : textStroke
})
});
return style;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment