Skip to content

Commit 727bdef

Browse files
authored
fix loading maplibre css on web under shadow dom (#711)
1 parent 1fd0a40 commit 727bdef

File tree

5 files changed

+18
-28
lines changed

5 files changed

+18
-28
lines changed

demo-app/src/jsMain/resources/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>MapLibre Compose demo app</title>
8-
<link
9-
rel="stylesheet"
10-
href="https://unpkg.com/[email protected]/dist/maplibre-gl.css"
11-
/>
128
<style>
139
html,
1410
body {

demo-app/src/jsMain/resources/styles.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/docs/getting-started.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,7 @@ androidMain.dependencies {
164164

165165
Web support is not yet at feature parity with Android and iOS. Check the [status table](index.md#status) for more info.
166166

167-
For Web, you'll additionally need to add the MapLibre CSS to your page. The
168-
easiest way to do this is via the CDN:
169-
170-
```html title="index.html"
171-
<!DOCTYPE html>
172-
<html lang="en">
173-
<head>
174-
<link
175-
rel="stylesheet"
176-
href="https://unpkg.com/maplibre-gl@{{ gradle.maplibre_js_version }}/dist/maplibre-gl.css"
177-
/>
178-
<title>Example Map</title>
179-
</head>
180-
</html>
181-
```
167+
There are no longer any special steps required to use MapLibre Compose on Web.
182168

183169
## Set up Desktop (JVM)
184170

lib/maplibre-compose/src/jsMain/kotlin/org/maplibre/compose/map/WebMapView.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import co.touchlab.kermit.Logger
1616
import kotlinx.browser.document
1717
import org.maplibre.compose.style.BaseStyle
1818
import org.maplibre.compose.style.SafeStyle
19+
import org.maplibre.kmp.js.getVersion
1920
import org.w3c.dom.HTMLElement
2021

2122
@Composable
@@ -55,7 +56,19 @@ internal fun WebMapView(
5556

5657
WebElementView(
5758
modifier = modifier.onGloballyPositioned { maybeMap?.resize() },
58-
factory = { document.createElement("div").unsafeCast<HTMLElement>() },
59+
factory = {
60+
document.createElement("div").unsafeCast<HTMLElement>().apply {
61+
appendChild(
62+
document.createElement("link").apply {
63+
setAttribute("rel", "stylesheet")
64+
setAttribute(
65+
"href",
66+
"https://unpkg.com/maplibre-gl@${getVersion()}/dist/maplibre-gl.css",
67+
)
68+
}
69+
)
70+
}
71+
},
5972
update = { element ->
6073
val map =
6174
maybeMap

lib/maplibre-js-bindings/src/commonMain/kotlin/org/maplibre/kmp/js/external.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import org.w3c.dom.TouchEvent
88
import org.w3c.dom.events.MouseEvent
99
import org.w3c.dom.events.WheelEvent
1010

11+
/** https://maplibre.org/maplibre-gl-js/docs/API/functions/getVersion/ */
12+
public external fun getVersion(): String
13+
1114
/** [Map](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/) */
1215
public external class Map public constructor(options: MapOptions) {
1316
public var repaint: Boolean

0 commit comments

Comments
 (0)