Skip to content

Commit

Permalink
refactor: import of maplibregl
Browse files Browse the repository at this point in the history
Seems link maplibregl doesn't have normal ESM build, use this weird
approach to get modules with 'Map' as constructor:

https://stackoverflow.com/questions/78176752/confusion-about-how-to-load-the-maplibre-gl-module-with-import-when-using-type

Because this approach don't access global variable from window, event
content script can get maplibregl
  • Loading branch information
Hsieh Chin Fan committed Oct 27, 2024
1 parent 1ebca08 commit 0af150f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/BasicMaplibreRenderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
renderByYamlWith,
renderByScriptTargetWith,
} from './mapclay.mjs'
import 'maplibre-gl'
/* eslint-disable no-unused-vars */
import * as M from 'maplibre-gl'
/* eslint-enable */
import { addProtocols } from 'maplibre-gl-vector-text-protocol'
import { TerraDrawMapLibreGLAdapter } from 'terra-draw'
loadCSS('https://unpkg.com/[email protected]/dist/maplibre-gl.css')
Expand All @@ -15,7 +17,9 @@ const Renderer = class extends defaultExport {
bearing = 0
style = 'https://demotiles.maplibre.org/style.json'
link = false
maplibregl = window.maplibregl
/* eslint-disable no-undef */
maplibregl = maplibregl
/* eslint-enable */

// Options {{{
static validOptions = this.validOptions.concat([
Expand Down

0 comments on commit 0af150f

Please sign in to comment.