11<script setup lang="ts">
2+ import { debounce } from " lodash" ;
23import { ref , watch , computed } from " vue" ;
3- import html2canvas from " html2canvas" ;
4- import { Map } from " maplibre-gl" ;
4+ import html2canvas from " html2canvas-pro " ;
5+ import { Map , type LngLatBoundsLike } from " maplibre-gl" ;
56
67import JsonEditorVue from " json-editor-vue" ;
78import " vanilla-jsoneditor/themes/jse-theme-dark.css" ;
@@ -81,7 +82,7 @@ const userHasEditPermission = computed(() => {
8182function createBasemapPreviews() {
8283 if (basemapList .value ) {
8384 const map = mapStore .getMap ();
84- const bounds = map .getBounds ();
85+ const bounds = map .getBounds (). toArray () as LngLatBoundsLike ;
8586 mapStore .availableBasemaps .forEach ((basemap ) => {
8687 if (basemap .id === undefined || basemap .style === undefined ) return ;
8788 if (basemapPreviews .value [basemap .id ]) {
@@ -140,7 +141,7 @@ function setNewBasemapStyleFromTileURL() {
140141 }
141142}
142143
143- function createNewBasemapPreview() {
144+ async function createNewBasemapPreview() {
144145 const map = mapStore .getMap ();
145146 const center = map .getCenter ();
146147 const zoom = map .getZoom ();
@@ -153,7 +154,17 @@ function createNewBasemapPreview() {
153154 newBasemapPreview .value .setCenter (center );
154155 newBasemapPreview .value .setZoom (zoom );
155156 if (newBasemapStyleJSON .value ) {
156- jsonErrors .value = validateStyleMin (newBasemapStyleJSON .value );
157+ if (typeof newBasemapStyleJSON .value == " string" ) {
158+ try {
159+ const response = await fetch (newBasemapStyleJSON .value );
160+ const content = await response .json ();
161+ jsonErrors .value = validateStyleMin (content );
162+ } catch {
163+ jsonErrors .value = [{ message: " Invalid URL." }];
164+ }
165+ } else {
166+ jsonErrors .value = validateStyleMin (newBasemapStyleJSON .value );
167+ }
157168 if (! jsonErrors .value ?.length ) {
158169 newBasemapPreview .value .setStyle (newBasemapStyleJSON .value );
159170 return ;
@@ -288,8 +299,8 @@ function copyViewStateLink(viewState: ViewState) {
288299
289300watch (basemapList , createBasemapPreviews );
290301watch (newBasemapTab , switchBasemapCreateTab );
291- watch (newBasemapTileURL , setNewBasemapStyleFromTileURL );
292- watch (newBasemapStyleJSON , createNewBasemapPreview );
302+ watch (newBasemapTileURL , debounce ( setNewBasemapStyleFromTileURL , 1000 ) );
303+ watch (newBasemapStyleJSON , debounce ( createNewBasemapPreview , 1000 ) );
293304 </script >
294305
295306<template >
0 commit comments