From b0adb91c69941e98ed54d9f10c651115cedfebfb Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Tue, 5 May 2020 19:44:54 +0200 Subject: Make street label collision flag a function --- htdocs/leafletjs/Leaflet.streetlabels.js | 7 +++++-- htdocs/mapscript.js | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/htdocs/leafletjs/Leaflet.streetlabels.js b/htdocs/leafletjs/Leaflet.streetlabels.js index 5342bea..864f791 100644 --- a/htdocs/leafletjs/Leaflet.streetlabels.js +++ b/htdocs/leafletjs/Leaflet.streetlabels.js @@ -94,7 +94,7 @@ L.StreetLabels = L.LabelTextCollision L.point(p.x + offsetX, p.y + offsetY), L.point( textWidth, textHeight)); - if (this.options.collisionFlg) { + if (this._getCollisionFlag(layer)) { for (var index in this._textList) { var pointBounds = this._textList[index]; if (pointBounds.intersects(bounds)) { @@ -105,7 +105,6 @@ L.StreetLabels = L.LabelTextCollision this._textList.push(bounds); - ctx.fillStyle = this.options.fontStyle.fillStyle; 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) from the first L.LatLng to the second, at the first LatLng diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index 8010b35..db74053 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -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) { zoom = mymap.getZoom(); -- cgit v1.2.3