Skip to content

Commit

Permalink
feat: add new plugin to theme mapstore with css file.
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Apr 17, 2024
1 parent 6ac702f commit 3c1e3e6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
27 changes: 14 additions & 13 deletions configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"enabled": true,
"contextOnly": true
},
"stylesheetUri": "",
"header": {
"height": 90,
"url": "/header/",
Expand Down Expand Up @@ -265,7 +266,7 @@
"homePath": "/home"
},
"plugins": {
"mobile": ["Header", {
"mobile": ["Header", "Easytheming", {
"name": "Map",
"cfg": {
"mapOptions": {
Expand Down Expand Up @@ -378,11 +379,11 @@
"name": "MetadataExplorer",
"cfg": {
"serviceTypes": [
{ "name": "csw", "label": "CSW" },
{ "name": "wms", "label": "WMS" },
{ "name": "wmts", "label": "WMTS" },
{ "name": "tms", "label": "TMS", "allowedProviders": ["OpenStreetMap", "OpenSeaMap", "Stamen"] },
{ "name": "wfs", "label": "WFS" },
{ "name": "csw", "label": "CSW" },
{ "name": "wms", "label": "WMS" },
{ "name": "wmts", "label": "WMTS" },
{ "name": "tms", "label": "TMS", "allowedProviders": ["OpenStreetMap", "OpenSeaMap", "Stamen"] },
{ "name": "wfs", "label": "WFS" },
{ "name": "3dtiles", "label": "3D Tiles" },
{ "name": "cog", "label": "COG" }
]
Expand All @@ -393,7 +394,7 @@
"GlobeViewSwitcher"
],
"desktop": [
"Header",
"Header", "Easytheming",
"Details",
{
"name": "Map",
Expand Down Expand Up @@ -564,11 +565,11 @@
"zoomToLayer": false,
"wrap": true,
"serviceTypes": [
{ "name": "csw", "label": "CSW" },
{ "name": "wms", "label": "WMS" },
{ "name": "wmts", "label": "WMTS" },
{ "name": "tms", "label": "TMS", "allowedProviders": ["OpenStreetMap", "OpenSeaMap", "Stamen"] },
{ "name": "wfs", "label": "WFS" },
{ "name": "csw", "label": "CSW" },
{ "name": "wms", "label": "WMS" },
{ "name": "wmts", "label": "WMTS" },
{ "name": "tms", "label": "TMS", "allowedProviders": ["OpenStreetMap", "OpenSeaMap", "Stamen"] },
{ "name": "wfs", "label": "WFS" },
{ "name": "3dtiles", "label": "3D Tiles" },
{ "name": "cog", "label": "COG" }
]
Expand Down Expand Up @@ -1072,7 +1073,7 @@
"ContextExport"
],
"context": [
"Header"
"Header", "Easytheming"
]
}
}
2 changes: 2 additions & 0 deletions js/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import productPlugins from '@mapstore/product/plugins';

import NotAllowedPlugin from "@js/plugins/NotAllowed";
import HeaderPlugin from "@js/plugins/Header";
import EasyTheming from "@js/plugins/EasyTheming";
import UserSessionPlugin from "@js/plugins/UserSession";
import VersionPlugin from "@js/plugins/Version";
import BackgroundSelectorPlugin from '@mapstore/plugins/BackgroundSelector';
Expand All @@ -30,6 +31,7 @@ export default {
// georchestra plugins2
NotAllowedPlugin,
HeaderPlugin,
EasyTheming,
UserSessionPlugin,
VersionPlugin,
BackgroundSelectorPlugin // This is not lazy loaded because of this issue. https://github.com/georchestra/mapstore2-georchestra/issues/573
Expand Down
28 changes: 28 additions & 0 deletions js/plugins/EasyTheming.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import {useEffect} from "react";
import {createPlugin, connect} from "@mapstore/utils/PluginsUtils";

export const Easytheming = ({stylesheet = ""}) => {
useEffect(() => {
if (stylesheet) {
const link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", stylesheet);
document.head.appendChild(link);
}
}, []);
return null;
};

export default createPlugin('Easytheming', {
component: connect((state) => ({
stylesheet: state.localConfig && state.localConfig.stylesheetUri
}))(Easytheming)
});
7 changes: 0 additions & 7 deletions js/plugins/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ export const Header = ({url = "/header/", page = "mapstore", height = 90, ignore
header.setAttribute("logo-url", logoUrl);
header.setAttribute("stylesheet", stylesheet);
headerScript.src = script;
if (stylesheet) {
const link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", stylesheet);
document.head.appendChild(link);
}

if (container) {
container.style.top = height + "px";
Expand Down

0 comments on commit 3c1e3e6

Please sign in to comment.