diff --git a/public/favicon.ico b/public/favicon.ico
deleted file mode 100644
index cc6cd75..0000000
Binary files a/public/favicon.ico and /dev/null differ
diff --git a/src/components/GeoViewMap.tsx b/src/components/GeoViewMap.tsx
index 70d99c2..a977f98 100644
--- a/src/components/GeoViewMap.tsx
+++ b/src/components/GeoViewMap.tsx
@@ -7,11 +7,11 @@ import { MapRenderer } from './MapRenderer';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { useNavigate } from 'react-router-dom';
import { AppToolbar } from './AppToolbar';
+import { useSearchParams } from "react-router-dom";
+import { DEFAULT_CONFIG_FILE } from '@/constants';
interface GeoViewMapProps {
showConfigEditor?: boolean;
- config: string | object;
- configIsFilePath?: boolean;
children?: React.ReactNode;
top?: React.ReactNode;
codeSnippet?: string;
@@ -21,29 +21,39 @@ interface GeoViewMapProps {
function GeoViewMap(props: GeoViewMapProps) {
const cgpvContext = useContext(CGPVContext);
const navigate = useNavigate();
+ const [searchParams, setSearchParams] = useSearchParams();
+
if (!cgpvContext) {
throw new Error('CGPVContent must be used within a CGPVProvider');
}
- const { initializeMap, isInitialized } = cgpvContext;
+ const { configFilePath, initializeMap, isInitialized } = cgpvContext;
+
+ const [mobileOpen, setMobileOpen] = React.useState(false);
+ const [isClosing, setIsClosing] = React.useState(false);
+
const {
- config,
- configIsFilePath,
children
} = props;
- const drawerWidth = 440;
+ const DRAWER_WIDTH = 440;
- //when component is mounted, initialize the map
useEffect(() => {
- if (!isInitialized) {
- initializeMap(config, configIsFilePath);
+ if(!isInitialized) {
+ const fPath = searchParams.get('config') ?? DEFAULT_CONFIG_FILE;
+ initializeMap(fPath, true);
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps
- const [mobileOpen, setMobileOpen] = React.useState(false);
- const [isClosing, setIsClosing] = React.useState(false);
+ useEffect(() => {
+ if (configFilePath && configFilePath.length > 0) {
+ setSearchParams({ config: configFilePath });
+ } else if(isInitialized) {
+ setSearchParams({ config: ''});
+ }
+ }, [configFilePath]);
+
const handleDrawerClose = () => {
setIsClosing(true);
@@ -70,8 +80,8 @@ function GeoViewMap(props: GeoViewMapProps) {
@@ -95,7 +105,7 @@ function GeoViewMap(props: GeoViewMapProps) {
-
+
{/* The implementation can be swapped with js to avoid SEO duplication of links. */}
@@ -117,14 +127,14 @@ function GeoViewMap(props: GeoViewMapProps) {
variant="permanent"
sx={{
display: { xs: 'none', sm: 'block' },
- '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth, borderRight: '5px solid lightgray', },
+ '& .MuiDrawer-paper': { boxSizing: 'border-box', width: DRAWER_WIDTH, borderRight: '5px solid lightgray', },
}}
open
>
-
+
{props.top}
{children}
diff --git a/src/components/MapBuilder.tsx b/src/components/MapBuilder.tsx
index 22b499f..baf9939 100644
--- a/src/components/MapBuilder.tsx
+++ b/src/components/MapBuilder.tsx
@@ -18,6 +18,7 @@ import SingleSelectComplete from './SingleSelectAutoComplete';
import { ConfigSaveUploadButtons } from './ConfigSaveUploadButtons';
+
export function MapBuilder() {
const cgpvContext = useContext(CGPVContext);
diff --git a/src/pages/default.tsx b/src/pages/default.tsx
index 73f8795..34948c8 100644
--- a/src/pages/default.tsx
+++ b/src/pages/default.tsx
@@ -1,12 +1,11 @@
import GeoViewMap from '../components/GeoViewMap';
-import { DEFAULT_CONFIG_FILE } from '../constants';
import GeoViewPage from '../components/GeoViewPage';
function DefaultPage() {
return (
-
+
);
}
diff --git a/src/providers/cgpvContextProvider/cgpvHook.ts b/src/providers/cgpvContextProvider/cgpvHook.ts
index cbe6e89..8000b57 100644
--- a/src/providers/cgpvContextProvider/cgpvHook.ts
+++ b/src/providers/cgpvContextProvider/cgpvHook.ts
@@ -201,24 +201,25 @@ export function useCgpvHook(): ICgpvHook {
//throw new Error(`Element with id ${mapId} not found`);
}
- let configTxt = config;
+ let configTxt = '';
+ let configData = {};
if (typeof config !== 'string' && !configIsFilePath) {
configTxt = JSON.stringify(config);
+ configData = JSON.parse(configTxt as string);
}
if (configIsFilePath) {
const res = await readConfigFile(config as string);
+ configData = res;
configTxt = JSON.stringify(res)
}
- let configData = JSON.parse(configTxt as string);
if (_.get(configData, 'mapDimensions.width') === undefined) {
_.set(configData, 'mapDimensions.width', DEFAULT_MAP_WIDTH);
}
if (_.get(configData, 'mapDimensions.height') === undefined) {
_.set(configData, 'mapDimensions.height', DEFAULT_MAP_HEIGHT);
}
-
// setting dimensions of the map
mapElement?.setAttribute('style', `width: ${_.get(configData, 'mapDimensions.width')}; height: ${_.get(configData, 'mapDimensions.height')}`);
@@ -231,16 +232,18 @@ export function useCgpvHook(): ICgpvHook {
}
setConfigJson({ ...configData });
- cgpv.api.createMapFromConfig(mapId, configTxt);
- console.log('map created... initializing', configData);
-
- setTimeout(() => { // just a delay for animation purposes
- setIsLoading(false);
- }, 2500);
+ if (configIsFilePath) {
+ cgpv.api.createMapFromConfig(mapId, `${URL_TO_CONFIGS}${config}`, 800); // just use file directly if its a file path
+ } else {
+ cgpv.api.createMapFromConfig(mapId, configData);
+ }
+
+ setTimeout(() => { // just a delay for animation purposes
+ setIsLoading(false);
+ }, 2500);
cgpv.init(async () => {
- console.log('map created... initializing');
registerEventListeners(mapId);
-
+
});
};