@indiscale/linkahead-webui-ext-map 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +45 -0
- package/.gitlab-ci.yml +44 -0
- package/CHANGELOG.md +78 -0
- package/README.md +97 -0
- package/RELEASE_GUIDELINES.md +45 -0
- package/__mocks__/fileMock.js +3 -0
- package/__mocks__/styleMock.js +1 -0
- package/babel.config.js +22 -0
- package/cypress/e2e/standalone-map.cy.js +55 -0
- package/cypress/support/commands.js +25 -0
- package/cypress/support/e2e.js +17 -0
- package/cypress.config.js +10 -0
- package/dist/2b3e1faf89f94a483539.png +0 -0
- package/dist/416d91365b44e4b4f477.png +0 -0
- package/dist/8f2c4d11474275fbc161.png +0 -0
- package/dist/index.html +1 -0
- package/dist/linkahead-webui-ext-map.js +3 -0
- package/dist/linkahead-webui-ext-map.js.LICENSE.txt +45 -0
- package/dist/linkahead-webui-ext-map.js.map +1 -0
- package/iframe/index.html +6 -0
- package/indiscale-linkahead-webui-ext-map-0.4.1.tgz +0 -0
- package/jest.config.js +23 -0
- package/jest.setup.js +2 -0
- package/package.json +105 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +11 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +25 -0
- package/public/map_tile_caosdb_logo.png +0 -0
- package/public/mock.js +41 -0
- package/public/robots.txt +3 -0
- package/select_query.json +3 -0
- package/src/AllMapEntities.tsx +294 -0
- package/src/CurrentPageEntities.js +318 -0
- package/src/Map.helpers.css +8 -0
- package/src/Map.helpers.js +536 -0
- package/src/Map.js +288 -0
- package/src/Map.test.js +252 -0
- package/src/MapConfig.js +75 -0
- package/src/__snapshots__/Map.test.js.snap +1725 -0
- package/src/components/Coordinates.js +24 -0
- package/src/components/ErrorComponent.tsx +2 -0
- package/src/components/Graticule.js +27 -0
- package/src/components/Loader.module.css +17 -0
- package/src/components/Loader.tsx +36 -0
- package/src/components/PathDropDown.js +108 -0
- package/src/components/SearchControl.js +502 -0
- package/src/components/ToggleMapButton.js +194 -0
- package/src/components/ViewChangeControl.js +104 -0
- package/src/constants/index.js +1 -0
- package/src/context/ConfigProvider.test.js +232 -0
- package/src/context/ConfigProvider.tsx +189 -0
- package/src/context/LoadingProvider.test.js +124 -0
- package/src/context/LoadingProvider.tsx +117 -0
- package/src/context/PathIdProvider.js +102 -0
- package/src/contrib/latlnggraticule/LICENSE +20 -0
- package/src/contrib/latlnggraticule/README.md +68 -0
- package/src/contrib/latlnggraticule/leaflet.latlng-graticule.js +528 -0
- package/src/contrib/simplegraticule/L.Graticule.js +138 -0
- package/src/default_config.json +57 -0
- package/src/global.d.ts +8 -0
- package/src/index.js +6 -0
- package/src/index.scss +133 -0
- package/src/logging.js +7 -0
- package/src/renderHtmlTemplate.test.js +60 -0
- package/src/select-search.min.svg +1 -0
- package/src/select-search.svg +46 -0
- package/src/setupTests.js +5 -0
- package/src/utils/GenerateQueryString.js +200 -0
- package/src/utils/GenerateQueryString.test.js +304 -0
- package/src/utils/index.ts +3 -0
- package/standalone.config.js +5 -0
- package/static/map_tile_caosdb_logo.png +0 -0
- package/tsconfig.json +25 -0
- package/webpack.config.js +193 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import L from "leaflet";
|
|
2
|
+
import { useMap } from "react-leaflet";
|
|
3
|
+
import "leaflet.coordinates/dist/Leaflet.Coordinates-0.1.5.min.js";
|
|
4
|
+
import { logger } from "../logging";
|
|
5
|
+
|
|
6
|
+
export function Coordinates() {
|
|
7
|
+
const map = useMap();
|
|
8
|
+
|
|
9
|
+
const coordinates = L.control.coordinates({
|
|
10
|
+
// TODO move to config
|
|
11
|
+
position: "bottomleft",
|
|
12
|
+
decimals: 2,
|
|
13
|
+
enableUserInput: false,
|
|
14
|
+
useDMS: true,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (!map._coordinates) {
|
|
18
|
+
logger.trace("Coordinates", map);
|
|
19
|
+
map._coordinates = coordinates;
|
|
20
|
+
coordinates.addTo(map);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import L from "leaflet";
|
|
3
|
+
import "../contrib/latlnggraticule/leaflet.latlng-graticule.js";
|
|
4
|
+
import "../contrib/simplegraticule/L.Graticule.js";
|
|
5
|
+
import { useMap } from "react-leaflet";
|
|
6
|
+
import { logger } from "../logging";
|
|
7
|
+
|
|
8
|
+
export function Graticule({ config }) {
|
|
9
|
+
const map = useMap();
|
|
10
|
+
|
|
11
|
+
if (config.type === "latlngGraticule") {
|
|
12
|
+
L.latlngGraticule(config.options).addTo(map);
|
|
13
|
+
} else if (typeof config.type === "undefined" || config.type === "simple") {
|
|
14
|
+
L.graticule(config.options).addTo(map);
|
|
15
|
+
} else {
|
|
16
|
+
logger.warn("unknown graticule type: ", config.type);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Graticule.propTypes = {
|
|
23
|
+
config: PropTypes.shape({
|
|
24
|
+
options: PropTypes.object,
|
|
25
|
+
type: PropTypes.oneOf(["simple", "latlngGraticule"]),
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.loader {
|
|
2
|
+
top: 50%;
|
|
3
|
+
left: 50%;
|
|
4
|
+
transform: translate(-50%, -50%);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.spinnerM {
|
|
8
|
+
--bs-spinner-width: 3rem;
|
|
9
|
+
--bs-spinner-height: 3rem;
|
|
10
|
+
}
|
|
11
|
+
.loaderFullScreen {
|
|
12
|
+
position: fixed;
|
|
13
|
+
}
|
|
14
|
+
.loaderInMap {
|
|
15
|
+
position: absolute;
|
|
16
|
+
z-index: 10000;
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
import styles from "./Loader.module.css";
|
|
3
|
+
import { LoadingInfo } from "@indiscale/linkahead-webui-core-components";
|
|
4
|
+
|
|
5
|
+
type TLoaderProps = {
|
|
6
|
+
className?: string;
|
|
7
|
+
size?: "sm";
|
|
8
|
+
color?: "primary" | "secondary";
|
|
9
|
+
title?: string;
|
|
10
|
+
inMap?: boolean;
|
|
11
|
+
dataTestId?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const Loader = ({
|
|
15
|
+
className = styles.spinnerM,
|
|
16
|
+
size,
|
|
17
|
+
color = "primary",
|
|
18
|
+
title,
|
|
19
|
+
inMap = false,
|
|
20
|
+
dataTestId = "loader",
|
|
21
|
+
}: TLoaderProps) => {
|
|
22
|
+
const props = { className, size, color, title };
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
data-testid={dataTestId}
|
|
27
|
+
className={
|
|
28
|
+
inMap
|
|
29
|
+
? `${styles.loader} ${styles.loaderInMap}`
|
|
30
|
+
: `${styles.loader} ${styles.loaderFullScreen}`
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
<LoadingInfo {...props} />
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import { logger } from "../logging";
|
|
3
|
+
import L from "leaflet";
|
|
4
|
+
import { useMap } from "react-leaflet";
|
|
5
|
+
import { useConfig } from "../context/ConfigProvider";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Return a new leaflet control for setting paths to use for geo location
|
|
9
|
+
*
|
|
10
|
+
* @param {function} callback - a callback applies the effect of a
|
|
11
|
+
* changed path
|
|
12
|
+
* @param {string[]} paths - ids of the paths defined for this map.
|
|
13
|
+
*
|
|
14
|
+
* @returns {L.Control} the drop down menu button.
|
|
15
|
+
*/
|
|
16
|
+
const get_path_ddm = function (callback, paths) {
|
|
17
|
+
logger.trace("get_path_ddm", callback, paths);
|
|
18
|
+
|
|
19
|
+
var path_ddm = L.Control.extend({
|
|
20
|
+
options: {
|
|
21
|
+
position: "bottomright",
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
onAdd: function () {
|
|
25
|
+
return this.button;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
setValue: function (value) {
|
|
29
|
+
this.button.value = value;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
button: (function () {
|
|
33
|
+
var select = L.DomUtil.create(
|
|
34
|
+
"select",
|
|
35
|
+
"leaflet-bar leaflet-control leaflet-control-custom caosdb-f-map-path-drop-down"
|
|
36
|
+
);
|
|
37
|
+
select.title = `Show the location of related entities.
|
|
38
|
+
By default ('Same Entity') entities are shown that have
|
|
39
|
+
a geographic location. The other options allow to show
|
|
40
|
+
entities on the map using the location of a related
|
|
41
|
+
entity.`;
|
|
42
|
+
|
|
43
|
+
let tmp_html = '<option value="same">Same Entity</option>';
|
|
44
|
+
for (let pa in paths) {
|
|
45
|
+
tmp_html += `<option value="${pa}">${pa}</option>`;
|
|
46
|
+
}
|
|
47
|
+
select.innerHTML = tmp_html;
|
|
48
|
+
|
|
49
|
+
L.DomEvent.on(select, "change", (e) => {
|
|
50
|
+
callback(e);
|
|
51
|
+
});
|
|
52
|
+
return select;
|
|
53
|
+
})(),
|
|
54
|
+
});
|
|
55
|
+
return new path_ddm();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const path_drop_down_handler = {
|
|
59
|
+
_control: undefined,
|
|
60
|
+
_callback: console.log,
|
|
61
|
+
_paths: [],
|
|
62
|
+
_current_path: undefined,
|
|
63
|
+
|
|
64
|
+
addHooks: function () {
|
|
65
|
+
this._control = get_path_ddm(this._callback, this._paths);
|
|
66
|
+
this._map.addControl(this._control);
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
removeHooks: function () {
|
|
70
|
+
this._map.removeControl(this._control);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
setCurrentPath: function (path) {
|
|
74
|
+
logger.trace("setCurrentPath", this, path);
|
|
75
|
+
this._control.setValue(path);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function PathDropDown({ setCurrentPath, currentPath }) {
|
|
80
|
+
const {
|
|
81
|
+
config: {
|
|
82
|
+
select: { paths },
|
|
83
|
+
},
|
|
84
|
+
} = useConfig();
|
|
85
|
+
|
|
86
|
+
logger.trace("PathDropDown", setCurrentPath, currentPath, paths);
|
|
87
|
+
const map = useMap();
|
|
88
|
+
|
|
89
|
+
if (!map.path_drop_down) {
|
|
90
|
+
path_drop_down_handler._callback = (e) => {
|
|
91
|
+
setCurrentPath(e.target.value);
|
|
92
|
+
};
|
|
93
|
+
path_drop_down_handler._paths = paths;
|
|
94
|
+
const handler = L.Handler.extend(path_drop_down_handler);
|
|
95
|
+
|
|
96
|
+
map.addHandler("path_drop_down", handler);
|
|
97
|
+
map.path_drop_down.enable();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
map.path_drop_down.setCurrentPath(currentPath);
|
|
101
|
+
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
PathDropDown.propTypes = {
|
|
106
|
+
setCurrentPath: PropTypes.func,
|
|
107
|
+
currentPath: PropTypes.string,
|
|
108
|
+
};
|