From 66ad5d9afbd968d61d0f0fe883db93f4f0ac1756 Mon Sep 17 00:00:00 2001 From: James Stephens Date: Tue, 1 Mar 2022 14:52:25 +0000 Subject: [PATCH 1/2] Fix: Fixed type errors revealed by Cypress. --- src/ui/map/Map.svelte | 72 ++++++++++++++++---------------- src/ui/map/TileSet.svelte | 15 ++----- src/ui/ons/ONSAutosuggest.svelte | 5 ++- 3 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/ui/map/Map.svelte b/src/ui/map/Map.svelte index 6633613b..6121fcdb 100644 --- a/src/ui/map/Map.svelte +++ b/src/ui/map/Map.svelte @@ -69,41 +69,43 @@ link.href = "https://unpkg.com/mapbox-gl/dist/mapbox-gl.css"; link.onload = () => { - map = new Map({ - container, - style: mapstyle, - minZoom: minzoom, - maxZoom: maxzoom, - maxBounds: outerMapBounds, - attributionControl: false, - ...options, - }); - - map.addControl(new NavigationControl()); - - map.addControl(new AttributionControl(), "bottom-left"); - - map.fitBounds(bounds, { padding: 20 }); - - // Get initial zoom level - map.on("load", () => { - debouncedMapZoomBBoxStore(map); - zoom = map.getZoom(); - }); - - map.on("render", () => { - map.resize(); - }); - - // Update zoom level when the view zooms - map.on("zoom", () => { - debouncedMapZoomBBoxStore(map); - zoom = map.getZoom(); - }); - - map.on("drag", () => { - debouncedMapZoomBBoxStore(map); - }); + if (container) { + map = new Map({ + container, + style: mapstyle, + minZoom: minzoom, + maxZoom: maxzoom, + maxBounds: outerMapBounds, + attributionControl: false, + ...options, + }); + + map.addControl(new NavigationControl()); + + map.addControl(new AttributionControl(), "bottom-left"); + + map.fitBounds(bounds, { padding: 20 }); + + // Get initial zoom level + map.on("load", () => { + debouncedMapZoomBBoxStore(map); + zoom = map.getZoom(); + }); + + map.on("render", () => { + map.resize(); + }); + + // Update zoom level when the view zooms + map.on("zoom", () => { + debouncedMapZoomBBoxStore(map); + zoom = map.getZoom(); + }); + + map.on("drag", () => { + debouncedMapZoomBBoxStore(map); + }); + } }; document.head.appendChild(link); diff --git a/src/ui/map/TileSet.svelte b/src/ui/map/TileSet.svelte index f7cde11c..26184a1f 100644 --- a/src/ui/map/TileSet.svelte +++ b/src/ui/map/TileSet.svelte @@ -39,15 +39,9 @@ } // watches for isMapLoaded then runs the addSource method - function isMapLoaded() { - if (map.isStyleLoaded(id)) { - addSource(); - } else { - setTimeout(() => { - isMapLoaded(); - }, 100); - } - } + map.on("style.load", () => { + addSource(); + }); // Set optional source properties if (minzoom) { @@ -97,9 +91,6 @@ isSourceLoaded(); } } - - // kicks off the chain - $: map && isMapLoaded(); {#if loaded} diff --git a/src/ui/ons/ONSAutosuggest.svelte b/src/ui/ons/ONSAutosuggest.svelte index a17ca0db..71483f40 100644 --- a/src/ui/ons/ONSAutosuggest.svelte +++ b/src/ui/ons/ONSAutosuggest.svelte @@ -23,7 +23,10 @@ function onKeyUp(e) { if (e.keyCode === 13) { - autosuggestValue = document.querySelector(".ons-autosuggest-input__option--focused").innerText; + const input = document.querySelector(".ons-autosuggest-input__option--focused"); + if (input) { + autosuggestValue = input.innerText; + } } } From be444f62728f5a5832d069f0fa80d74f24e3b665 Mon Sep 17 00:00:00 2001 From: James Stephens Date: Wed, 2 Mar 2022 11:04:01 +0000 Subject: [PATCH 2/2] Fix: Added warning comment. --- src/ui/map/TileSet.svelte | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/map/TileSet.svelte b/src/ui/map/TileSet.svelte index 26184a1f..71f341c8 100644 --- a/src/ui/map/TileSet.svelte +++ b/src/ui/map/TileSet.svelte @@ -38,7 +38,10 @@ } } - // watches for isMapLoaded then runs the addSource method + /* Waits for style to load then runs the addSource method. + Warning: style.load is not documentated as never intended to be a public API. + More information can be found here: https://github.com/mapbox/mapbox-gl-js/issues/2268 + */ map.on("style.load", () => { addSource(); });