Skip to content

Commit

Permalink
feat: implement new header
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Nov 10, 2023
1 parent 59e7d1d commit a233d0b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ coverage/
backend/.classpath
backend/.project
package-lock.json
.idea/
4 changes: 3 additions & 1 deletion configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
},
"header": {
"height": 90,
"url": "/header/"
"url": "/header/",
"script": "https://cdn.jsdelivr.net/gh/georchestra/header@dist/header.js",
"legacy": false
},
"defaultMapOptions": {
"cesium": {
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
width: 100%;
height: 90px;
border: none;
overflow: hidden;
overflow: visible;
position: absolute;
}
#container {
Expand All @@ -124,7 +124,7 @@

</head>
<body>
<iframe id="georchestra-header" src="header.html" scrolling="no" frameBorder="0"></iframe>
<div id="georchestra-header"></div>
<div id="container">
<div class="_ms2_init_spinner _ms2_init_center"><div></div></div>
<div class="_ms2_init_text _ms2_init_center">Loading</div>
Expand Down
4 changes: 2 additions & 2 deletions indexTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
width: 100%;
height: 90px;
border: none;
overflow: hidden;
overflow: visible;
position: absolute;
}
#container {
Expand Down Expand Up @@ -137,7 +137,7 @@
</script>
</head>
<body>
<iframe id="georchestra-header" src="header.html" scrolling="no" frameBorder="0"></iframe>
<div id="georchestra-header"></div>
<div id="container">
<div class="_ms2_init_spinner _ms2_init_center"><div></div></div>
<div class="_ms2_init_text _ms2_init_center">Loading</div>
Expand Down
28 changes: 24 additions & 4 deletions js/plugins/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,39 @@
import {useEffect} from "react";
import { createPlugin, connect } from "@mapstore/utils/PluginsUtils";

export const Header = ({url = "/header/", page = "mapstore", height = 90, ignoreIFrame = false}) => {
export const Header = ({url = "/header/", page = "mapstore", height = 90, ignoreIFrame = false, script = "https://cdn.jsdelivr.net/gh/georchestra/header@dist/header.js", legacy = false}) => {
useEffect(() => {
const header = document.getElementById("georchestra-header");
const container = document.getElementById("container");
if (header) {
// Prevent creation of multiple headers
const existingGeorHeader = document.getElementsByTagName("geor-header");
if (existingGeorHeader?.length > 0) {
existingGeorHeader[0].remove();
}
const existingScript = document.querySelectorAll("script[src='" + script + "']");
if (existingScript?.length > 0) {
existingScript[0].remove();
}
if (!ignoreIFrame && window.location !== window.parent.location) {
header.style.display = 'none';
if (container) {
container.style.top = '0';
}
} else {
header.style.display = 'block';
header.src = url + "?active=" + page;
const georHeader = document.createElement("geor-header");
const georHeaderScript = document.createElement("script");

georHeader.setAttribute("active-app", page);
georHeader.setAttribute("legacy-header", false);
georHeader.setAttribute("legacy-url", url);
georHeader.setAttribute("legacy-header", legacy);
georHeaderScript.src = script;
header.style.height = height + "px";


header.appendChild(georHeader);
header.appendChild(georHeaderScript);
if (container) {
container.style.top = height + "px";
}
Expand All @@ -36,6 +54,8 @@ export const Header = ({url = "/header/", page = "mapstore", height = 90, ignore
export default createPlugin('Header', {
component: connect((state) => ({
url: state.localConfig && state.localConfig.header && state.localConfig.header.url,
height: state.localConfig && state.localConfig.header && state.localConfig.header.height
height: state.localConfig && state.localConfig.header && state.localConfig.header.height,
script: state.localConfig && state.localConfig.header && state.localConfig.header.script,
legacy: state.localConfig && state.localConfig.header && state.localConfig.header.legacy
}))(Header)
});
2 changes: 1 addition & 1 deletion web/src/main/resources/mapstore.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

datadir.location=${georchestra.extensions:},${georchestra.datadir}/mapstore
overrides.config=../default.properties
overrides.mappings=header.url=headerUrl,header.height=headerHeight
overrides.mappings=header.url=headerUrl,header.height=headerHeight,header.script=headerScript,header.legacy=useLegacyHeader

0 comments on commit a233d0b

Please sign in to comment.