bbecquet / Leaflet.PolylineOffset

Apply a relative pixel offset to polylines without changing their coordinates.
MIT License
152 stars 32 forks source link

Fix #1 #21

Open ghost opened 5 years ago

ghost commented 5 years ago

This pull request is based on the pull request from @Sijmen, and provides an additional fix for the circles that still appear on zoomout.

This works for my current usage, as it assumes the maximum zoom level is 18 and the map is globally available via Window.map, further work may be needed before it can be used as is, but it can be useful for others.

ghost commented 5 years ago

The important part is the new function "reductor", which adjusts the offset depending on the zoom-level

trafficonese commented 4 years ago

Very nice fix! Since I am using an R wrapper for this plugin, I wanted to ask if you could modify the reductor function a bit, as otherwise it throws this error in r-leaflet as Window.map is undefined: Uncaught TypeError: Cannot read property 'getZoom' of undefined

Unfortunately I dont understand why that is the case, but I found a function that would work:

        var reductor = function (dist) {
          var el = $(window.map).data("leafletMap");
          var zoom = el ? el.getZoom() : 18;
          return dist / Math.pow(2, 18 - zoom);
        };

It would probably also be nice to be able to define the exponent (hard coded 2 here). I for example would prefer a value of 1.3. for the current task.