Leaflet / Leaflet.VectorGrid

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

Click event not working for point geojson featureCollection #168

Closed marsmith closed 4 years ago

marsmith commented 6 years ago

Using version 1.3.0, it seems like there is an issue with events when interactive: true is set. Console is showing "Uncaught TypeError: Cannot read property 'lat' of undefined" on any event (click, mouseover). I basically just tweaked the demo.

added jsfiddle: https://jsfiddle.net/gfpzvs28/

image

Here is my code:

var vectorGrid = L.vectorGrid.slicer( points, { 
    vectorTileLayerStyles: {
        sliced: function(properties, zoom) {

            var state = properties.state_province;
            var radius = 2;
            if (zoom >= 8) radius = 4;
            return {

                fillColor: state === 'Michigan' ? '#800026' :
                state === 'Wisconsin' ? '#E31A1C' :
                state === 'Minnesota' ? '#FEB24C' :
                state === 'New York' ? '#B2FE4C' :
                state === 'Ohio' ? '#B2AE4C' :  
                state === 'Indiana' ? '#A2CE4C' :  
                        '#FFEDA0',  //otherwise
                fillOpacity: 0.5,
                opacity: 1,
                stroke: true,
                fill: true,
                weight: 0,
                radius: radius
            }
        }
    },
    interactive: true,
    getFeatureId: function(f) {
        return f.properties.site_id;
    }
})
.on('click', function(e) {
    var properties = e.layer.properties;
    console.log(properties)
})
.addTo(map);
ekeydar commented 6 years ago

I've looked on the leaflet code, it seems that the bug is since now Leaflet consider this as marker since it has getLatLng function.

https://github.com/Leaflet/Leaflet/blame/master/src/map/Map.js#L1378

chriszrc commented 6 years ago

You can read the thread on this issue, it has a discussion of the problem, and at least a temporary fix: https://github.com/Leaflet/Leaflet.VectorGrid/issues/148

There is also a fork you can use with a fix implemented already: https://github.com/chriszrc/Leaflet.VectorGrid

karussell commented 5 years ago

This problem seems to show up in the unmodified demo too: http://leaflet.github.io/Leaflet.VectorGrid/demo-points.html (with the same error in chromium; in firefox you get several "TypeErrors t is undefined" and "L.DomEvent._fakeStop is not a function" if you click on something)

tomchadwin commented 4 years ago

Duplicate of #148