aazuspan / snazzy

✨🗺️ Snazzy basemaps and Font Awesome icons in the Earth Engine code editor
31 stars 3 forks source link

Add support for custom map instances #3

Open iagomoliv opened 4 days ago

iagomoliv commented 4 days ago

Current behavior

Currently, the module only works with the default Map instance. Users cannot use the module's functions with custom map instances created via ui.Map().

Proposed enhancement

Add an optional map parameter to the module's functions. When not specified, it defaults to the standard Map.

Example

snazzy.addStyle(map, url, alias, callback?);
aazuspan commented 4 days ago

I like this suggestion @iagomoliv! To avoid breaking existing code, the new parameter would probably be added at the end (or just before callback which was added very recently). Something like:

snazzy.addStyle(url, alias, map, callback?);

The implementation is a little tricky, but should be possible. Some details below for my own reference.

To allow multiple custom styles, snazzy stores all the active styles in an object and adds them to the map together. With multiple maps, each map will need its own set of active styles. They can't be set as properties of the map object because the default Map is not extensible, and the map instance can't be used as an object key because they just stringify to "[object Object]". An association list with [ui.Map, [style]] pairs might be the best approach.