Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
593 stars 192 forks source link

Interaction Lost at Fractional Zoom #236

Closed grid-100 closed 3 years ago

grid-100 commented 4 years ago

This 174 issue might be similar with hope that the issues will be fixed in the next release.

I've been sucessfully testing VectorGrid to render custom data (electricity network cables) using Leaflet.Vector Grid v1.3 + Leaflet 1.4. Network cables was added as overlay and rendered with Leaflet.VectorGrid. This arrangement allows me to have dynamic combination between basemap and overlays. Everything looks great with standard basemap. The problems arise when I try to use Nextgen-tilezen (using tangram). At fractional zoom, the mouse event seems to be losing its grip from the data.

Using Leaflet.hash as a clue and this Leaflet.VectorGrid.js log at

_onMouseMove: function (e) {

    if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; }
    console.log(this.getOffset());
    var point = this._map.mouseEventToLayerPoint(e).subtract(this.getOffset());
    this._handleMouseHover(e, point);
},

I notice that at integer zoom where mouseover and click works, the values of this.getOffset() varies between

top-left    {x: -579, y: -428},
bottom-right    {x: 445, y: 84}

When mousewheelzoom / scrolling occurs and map get fractional zoom those values start to jump somewhere between

topleft     {x: -519731, y: -337424}
bottom-right    {x: -518707, y: -336912}

I always get normal mouseover interaction whenever i strip down fractional zoom from browser address bar. Do you think getOffset return sort of string concatenation? I don't have any idea how to fix it

zmbc commented 3 years ago

@grid-100 I believe this issue and #174 may both be caused by mouse event locations being calculated using the zoom of the tiles, not the map. I have opened a PR to fix this: #252.

grid-100 commented 3 years ago

@zmbc, perfect! Just tested your fix #252 and my tangram+L.VectorGrid layering works fine now.

ssontag55 commented 3 years ago

@grid-100 How did you get this to work? I pull down that PR and with zoomSnap: .25 click or mouse events didn't work at fractional zoom.

grid-100 commented 3 years ago

I manually replaced the L.Canvas.Tile from Leaflet.VectorGrid.js with @zmbc code attempt to fix the issue: https://github.com/zmbc/Leaflet.VectorGrid/blob/master/src/Leaflet.Renderer.Canvas.Tile.js. It didn't fix all fractional zoom. But i find it suffice for my current test.