From 7eb8f3ea42fb1399bc9960697e9f6439fe5ec6cb Mon Sep 17 00:00:00 2001 From: Jakub Hampl Date: Wed, 20 Jun 2018 15:56:35 +0100 Subject: Add basic Command module --- src/js/main.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/js/main.js') 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; } -- cgit v1.2.3