-
Notifications
You must be signed in to change notification settings - Fork 0
Expose core to plugins via engine-agnostic map:* APIs
#75
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
base: development
Are you sure you want to change the base?
Changes from all commits
2718d32
524ff46
4616a20
b6b2837
0694875
54bb007
b7f2934
319533b
7ffc66f
cd67ceb
036be3d
dda2fe9
a3b1a3d
cbc4536
ae72021
2eb8c4e
748c51b
0f23b30
51485e0
1a21746
5fd1d93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ | |
| { | ||
| "field": "msv.basemap.provider", | ||
| "name": "Provider", | ||
| "description": "Renders a vector-tile basemap beneath deck.gl layers using MapboxOverlay. Has no effect on Leaflet-engine missions. 'maplibre' is open-source and requires no token. 'mapbox' requires an access token.", | ||
| "description": "Renders a vector-tile basemap beneath map layers using MapLibre or Mapbox GL. Works with both Leaflet and deck.gl engine missions. 'maplibre' is open-source and requires no token. 'mapbox' requires an access token.", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to mention that it works with both Leaflet and deck.gl? Might make more sense to only specify if something is engine specific or UI specific |
||
| "type": "dropdown", | ||
| "options": ["none", "maplibre", "mapbox"], | ||
| "default": "none", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,6 +191,29 @@ function getPropValue(object: unknown, path: string | undefined): unknown { | |
| * | ||
| * @throws {Error} If `options.type` is not a supported layer type. | ||
| */ | ||
| function _toRgba( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| input: unknown, | ||
| fallback: [number, number, number, number] | ||
| ): [number, number, number, number] { | ||
| if (Array.isArray(input) && input.length >= 3) { | ||
| const [r, g, b, a] = input as number[] | ||
| return [r, g, b, a ?? 255] | ||
| } | ||
| if (typeof input === 'string') { | ||
| let s = input.trim() | ||
| if (s.startsWith('#')) s = s.slice(1) | ||
| if (s.length === 3) s = s.split('').map((c) => c + c).join('') | ||
| if (s.length === 6 || s.length === 8) { | ||
| const r = parseInt(s.slice(0, 2), 16) | ||
| const g = parseInt(s.slice(2, 4), 16) | ||
| const b = parseInt(s.slice(4, 6), 16) | ||
| const a = s.length === 8 ? parseInt(s.slice(6, 8), 16) : 255 | ||
| if (!isNaN(r) && !isNaN(g) && !isNaN(b)) return [r, g, b, a] | ||
| } | ||
| } | ||
| return fallback | ||
| } | ||
|
|
||
| export function buildDeckLayer(id: string, options: LayerOptions): Layer { | ||
| const resolvedType = DECKGL_TYPE_ALIAS[options.type ?? ''] ?? options.type | ||
| switch (resolvedType) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { | |
| FitBoundsOptions, | ||
| MapInitOptions, | ||
| ProjectionOptions, | ||
| BasemapOptions, | ||
| } from '../types/view' | ||
| import { LayerOptions, TileLayerOptions, MarkerOptions } from '../types/layers' | ||
| import { IMapEngineMarkers } from '../IMapEngineMarkers' | ||
|
|
@@ -39,6 +40,7 @@ import { | |
| QueryFeaturesOptions, | ||
| } from '../types/events' | ||
| import { MapEngineType } from '../types/engine' | ||
| import { MAPBOX_STATIC_TILE_OPTIONS, OSM_FALLBACK_TILE } from './LeafletHelpers' | ||
|
|
||
| // Leaflet is loaded globally via window.L | ||
| declare const L: any | ||
|
|
@@ -79,6 +81,9 @@ export default class LeafletAdapter implements IMapEngine<any, any, any>, IMapEn | |
| */ | ||
| private _initOptions: MapInitOptions | null = null | ||
|
|
||
| private _basemapLayer: any = null | ||
| private _basemapAccessToken: string | undefined | ||
|
|
||
| /** | ||
| * Initialize the Leaflet map instance | ||
| */ | ||
|
|
@@ -154,6 +159,10 @@ export default class LeafletAdapter implements IMapEngine<any, any, any>, IMapEn | |
| if (attributionControl) { | ||
| attributionControl.remove() | ||
| } | ||
|
|
||
| if (options.basemap && options.basemap.provider && options.basemap.provider !== 'none') { | ||
| this._initBasemapTileLayer(options.basemap) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -247,6 +256,8 @@ export default class LeafletAdapter implements IMapEngine<any, any, any>, IMapEn | |
| destroy(): void { | ||
| if (!this._map) return | ||
|
|
||
| this._removeBasemapLayer() | ||
|
|
||
| this._eventHandlers.forEach((handler, eventName) => { | ||
| this._map.off(eventName, handler) | ||
| }) | ||
|
|
@@ -268,6 +279,10 @@ export default class LeafletAdapter implements IMapEngine<any, any, any>, IMapEn | |
| return this._map | ||
| } | ||
|
|
||
| getBasemap(): any { | ||
| return this._basemapLayer | ||
| } | ||
|
|
||
| /** | ||
| * Get the container element | ||
| */ | ||
|
|
@@ -939,4 +954,66 @@ export default class LeafletAdapter implements IMapEngine<any, any, any>, IMapEn | |
| } | ||
| return null | ||
| } | ||
|
|
||
| // ======================================== | ||
| // BASEMAP TILE LAYER METHODS | ||
| // ======================================== | ||
|
|
||
| private _initBasemapTileLayer(basemap: BasemapOptions): void { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this call setBasemapStyle for setting the style? I can see quite a bit of overlap between the two |
||
| this._basemapAccessToken = basemap.accessToken | ||
| const spec = this._resolveBasemapTileSpec(basemap) | ||
| this._basemapLayer = L.tileLayer(spec.url, spec.options) | ||
| this._basemapLayer.addTo(this._map) | ||
| this._basemapLayer.bringToBack() | ||
|
|
||
| const specMinZoom = (spec.options as { minZoom?: number }).minZoom | ||
| if (typeof specMinZoom === 'number' && specMinZoom > this._map.getMinZoom()) { | ||
| this._map.setMinZoom(specMinZoom) | ||
| } | ||
| } | ||
|
|
||
| setBasemapStyle(styleUrl: string): void { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to respect basemap's minZoom setting when making the switch? |
||
| if (!this._map) return | ||
| const spec = this._resolveBasemapTileSpec({ | ||
| style: styleUrl, | ||
| accessToken: this._basemapAccessToken, | ||
| }) | ||
| this._removeBasemapLayer() | ||
| this._basemapLayer = L.tileLayer(spec.url, spec.options) | ||
| this._basemapLayer.addTo(this._map) | ||
| this._basemapLayer.bringToBack() | ||
| } | ||
|
|
||
| private _removeBasemapLayer(): void { | ||
| if (this._basemapLayer && this._map) { | ||
| this._map.removeLayer(this._basemapLayer) | ||
| } | ||
| this._basemapLayer = null | ||
| } | ||
|
|
||
| private _resolveBasemapTileSpec(basemap: Omit<BasemapOptions, 'provider'>): { | ||
| url: string | ||
| options: Record<string, unknown> | ||
| } { | ||
| const style = basemap.style || '' | ||
|
|
||
| const mapboxMatch = style.match(/^mapbox:\/\/styles\/([^/]+)\/(.+)$/) | ||
| if (mapboxMatch) { | ||
| const [, user, styleId] = mapboxMatch | ||
| const token = basemap.accessToken || this._basemapAccessToken || '' | ||
| return { | ||
| url: `https://api.mapbox.com/styles/v1/${user}/${styleId}/tiles/{z}/{x}/{y}?access_token=${token}`, | ||
| options: { ...MAPBOX_STATIC_TILE_OPTIONS }, | ||
| } | ||
| } | ||
|
|
||
| if (style.includes('{z}') && style.includes('{x}') && style.includes('{y}')) { | ||
| return { url: style, options: {} } | ||
| } | ||
|
|
||
| return { | ||
| url: OSM_FALLBACK_TILE.url, | ||
| options: { ...OSM_FALLBACK_TILE.options }, | ||
| } | ||
| } | ||
| } | ||
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.
Should this view be hard coded? This is not limited to earth so doesn't make sense to have it center on USA.
Also, I created new mission and it is still initializing to 0, 0, 0 so this might not be working as intended.