Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow theming mapstore with another css file #709

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
});
Loading
Loading