aboutsummaryrefslogtreecommitdiffstats
path: root/src/js
diff options
context:
space:
mode:
authorJakub Hampl <kopomir@gmail.com>2018-06-20 15:56:35 +0100
committerJakub Hampl <kopomir@gmail.com>2018-06-20 15:56:35 +0100
commit7eb8f3ea42fb1399bc9960697e9f6439fe5ec6cb (patch)
tree183cbf84ab1383ba11f9502f30db1270ffdd25cd /src/js
parent42d12f835708b15f6730cf0f3fdf6072de1e3002 (diff)
Add basic Command module
Diffstat (limited to 'src/js')
-rw-r--r--src/js/main.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/js/main.js b/src/js/main.js
index 4f561fc..0d8b307 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -1,6 +1,9 @@
import mapboxgl from "mapbox-gl";
-function wrapElmApplication(elmApp) {
+function wrapElmApplication(elmApp, options = {}) {
+ if (options.token) {
+ mapboxgl.token = options.token;
+ }
window.customElements.define(
"elm-mapbox-map",
class MapboxMap extends window.HTMLElement {
@@ -203,7 +206,9 @@ function wrapElmApplication(elmApp) {
}
connectedCallback() {
- mapboxgl.accessToken = this.token;
+ if(this.token) {
+ mapboxgl.accessToken = this.token;
+ }
this.style.display = "block";
this.style.width = "100%";
this.style.height = "100%";
@@ -216,6 +221,17 @@ function wrapElmApplication(elmApp) {
}
}
);
+
+ if (elmApp.ports && elmApp.ports.elmMapboxOutgoing) {
+ elmApp.ports.elmMapboxOutgoing.subscribe(event => {
+ var target = document.getElementById(event.target);
+ switch(event.command) {
+ case "fitBounds":
+ return target.map.fitBounds(event.bounds);
+ }
+ })
+ }
+
return elmApp;
}