Comments (5)
Hi there,
you mean you want to update the style for all features in the layer?
There is currently no method for doing that. You could theoretically achieve this by using getFeatureId
option, and then finding all features through the private member _vectorTiles
and settings their style, but that would be a hack.
This seems like a useful feature, though, so I'll keep the issue open and think about if it could be implemented.
from leaflet.vectorgrid.
duplicate/related to #50
from leaflet.vectorgrid.
I have done what you describe: override/replace the vectorTileLayerStyles
for a specific layer, then call its redraw()
in order to apply the new style.
// the VectorGrid setup, with initial color schemes
mylayer = L.vectorGrid.protobuf(URL_HERE, {
rendererFactory: L.canvas.tile,
interactive: true,
vectorTileLayerStyles: {
easythings: {
fill: true, fillColor: 'blue', fillOpacity: 1,
color: 'rgb(0, 0, 0)', opacity: 1, weight: 0.5,
},
bigthings: {
fill: true, fillColor: 'red', fillOpacity: 1,
color: 'rgb(0, 0, 0)', opacity: 1, weight: 0.5,
},
otherthings: {
fill: true, fillColor: 'yellow', fillOpacity: 1,
color: 'rgb(0, 0, 0)', opacity: 1, weight: 0.5,
}
},
}).addTo(MAP);
// override the styles for one of those, to use a different fill color
// then redraw
mylayer.options.vectorTileLayerStyles.bigthings.fillColor = 'purple';
mylayer.redraw();
// override the styles for one of those, to use a callback for choosing colors
// before, it was just one solid color but now it chooses based on criteria
// then redraw
mylayer.options.vectorTileLayerStyles.easythings = function (properties, zoom) {
var style = {
fill: true, fillColor: 'white', fillOpacity: 1,
color: 'rgb(0, 0, 0)', opacity: 1, weight: 0.5,
};
switch (properties.status) {
case 'done':
style.fillColor = 'orange';
break;
case 'happening':
style.fillColor = 'silver';
break;
case 'pending':
style.fillColor = 'blue';
break;
default:
style.fillColor = 'green';
break;
}
return style;
};
mylayer.redraw();
An improvement I would like to see, would be an alternative to redraw()
to simply reapply the styles, without re-downloading the tiles. As it stands, the tiles are re-downloaded and this makes for a relatively slow visual experience as well as network usage and server hits. I think I'll open an Issue for that, and see about doing that...
from leaflet.vectorgrid.
And should it be possible to achieve the same behavior with a L.vectorGrid.slicer
layer?
I tried the same approach you suggest, the layer only flashes but its style is not updated.
Inspecting layer.options.vectorTileLayerStyles.sliced
reveals that whatever style I am setting gets changed there, just not on the tiles.
from leaflet.vectorgrid.
As an update to my previous post/question, I found that if I only set a property and redraw the layer, it doesn't work:
layer.options.vectorTileLayerStyles.sliced.fillColor = 'green';
layer.redraw();
whereas setting it to be a function and return the style, does:
layer.options.vectorTileLayerStyles.sliced = () => {
return {
fill: true,
fillColor: 'green',
fillOpacity: 0.25,
stroke: true,
color: 'green',
weight: 1
}
}
layer.redraw();
I had to include fill
for fillColor
to work... Not sure why, though.
from leaflet.vectorgrid.
Related Issues (20)
- Build failed HOT 1
- 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)
- Problem with Leaflet >= 1.8 HOT 3
- 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?
- While using vectorGrid.protobuf for displaying vector tiles on map i was not able to capture mouse events initially until when i zoomed out to minzoom level
- Filter not working with L.VectorGrid.Protobuf 🔴 HOT 2
- Does geojson-vt adjust resolution according to zoom level? HOT 3
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.