Simplify the renderer function API

This commit is contained in:
Andreas Hocevar
2017-08-04 22:52:08 +02:00
parent 67aa1a6dc9
commit 617151c8ff
6 changed files with 63 additions and 46 deletions

View File

@@ -70,9 +70,9 @@ var styles = [
})
}),
new ol.style.Style({
renderer: function(coord, geometry, feature, state) {
renderer: function(coords, state) {
var pixelRatio = state.pixelRatio;
var text = feature.get('name');
var text = state.feature.get('name');
var canvas = textCache[text];
if (!canvas) {
// Draw the label to its own canvas and cache it.
@@ -87,7 +87,7 @@ var styles = [
context.fillText(text, 0, 0);
}
// The 3rd value of the coordinate is the measure of the extent width
var extentWidth = geometry.getCoordinates()[2] / resolution * pixelRatio;
var extentWidth = state.geometry.getCoordinates()[2] / resolution * pixelRatio;
if (extentWidth > canvas.width) {
// Only consider labels not wider than their country's bounding box
createLabel(canvas, text, coord);