Make street label collision flag a function

This commit is contained in:
Markus Koch 2020-05-05 19:44:54 +02:00
parent 2054d66191
commit b0adb91c69
2 changed files with 12 additions and 2 deletions

View File

@ -94,7 +94,7 @@ L.StreetLabels = L.LabelTextCollision
L.point(p.x + offsetX, p.y + offsetY), L.point( L.point(p.x + offsetX, p.y + offsetY), L.point(
textWidth, textHeight)); textWidth, textHeight));
if (this.options.collisionFlg) { if (this._getCollisionFlag(layer)) {
for (var index in this._textList) { for (var index in this._textList) {
var pointBounds = this._textList[index]; var pointBounds = this._textList[index];
if (pointBounds.intersects(bounds)) { if (pointBounds.intersects(bounds)) {
@ -105,7 +105,6 @@ L.StreetLabels = L.LabelTextCollision
this._textList.push(bounds); this._textList.push(bounds);
ctx.fillStyle = this.options.fontStyle.fillStyle; ctx.fillStyle = this.options.fontStyle.fillStyle;
ctx.strokeStyle = this.options.fontStyle.strokeStyle; ctx.strokeStyle = this.options.fontStyle.strokeStyle;
@ -143,6 +142,10 @@ L.StreetLabels = L.LabelTextCollision
} }
}, },
_getCollisionFlag: function (layer) {
return this.options.collisionFlg;
},
/*** /***
* Returns the bearing in degrees clockwise from north (0 degrees) * Returns the bearing in degrees clockwise from north (0 degrees)
from the first L.LatLng to the second, at the first LatLng from the first L.LatLng to the second, at the first LatLng

View File

@ -36,6 +36,13 @@ var streetLabelsRenderer = new L.StreetLabels({
}, },
}); });
streetLabelsRenderer._getCollisionFlag = function (layer) {
if (!(layer instanceof L.Polygon)) // Always check collision for streets
return true;
zoom = mymap.getZoom();
return (zoom < 5);
}
streetLabelsRenderer._getDynamicFontSize = function (layer) { streetLabelsRenderer._getDynamicFontSize = function (layer) {
zoom = mymap.getZoom(); zoom = mymap.getZoom();