diff --git a/src/components/MapBuilder.tsx b/src/components/MapBuilder.tsx index 6b4cfe9..e52e00d 100644 --- a/src/components/MapBuilder.tsx +++ b/src/components/MapBuilder.tsx @@ -19,15 +19,13 @@ import { import SingleSelectComplete from './SingleSelectAutoComplete'; import { ConfigSaveUploadButtons } from './ConfigSaveUploadButtons'; - - export function MapBuilder() { const cgpvContext = useContext(CGPVContext); if (!cgpvContext) { throw new Error('CGPVContent must be used within a CGPVProvider'); } - + const { mapId } = cgpvContext; const { configJson, handleApplyStateToConfigFile, handleConfigFileChange, handleConfigJsonChange, configFilePath, mapWidth, mapHeight, setMapWidth, setMapHeight } = cgpvContext; @@ -36,22 +34,17 @@ export function MapBuilder() { const [isEn, setEn] = useState(true); - const _updateConfigProperty = (property: string, value: any) => { + const _updateConfigProperty = (property: string, value: any) => { const newConfig = { ...modifiedConfigJson }; if (value === undefined) { _.unset(newConfig, property); } else { - _.set(newConfig, property, value); + _.set(newConfig, property, value); } setModifiedConfigJson(newConfig); setIsModified(true); - } - const getProperty = (property: string, defaultValue = undefined) => { - return _.get(configJson, property) ?? defaultValue; - }; - const updateProperty = (property: string, value: any) => { _updateConfigProperty(property, value); }; @@ -78,26 +71,32 @@ export function MapBuilder() { handleConfigJsonChange(modifiedConfigJson); setIsModified(false); } + + const getProperty = (property: string, defaultValue?: any) => { + return _.get(configJson, property) ?? defaultValue; + }; return( + + + + + + - - - - - + handleConfigFileChange(value)} label="Select Configuration File" placeholder="" /> + + Map configuration Map Size @@ -133,64 +134,62 @@ export function MapBuilder() { - - { (isEn) ? cgpv.api.maps[mapId].setLanguage('fr') : cgpv.api.maps[mapId].setLanguage('en'); setEn(!isEn); }} - label="Change Language" placeholder="" /> + label="Map Language" placeholder="" /> updateProperty('theme', value)} label="Display Theme" placeholder="" /> updateProperty('map.interaction', value)} label="Map Interaction" placeholder="" /> + Base map + updateProperty('map.basemapOptions.basemapId', value)} label="Base Map" placeholder="" /> { - updateProperty('map.basemapOptions.shaded', JSON.parse(value)); - console.log("value of unshaded=",value,"boolean=", JSON.parse(value)); - }} + onChange={(value) => { updateProperty('map.basemapOptions.shaded', JSON.parse(value))}} label="Base Map Shaded" placeholder="" /> updateProperty('map.basemapOptions.labeled', JSON.parse(value))} - label="Base Map Labeled" placeholder="" /> - + label="Base Map Labeled" placeholder="" /> + - Zoom Levels - - + updateProperty('map.viewSettings.minZoom', value)} label="Min Zoom" placeholder="" /> + updateProperty('map.viewSettings.maxZoom', value)} label="Max Zoom" placeholder="" /> @@ -200,15 +199,17 @@ export function MapBuilder() { updateProperty('map.viewSettings.projection', value)} label="Map Projection" placeholder="" /> + + Map components Components updateArrayProperty('components', value)} options={componentsOptions} label="Components Options" @@ -219,9 +220,9 @@ export function MapBuilder() { Navigation Bar updateArrayProperty('navBar', value)} - options={navBarOptions} + defaultValue={((getProperty('navBar') !== undefined) && (Array.from(getProperty('navBar')!).length) === 0) ? ['zoom'] : getProperty('navBar', ['zoom', 'home', 'basemap-select', 'fullscreen'])} + options = { navBarOptions } label="Options" placeholder="" /> @@ -246,7 +247,7 @@ export function MapBuilder() { /> updateArrayProperty('appBar.tabs.core', value)} options={appBarOptions} label="App-bar Options" placeholder="" /> diff --git a/src/constants.ts b/src/constants.ts index 755d573..06eecff 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -160,4 +160,4 @@ export const corePackagesOptions: ListOptionType[] = [ { title: 'Swiper', value: 'swiper' } ]; -export const zoomOptions: ListOptionType[] = _.range(0, 51).map((value) => ({ title: value.toString(), value })); +export const zoomOptions: ListOptionType[] = _.range(0, 51).map((value) => ({ title: value.toString().padStart(2), value })); \ No newline at end of file diff --git a/src/providers/cgpvContextProvider/cgpvHook.ts b/src/providers/cgpvContextProvider/cgpvHook.ts index cf0ca47..17da421 100644 --- a/src/providers/cgpvContextProvider/cgpvHook.ts +++ b/src/providers/cgpvContextProvider/cgpvHook.ts @@ -267,7 +267,7 @@ export function useCgpvHook(): ICgpvHook { const str = json.replaceAll(`'`, `"`); JSON.parse(str); cgpv.api.config.createMapConfig(str, 'en'); - } catch (e: any) { + } catch (e: any) { return cgpv.api.utilities.core.escapeRegExp(e.message); } return null;