Comments (3)
TL;DR: I solved this by changing to svg renderer instead of canvas renderer with rendererFactory option.
Issue is due to a change in Leaflet 1.8 due to this issue, Leaflet/Leaflet#7431
Leaflet.Vectorgrid extends the Canvas renderer and its _onClick function and thus it has old Canvas code with fakeStop.
But SVG renderer does not extend _onClick, instead it uses Leaflet native _onClick.
I think that this kind of issues is why the author of Leaflet.VectorTileLayer opted for another design. As he writes: "In contrast to VectorGrid, this class has been designed as much as possible in terms of Leaflet's public API."
from leaflet.vectorgrid.
I have used:
- <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-o9N1jGDZrf5tS+Ft4gbIK7mYMipq9lqpVJ91xHSyKhg=" crossorigin=""></script>
- <script type="text/javascript" src="https://unpkg.com/[email protected]"></script>
additional code:
var vtLayer2 = L.vectorGrid
.slicer(vt_layer, {
rendererFactory: L.svg.tile,
vectorTileLayerStyles: {
sliced: function (properties, zoom) {
var p = properties.D01;
return {
fillColor:
p <= 3 ? "#ccffbb" :
p <= 10 ? '#800026' :
p <= 20 ? '#BD0026' :
p <= 30 ? '#E31A1C' :
p <= 40 ? '#FC4E2A' :
p <= 50 ? '#FD8D3C' :
p <= 60 ? '#FEB24C' :
p <= 70 ? '#FED976' :
p <= 100 ? '#E31A1C' :
p <= 120 ? '#800026' :
p <= 150 ? '#FEB24C' :
p <= 300 ? '#B2FE4C' :
p <= 500 ? '#B2FE4C' :
p <= 1000 ? '#B2FE4C' :
p <= 2000 ? '#B2FE4C' : '#FFEDA0',
fillOpacity: 0.5,
//fillOpacity: 1,
stroke: true,
fill: true,
color: 'black',
//opacity: 0.2,
weight: 0,
}
},
},
interactive: true,
getFeatureId: function (f) {
return f.properties.NAMELSAD10;
}
}).on('mouseover', function (e) {
var properties = e.layer.properties;
L.popup()
.setContent("County: " + e.layer.properties.NAMELSAD10 + "<br>White Student: " + e.layer.properties.D01 + "<br>White Teacher: " + e.layer.properties.D02)
.setLatLng(e.latlng)
.openOn(map);
clearHighlight();
highlight = properties.NAMELSAD10;
var p = properties.D01;;
var style = {
fillColor: p === 0 ? '#800026' :
p <= 3 ? "#ccffbb" :
p <= 10 ? '#800026' :
p <= 20 ? '#BD0026' :
p <= 30 ? '#E31A1C' :
p <= 40 ? '#FC4E2A' :
p <= 50 ? '#FD8D3C' :
p <= 60 ? '#FEB24C' :
p <= 70 ? '#FED976' :
p <= 100 ? '#E31A1C' :
p <= 120 ? '#800026' :
p <= 150 ? '#FEB24C' :
p <= 300 ? '#B2FE4C' :
p <= 500 ? '#B2FE4C' :
p <= 1000 ? '#B2FE4C' :
p <= 2000 ? '#B2FE4C' : '#FFEDA0',
fillOpacity: 0.5,
fillOpacity: 1,
stroke: true,
fill: true,
color: 'red',
opacity: 1,
weight: 2,
};
vtLayer2.setFeatureStyle(properties.NAMELSAD10, style);
})
.addTo(map);
vtLayer2.on('click', function(e) {
var properties = e.layer.properties.NAMELSAD10;
highlight = properties.NAMELSAD10;
var p = properties.D01;
var style = {
fillColor: p === 0 ? '#800026' :
p<=3?"#ccffbb":
p <=10 ? '#800026' :
p <= 20 ? '#BD0026' :
p <= 30 ? '#E31A1C' :
p <= 40 ? '#FC4E2A' :
p <= 50 ? '#FD8D3C' :
p <= 60 ? '#FEB24C' :
p <= 70 ? '#FED976' :
p <=100 ? '#E31A1C' :
p<=120?'#800026':
p <=150 ? '#FEB24C' :
p <= 300 ? '#B2FE4C':
p <= 500 ? '#B2FE4C':
p <= 1000 ? '#B2FE4C':
p <=2000 ? '#B2FE4C' : '#FFEDA0',
fillOpacity: 0.5,
fillOpacity: 1,
stroke: true,
fill: true,
color: 'red',
opacity: 1,
weight: 2,
};
vtLayer2.setFeatureStyle(properties.NAMELSAD10, style);
});
from leaflet.vectorgrid.
I was able to solve this by including the following code before any use of L.VectorGrid code. This overwrites the place in the codebase where .fakeStop
is used, and passes the event on to fire correctly without error
L.Canvas.Tile.include({
_onClick: function (e) {
var point = this._map.mouseEventToLayerPoint(e).subtract(this.getOffset());
var layer: L.Layer;
var clickedLayer: L.Layer;
for (var id in this._layers) {
layer = this._layers[id];
if (
layer.options.interactive &&
layer._containsPoint(point) &&
!this._map._draggableMoved(layer)
) {
clickedLayer = layer;
}
}
if (clickedLayer) {
// offending code used to be right here
clickedLayer.fireEvent(e.type, undefined, true);
}
},
});
from leaflet.vectorgrid.
Related Issues (20)
- Consuming compressed vector image responses
- Uncaught Error: Unimplemented type: 3 HOT 2
- protobuf vectorgrid is not handling Long Integers why? HOT 4
- Build failed HOT 2
- Toggle polygon HOT 1
- I cant display points. I can't change the style points/polygons. HOT 1
- Define bounds or extent of VectorGrid layer HOT 2
- Demo pages with points don't work HOT 1
- Layer order inside a tile
- Some tiles not rendering HOT 2
- Uncaught TypeError: Cannot read properties of undefined (reading 'lat') HOT 4
- support L.divIcon
- Protobuf - Get clicked feature (or its geometry)
- remove added layer from map HOT 2
- Project status / Alternative Fork? HOT 1
- Nothing rendering with `_getVectorTilePromise` custom implementation HOT 3
- fillOpacity and fillColor have no effect when rendering circlemarkers HOT 1
- Styling points/circles differently from Polygons
- How can I use maxNativeZoom to continue to show the vector tiles beyond their maximum zoom level?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet.vectorgrid.