I'm a self-taught fullstack developer and skier based in 🇦🇩 Andorra.
Interested in design 🎨, TV shows 📺 and asian food 🍜
Formerly building Snowplanner.
Add a legend to a mapbox-gl map by parsing layer layout & paint expressions.
License: ISC License
I'm a self-taught fullstack developer and skier based in 🇦🇩 Andorra.
Interested in design 🎨, TV shows 📺 and asian food 🍜
Formerly building Snowplanner.
When i download the module, i get .min.js files that are bundled. Thus unusable. Can anyone help?
Hello,
Is the project compatible with https://openmaptiles.org/ and Tileserver-GL serving mapbox compatible tiles from a Docker container ?
If no layer is loaded and the legend is empty, the shadow borders are still visible.
Is it appropriate to have, for example, 0m ?
Just found your repo and it's pretty cool - have you thought of adding support for custom markers? I have a map that uses a local file with custom markers and since it doesn't get added as a regular layer it doesn't look like I can get it to show up in the legend.
Hello,
Is it possible to omit or rename the "other" label from the legend?
If I omit it manually I get the following error:
Error: layers.Legend.paint.line-color: Expected an even number of arguments.
If it could be renamed, I could assign the last layer to the feedback layer in the mapbox studio.
This is the object received by the paint
mapboxObj.addLayer({ id: "Legend", type: mapboxObj.style.stylesheet.layers[i].type, source: "id123", "source-layer": 'id123', paint: { "line-color": [ "match", [ "get", "roadtype" ], "class1", "hsl(0, 89%, 56%)", "class2", "hsl(205, 84%, 56%)", /* Other */ "#2deb2d" ] }
thanks in advance!
Add a method to trigger the legend update, not having to rely on map events.
Provide an option to programatically refresh the legend when using reactive frameworks like React or Vue. Mainly on changing metadata when using multiple locales, legend should be able to be refreshed without deleting and reading the new layer (this is the workaround right now).
Patterns are images, and can be trated the same way.
Layers are stacked on the map in the order they are added (first on the bottom and last on the top) while Legend panels are added in sequential order (last layer panel at the bottom). This is counter-intuitive and the Legend panels should follow the same stacking order as map layers.
There is a problem when the legend is added to multiple maps per document.
If there are multiple maps per document, and if theses maps share a
layer with the same id, scoping the legend pane querySelector to
document instead of the container causes matches across the different
maps.
The error thrown is this:
index.ts:122 Uncaught DOMException: Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.
at http://localhost:5173/src/index.ts?t=1671003943193:94:25
at Array.forEach (<anonymous>)
at LegendControl._loadPanes (http://localhost:5173/src/index.ts?t=1671003943193:71:187)
at Map.fire (http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:717:20)
at Map.<anonymous> (http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:21086:59)
at Map.fire (http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:717:20)
at ei.fire (http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:722:132)
at ei.update (http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:15664:246)
at Map._render (http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:21568:115)
at http://localhost:5173/node_modules/.vite/deps/mapbox-gl.js?v=b39e1061:21678:76
You can reproduce this by adding a second map to the demo html page:
Hi,
Is it possible to support the raster layer? Like when we have a TMS or wms layer which has color classes (like a landcover map).
We have discrate, classified and continues rasters. I see legend already supports such data type. I feel we can read these information from layer metadata when source type is raster. A descrate and classifoed raster can have oprion to manually feed classes/color as key value pair and for the continues raster we can have a color ramp or an array of colors (max 100).
I can add its PR if you think this is something we can add to this project.
Some sources update frequently, but layers (and so the legend) do not need to change. Add an option ¿optional? that skips legend redraw when styledata event is triggered, at least if layers have not changed.
When interpreting numeric step expressions for colors, we are currently using the "other" label for the base color (stop_output_0 in the spec).
However, it looks to me that there should be some label like < [first step]
. Also, this label should be ordered accordingly as the first label since it's numerically the first one also.
https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#step
I could just override the "other" label in the metadata, but it would be nice if the label automatically incorporated the value of the first step, and also it should be the first label and not the last. For example if the first step is 5, it would read < 5
.
(Btw, I'm working in a non-English, multilingual context so something like up to 5
would be suboptimal)
It could even read "0-5" if we knew the minimum value in the data was 0, but I realize this might be out of scope.
I'm happy to implement at least a minimal "< [first step]" version if you agree this is needed.
Label for value 0 is not rendered
'fill-color': [
'step',
['get', 'property'],
'#f00',
0, '#00f',
1, '#ff0',
2, '#f0f',
]
Sometimes the only needed thing to add to labels is a unit, no need to map every label
Hi,
I'd like to know if this library is also working with maplibre-gl-js ?
Is there a way to accept layer IDs with spaces in them? It looks like mapbox GL handles layers with spaces in their names just fine, but those don't show in the legend.
Support for ['get', {attribute}]
would be a nice feature to have.
Workaround now is to declare a match
expression and enumerate al possible values. Not very cool.
Uncategorized features are grouped under OTHER label. Need some way to customize this label, ideally through metadata > labels
option.
If I have layers in my map like "layer","layer1","layer2", and pass in config options like this:
mapLegendRef.current = new LegendControl({
collapsed: false,
layers: {
["layer"]:"fill-color"
},
toggler: true,
});
Layers "layer1" and "layer2" will also be added because of the broad regex matching here:
mapboxgl-legend/src/LegendControl.ts
Line 104 in c770843
Also, passing in a regex like [^layer$]:"fill-color"
will work at first, but then the layer config appears to get overridden in subsequent updates, so that's not working either.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.