dimfeld / svelte-maplibre

Svelte bindings for the MapLibre mapping library
https://svelte-maplibre.vercel.app
MIT License
284 stars 34 forks source link

Ability to override UI for existing controls #39

Open dimfeld opened 12 months ago

dimfeld commented 12 months ago

Specifically in the context of the GeolocateControl, as mentioned by @dominikg on the Svelte Discord.

Proposed method, which I haven't tried yet but I think should work ok:

Subclass the GeolocateControl class from maplibre, and override its onAdd function to call super.onAdd(map), but return a different DOM element managed by Svelte.

Then when your button is clicked, call the trigger method on the control to do the position update. You can also listen to events emitted by the control to perform other UI updates.

I think adding a slot into the GeolocateControl component, and checking for $$slots.default to enable the UI override functionality might be a good way to accomplish this.