-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StyleSelectControl element #206
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: c39d642 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@spwoodcock is attempting to deploy a commit to the Daniel Imfeld's projects Team on Vercel. A member of the Team first needs to authorize it. |
@@ -0,0 +1,239 @@ | |||
<!-- A component to render a style selection prompt, including a thumbnail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the JS script in this file to a .js
file instead of a .svelte
file?
It will be much easier to integrate into other frontend frameworks (e.g. React) if the MapLibre lifecycle management were done in pure JS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea!
Do you mean to move this logic perhaps into styles.ts
& export the functions for use in this component:
Then the component will basically just accept props and pass data to these functions - is that right?
Other feedback is that the bubble sizes are probably a bit too bit - will reduce them slightly 😄 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks this is pretty cool! I agree moving the processing code out to another file is a good idea, so that people can more easily create their own style switcher controls. Will do a full review once that's done. :)
@@ -9,7 +9,7 @@ | |||
export { classNames as class }; | |||
</script> | |||
|
|||
<button type="button" {title} on:click> | |||
<button type="button" {title} on:click {...$$props}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use ...$$restProps
here instead. Also did it not work to just pass rounded-full
in the class
property?
|
||
function selectStyle(style: MapLibreStylePlusMetadata) { | ||
selectedStyleUrl = style.metadata.thumbnail; | ||
$map?.setStyle(style); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug, as it would actually remove any additional layers added to the map.
If styles is used to load say a vector layer and a vector tile layer on top of the basemap raster layers. We would override the vector styles with only the basemap style.
Needs a fix before merge!
I got a bit sidetracked, but will try to come back to this soon! |
Issue
Solution
Made a StyleSelectControl component that can be rendered in any corner of the map (configurable):
Hovering over the control expands the options available & hovering over each element shows a tooltip of the style
name
:Selecting a style updates the map style:
The direction the elements expand is also configurable:
Each item is a
ControlButton
component with a thumbnail preview displayed.Note
Currently the thumbnail is only rendered for raster basemaps of XYZ format.
extraStyles
, which is a list of eithermaplibregl.StyleSpecification
or a URL to a maplibre style JSON.Caveat 1
https://a.tile.openstreetmap.org/{z}/{x}/{y}.png
.ControlButton
:ControlButton
.svg
fallback that is displayed for other style types, for now.Caveat 2
For now I made this a separate control, as I'm not sure if it's desirable / certain to be accepted.
The flexibility allows for me (or anyone else) to take this code and use it as a component alongside an existing
svelte-maplibre
install.However, I realise that a prop like
extraStyles
is a bit clunky, and think the ideal implementation would simply be accepting either a single style or multiple styles on theMapLibre
element:or