From d17ce491d9ed016baa7e77aefa48ca00bd803052 Mon Sep 17 00:00:00 2001 From: chris marx Date: Wed, 4 Apr 2018 16:07:28 -0400 Subject: [PATCH] remove 'getLatLng' property from PointSymbolizer instances - references #148 Point Symbolizer instances inherit from marker or circlemarker, but they lack latlng information, and on mouseover or click, leaflet will error on these features if it find the getLatLng method, since that indicates it should be treated as a real marker instance, but even though the method is there, the value isnt, so leaflet produces an error. Maybe these instance should have a latlng, I don't know, this was just an easy fix so that I could continue to use vectorgrid protobuf support with points and have mouseover and click events work --- src/Leaflet.VectorGrid.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Leaflet.VectorGrid.js b/src/Leaflet.VectorGrid.js index 2a08d64..bd5f17d 100644 --- a/src/Leaflet.VectorGrid.js +++ b/src/Leaflet.VectorGrid.js @@ -61,7 +61,7 @@ L.VectorGrid = L.GridLayer.extend({ var tileSize = this.getTileSize(); var renderer = this.options.rendererFactory(coords, tileSize, this.options); - var tileBounds = this._tileCoordsToBounds(coords); + var tileBounds = this._tileCoordsToBounds(coords); var vectorTilePromise = this._getVectorTilePromise(coords, tileBounds); @@ -77,16 +77,16 @@ L.VectorGrid = L.GridLayer.extend({ for (var layerName in vectorTile.layers) { this._dataLayerNames[layerName] = true; var layer = vectorTile.layers[layerName]; - + var pxPerExtent = this.getTileSize().divideBy(layer.extent); - + var layerStyle = this.options.vectorTileLayerStyles[ layerName ] || L.Path.prototype.options; - + for (var i = 0; i < layer.features.length; i++) { var feat = layer.features[i]; var id; - + var styleOptions = layerStyle; if (storeFeatures) { id = this.options.getFeatureId(feat); @@ -99,31 +99,31 @@ L.VectorGrid = L.GridLayer.extend({ } } } - + if (styleOptions instanceof Function) { styleOptions = styleOptions(feat.properties, coords.z); } - + if (!(styleOptions instanceof Array)) { styleOptions = [styleOptions]; } - + if (!styleOptions.length) { continue; } - + var featureLayer = this._createLayer(feat, pxPerExtent); - + for (var j = 0; j < styleOptions.length; j++) { var style = L.extend({}, L.Path.prototype.options, styleOptions[j]); featureLayer.render(renderer, style); renderer._addPath(featureLayer); } - + if (this.options.interactive) { featureLayer.makeInteractive(); } - + if (storeFeatures) { renderer._features[id] = { layerName: layerName, @@ -131,15 +131,15 @@ L.VectorGrid = L.GridLayer.extend({ }; } } - + } - + } - + if (this._map != null) { renderer.addTo(this._map); } - + L.Util.requestAnimFrame(done.bind(coords, null, null)); }.bind(this)); @@ -217,6 +217,8 @@ L.VectorGrid = L.GridLayer.extend({ switch (feat.type) { case 1: layer = new PointSymbolizer(feat, pxPerExtent); + //prevent leaflet from treating these canvas points as real markers + layer.getLatLng = null; break; case 2: layer = new LineSymbolizer(feat, pxPerExtent);