@@ -202,71 +202,81 @@ export default {
202202 },
203203
204204 setupMapbox () {
205- this .geobounds = [
206- geostring2array (this .geojson .views [0 ].spec .bounds [0 ]),
207- geostring2array (this .geojson .views [0 ].spec .bounds [1 ])
208- ];
205+ try {
206+ this .geobounds = [
207+ geostring2array (this .geojson .views [0 ].spec .bounds [0 ]),
208+ geostring2array (this .geojson .views [0 ].spec .bounds [1 ])
209+ ];
209210
210- const lookupResources = {}; // name -> index
211- this .geojson .resources .forEach ((resource , index ) => {
212- lookupResources[resource .name ] = index;
213- });
211+ const lookupResources = {}; // name -> index
212+ this .geojson .resources .forEach ((resource , index ) => {
213+ lookupResources[resource .name ] = index;
214+ });
214215
215- this .geojson .views [0 ].resources .forEach ((resourceName ) => {
216- this .layers .push (
217- this .geojson .resources [lookupResources[resourceName]]
218- );
219- });
216+ this .geojson .views [0 ].resources .forEach ((resourceName ) => {
217+ this .layers .push (
218+ this .geojson .resources [lookupResources[resourceName]]
219+ );
220+ });
221+ } catch (error) {
222+ console .log (error);
223+ this .isMapLoaded = true ;
224+ }
220225 },
221226
222227 displayMapbox () {
223- L .mapbox .accessToken = process .env .VUE_APP_MAPBOX_ACCESSTOKEN ;
224- const boxSize = 800 ;
225- const bounds = geoViewport .viewport (this .geobounds .flat (), [boxSize, boxSize]);
226- this .map = L .mapbox .map (' map' ).setView (bounds .center , bounds .zoom );
227- this .layerContainer = new L.LayerGroup ();
228- // default test layer // this.layerContainer.addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/light-v10'));
229- if (this .hash ) { // full snapshot with hash
230- this .layers .forEach ((layer ) => {
231- if (layer .mediatype === ' application/vnd.mapbox-vector-tile' ) {
232- const tileLayer = L .mapbox .styleLayer (layer .path );
233- tileLayer .on (' load' , () => { this .isMapLoaded = true ; });
234- this .layerContainer .addLayer (tileLayer);
235- } else if (layer .mediatype === ' application/geo+json' ) {
236- this .layerContainer .addLayer (L .mapbox .featureLayer (layer .data , {
237- attribution: this .geojson .views [0 ].spec .attribution
238- }));
239- } else if (layer .mediatype === ' application/vnd.simplestyle-extended' ) {
240- this .layerContainer .addLayer (this .createFeatureLayer (
241- layer .data .features , this .geojson .views [0 ].spec .attribution
228+ try {
229+ L .mapbox .accessToken = process .env .VUE_APP_MAPBOX_ACCESSTOKEN ;
230+ const boxSize = 800 ;
231+ const bounds = geoViewport .viewport (this .geobounds .flat (), [boxSize, boxSize]);
232+ this .map = L .mapbox .map (' map' ).setView (bounds .center , bounds .zoom );
233+ this .layerContainer = new L.LayerGroup ();
234+ // default test layer // this.layerContainer.addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/light-v10'));
235+ if (this .hash ) { // full snapshot with hash
236+ this .layers .forEach ((layer ) => {
237+ if (layer .mediatype === ' application/vnd.mapbox-vector-tile' ) {
238+ const tileLayer = L .mapbox .styleLayer (layer .path );
239+ tileLayer .on (' load' , () => { this .isMapLoaded = true ; });
240+ this .layerContainer .addLayer (tileLayer);
241+ } else if (layer .mediatype === ' application/geo+json' ) {
242+ this .layerContainer .addLayer (L .mapbox .featureLayer (layer .data , {
243+ attribution: this .geojson .views [0 ].spec .attribution
244+ }));
245+ } else if (layer .mediatype === ' application/vnd.simplestyle-extended' ) {
246+ this .layerContainer .addLayer (this .createFeatureLayer (
247+ layer .data .features , this .geojson .views [0 ].spec .attribution
248+ ));
249+ }
250+ });
251+ } else if (this .bfsNumber ) { // empty municipality
252+ this .geojson .coordinates .forEach ((polygon ) => {
253+ this .layerContainer .addLayer (L .polygon (polygon, { color: ' #543076' }));
254+ });
255+ if (process .env .VUE_APP_MAPBOX_DEFAULT_STYLES ) {
256+ this .layerContainer .addLayer (L .mapbox .styleLayer (
257+ process .env .VUE_APP_MAPBOX_DEFAULT_STYLES
242258 ));
243259 }
244- });
245- } else if (this .bfsNumber ) { // empty municipality
246- this .geojson .coordinates .forEach ((polygon ) => {
247- this .layerContainer .addLayer (L .polygon (polygon, { color: ' #543076' }));
248- });
249- if (process .env .VUE_APP_MAPBOX_DEFAULT_STYLES ) {
250- this .layerContainer .addLayer (L .mapbox .styleLayer (
251- process .env .VUE_APP_MAPBOX_DEFAULT_STYLES
252- ));
253260 }
254- }
255- this .layerContainer .addTo (this .map );
256- L .control .scale ({
257- metric: true ,
258- imperial: false
259- }).addTo (this .map );
261+ this .layerContainer .addTo (this .map );
262+ L .control .scale ({
263+ metric: true ,
264+ imperial: false
265+ }).addTo (this .map );
260266
261- if (this .screenshotMode ) {
262- // no zoom controls in screenshot mode
263- document .querySelector (' .leaflet-control-zoom' ).style .display = ' none' ;
264- } else {
265- // no attribution in normal mode
266- document .querySelector (' .leaflet-control-attribution' ).style .display = ' none' ;
267- }
268- if (this .screenshotIsThumbnail ) {
269- document .querySelector (' #mapinfo' ).style .visibility = ' hidden' ;
267+ if (this .screenshotMode ) {
268+ // no zoom controls in screenshot mode
269+ document .querySelector (' .leaflet-control-zoom' ).style .display = ' none' ;
270+ } else {
271+ // no attribution in normal mode
272+ document .querySelector (' .leaflet-control-attribution' ).style .display = ' none' ;
273+ }
274+ if (this .screenshotIsThumbnail ) {
275+ document .querySelector (' #mapinfo' ).style .visibility = ' hidden' ;
276+ }
277+ } catch (error) {
278+ console .log (error);
279+ this .isMapLoaded = true ;
270280 }
271281 // L.control.zoom({ position: 'bottomleft' }).addTo(this.map);
272282 // this.map.addLayer(L.rectangle(this.geobounds, { color: 'red', weight: 1 }));
0 commit comments