@map-colonies/react-components 3.12.3 → 3.13.1
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/CHANGELOG.md +22 -0
- package/dist/cesium-map/data-sources/drawings.data-source.js +6 -0
- package/dist/cesium-map/map-legend/MapLegend.css +3 -2
- package/dist/cesium-map/map.d.ts +4 -0
- package/dist/cesium-map/map.js +9 -3
- package/dist/cesium-map/proxied.types.d.ts +1 -1
- package/dist/cesium-map/proxied.types.js +2 -1
- package/dist/cesium-map/tools/coordinates-tracker.tool.js +15 -11
- package/dist/cesium-map/tools/geojson/point.geojson.d.ts +4 -0
- package/dist/cesium-map/tools/geojson/point.geojson.js +26 -4
- package/jest_html_reporters.html +78 -0
- package/package.json +2 -2
- package/src/lib/cesium-map/data-sources/drawings.data-source.tsx +9 -0
- package/src/lib/cesium-map/layers/geojson.layer.stories.tsx +64 -3
- package/src/lib/cesium-map/map-legend/MapLegend.css +3 -2
- package/src/lib/cesium-map/map.tsx +14 -1
- package/src/lib/cesium-map/proxied.types.ts +5 -1
- package/src/lib/cesium-map/tools/coordinates-tracker.tool.tsx +13 -12
- package/src/lib/cesium-map/tools/geojson/point.geojson.ts +43 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@map-colonies/react-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.1",
|
|
4
4
|
"module": "dist/index.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"jest-enzyme": "^7.1.2",
|
|
94
94
|
"react-test-renderer": "^16.13.1"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "2b22c0f4e5e2b632bd656ec88b29a4d02d339af0",
|
|
97
97
|
"jest": {
|
|
98
98
|
"coverageReporters": [
|
|
99
99
|
"text",
|
|
@@ -76,6 +76,9 @@ export const CesiumDrawingsDataSource: React.FC<RCesiumDrawingDataSourceProps> =
|
|
|
76
76
|
if (drawState.drawing) {
|
|
77
77
|
switch (drawState.type) {
|
|
78
78
|
case DrawType.POLYGON:
|
|
79
|
+
// Disable terrain accounting before drawing.
|
|
80
|
+
mapViewer.scene.globe.depthTestAgainstTerrain = false;
|
|
81
|
+
|
|
79
82
|
// eslint-disable-next-line
|
|
80
83
|
drawHelperInstance.startDrawingPolygon({
|
|
81
84
|
callback: (positions: PrimitiveCoordinates) => {
|
|
@@ -100,6 +103,9 @@ export const CesiumDrawingsDataSource: React.FC<RCesiumDrawingDataSourceProps> =
|
|
|
100
103
|
});
|
|
101
104
|
break;
|
|
102
105
|
case DrawType.BOX:
|
|
106
|
+
// Disable terrain accounting before drawing.
|
|
107
|
+
mapViewer.scene.globe.depthTestAgainstTerrain = false;
|
|
108
|
+
|
|
103
109
|
// eslint-disable-next-line
|
|
104
110
|
drawHelperInstance.startDrawingExtent({
|
|
105
111
|
callback: (positions: PrimitiveCoordinates) => {
|
|
@@ -131,6 +137,9 @@ export const CesiumDrawingsDataSource: React.FC<RCesiumDrawingDataSourceProps> =
|
|
|
131
137
|
} else {
|
|
132
138
|
// eslint-disable-next-line
|
|
133
139
|
drawHelperInstance.stopDrawing();
|
|
140
|
+
|
|
141
|
+
// Enable terrain accounting after drawing.
|
|
142
|
+
mapViewer.scene.globe.depthTestAgainstTerrain = true;
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
}, [drawState, drawHelper]);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Color } from 'cesium';
|
|
2
3
|
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
3
4
|
import { action } from '@storybook/addon-actions';
|
|
4
|
-
import { Color } from 'cesium';
|
|
5
5
|
import { CesiumMap } from '../map';
|
|
6
|
+
import { LayerType } from '../layers-manager';
|
|
6
7
|
import { CesiumGeojsonLayer } from './geojson.layer';
|
|
7
8
|
|
|
8
9
|
export default {
|
|
@@ -19,6 +20,32 @@ const mapDivStyle = {
|
|
|
19
20
|
position: 'absolute' as const,
|
|
20
21
|
};
|
|
21
22
|
|
|
23
|
+
const BASE_MAPS = {
|
|
24
|
+
maps: [
|
|
25
|
+
{
|
|
26
|
+
id: '1st',
|
|
27
|
+
title: '1st Map Title',
|
|
28
|
+
isCurrent: true,
|
|
29
|
+
thumbnail:
|
|
30
|
+
'https://nsw.digitaltwin.terria.io/build/efa2f6c408eb790753a9b5fb2f3dc678.png',
|
|
31
|
+
baseRasteLayers: [
|
|
32
|
+
{
|
|
33
|
+
id: 'GOOGLE_TERRAIN',
|
|
34
|
+
type: 'XYZ_LAYER' as LayerType,
|
|
35
|
+
opacity: 1,
|
|
36
|
+
zIndex: 0,
|
|
37
|
+
options: {
|
|
38
|
+
url: 'https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
|
|
39
|
+
layers: '',
|
|
40
|
+
credit: 'GOOGLE',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
baseVectorLayers: [],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
22
49
|
const data = {
|
|
23
50
|
type: 'FeatureCollection',
|
|
24
51
|
features: [
|
|
@@ -82,14 +109,33 @@ const data = {
|
|
|
82
109
|
],
|
|
83
110
|
},
|
|
84
111
|
},
|
|
112
|
+
{
|
|
113
|
+
type: 'Feature',
|
|
114
|
+
geometry: {
|
|
115
|
+
type: 'MultiPolygon',
|
|
116
|
+
coordinates: [
|
|
117
|
+
[
|
|
118
|
+
[
|
|
119
|
+
[34.846843864982802, 32.068999681029801],
|
|
120
|
+
[34.863785627992797, 32.059005944018601],
|
|
121
|
+
[34.8773961450173, 32.068047896040397],
|
|
122
|
+
[34.880441855011703, 32.052819346068603],
|
|
123
|
+
[34.878633463995797, 32.0466327470143],
|
|
124
|
+
[34.8605495609931, 32.048821851014601],
|
|
125
|
+
[34.846843864982802, 32.068999681029801],
|
|
126
|
+
],
|
|
127
|
+
],
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
85
131
|
],
|
|
86
132
|
};
|
|
87
133
|
|
|
88
134
|
const onLoadAction = action('onLoad');
|
|
89
135
|
|
|
90
|
-
export const MapWithGeojsonLayer: Story = () => (
|
|
136
|
+
export const MapWithGeojsonLayer: Story = (args: unknown) => (
|
|
91
137
|
<div style={mapDivStyle}>
|
|
92
|
-
<CesiumMap>
|
|
138
|
+
<CesiumMap {...args}>
|
|
93
139
|
<CesiumGeojsonLayer
|
|
94
140
|
data={data}
|
|
95
141
|
markerColor={Color.RED}
|
|
@@ -116,4 +162,19 @@ export const MapWithGeojsonLayer: Story = () => (
|
|
|
116
162
|
</CesiumMap>
|
|
117
163
|
</div>
|
|
118
164
|
);
|
|
165
|
+
|
|
166
|
+
MapWithGeojsonLayer.argTypes = {
|
|
167
|
+
baseMaps: {
|
|
168
|
+
defaultValue: BASE_MAPS,
|
|
169
|
+
},
|
|
170
|
+
zoom: {
|
|
171
|
+
defaultValue: 17,
|
|
172
|
+
control: {
|
|
173
|
+
type: 'range',
|
|
174
|
+
min: 0,
|
|
175
|
+
max: 20,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
119
180
|
MapWithGeojsonLayer.storyName = 'GeoJson layer';
|
|
@@ -33,6 +33,7 @@ import LayerManager, { LegendExtractor } from './layers-manager';
|
|
|
33
33
|
import { CesiumSceneMode, CesiumSceneModeEnum } from './map.types';
|
|
34
34
|
|
|
35
35
|
import './map.css';
|
|
36
|
+
import { pointToLonLat } from './tools/geojson/point.geojson';
|
|
36
37
|
|
|
37
38
|
const DEFAULT_HEIGHT = 212;
|
|
38
39
|
const DEFAULT_WIDTH = 260;
|
|
@@ -76,6 +77,7 @@ export interface IContextMenuData {
|
|
|
76
77
|
x: number;
|
|
77
78
|
y: number;
|
|
78
79
|
};
|
|
80
|
+
coordinates: { latitude: number; longitude: number };
|
|
79
81
|
style?: Record<string, string>;
|
|
80
82
|
size?: {
|
|
81
83
|
height: number;
|
|
@@ -141,6 +143,10 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
141
143
|
const [isLegendsSidebarOpen, setIsLegendsSidebarOpen] = useState<boolean>(
|
|
142
144
|
false
|
|
143
145
|
);
|
|
146
|
+
const [rightClickCoordinates, setRightClickCoordinates] = useState<{
|
|
147
|
+
longitude: number;
|
|
148
|
+
latitude: number;
|
|
149
|
+
}>();
|
|
144
150
|
|
|
145
151
|
const viewerProps = {
|
|
146
152
|
fullscreenButton: true,
|
|
@@ -185,8 +191,13 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
185
191
|
viewer.screenSpaceEventHandler.setInputAction(
|
|
186
192
|
(evt: Record<string, unknown>) => {
|
|
187
193
|
// console.log('RIGHT click', evt.position);
|
|
194
|
+
const pos = evt.position as Record<string, unknown>;
|
|
195
|
+
|
|
188
196
|
setShowImageryMenu(false);
|
|
189
|
-
setImageryMenuPosition(
|
|
197
|
+
setImageryMenuPosition(pos);
|
|
198
|
+
setRightClickCoordinates(
|
|
199
|
+
pointToLonLat(viewer, pos.x as number, pos.y as number)
|
|
200
|
+
);
|
|
190
201
|
setShowImageryMenu(true);
|
|
191
202
|
},
|
|
192
203
|
ScreenSpaceEventType.RIGHT_CLICK
|
|
@@ -415,6 +426,7 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
415
426
|
{props.imageryContextMenu &&
|
|
416
427
|
showImageryMenu &&
|
|
417
428
|
imageryMenuPosition &&
|
|
429
|
+
rightClickCoordinates &&
|
|
418
430
|
React.cloneElement(props.imageryContextMenu, {
|
|
419
431
|
data: (mapViewRef?.layersManager?.findLayerByPOI(
|
|
420
432
|
imageryMenuPosition.x as number,
|
|
@@ -424,6 +436,7 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
424
436
|
x: imageryMenuPosition.x as number,
|
|
425
437
|
y: imageryMenuPosition.y as number,
|
|
426
438
|
},
|
|
439
|
+
coordinates: rightClickCoordinates,
|
|
427
440
|
style: getImageryMenuStyle(
|
|
428
441
|
imageryMenuPosition.x as number,
|
|
429
442
|
imageryMenuPosition.y as number,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
Rectangle,
|
|
15
15
|
Resource,
|
|
16
16
|
VerticalOrigin,
|
|
17
|
+
Math,
|
|
17
18
|
} from 'cesium';
|
|
18
19
|
|
|
19
20
|
// PROXIED CLASSES
|
|
@@ -51,4 +52,7 @@ export const CesiumVerticalOrigin = VerticalOrigin;
|
|
|
51
52
|
export const CesiumLabelStyle = LabelStyle;
|
|
52
53
|
|
|
53
54
|
// PROXIED FUNCTIONS
|
|
54
|
-
export {
|
|
55
|
+
export {
|
|
56
|
+
sampleTerrainMostDetailed as cesiumSampleTerrainMostDetailed,
|
|
57
|
+
Math as CesiumMath,
|
|
58
|
+
} from 'cesium';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { Cartesian3, Math as CesiumMath, WebMercatorProjection } from 'cesium';
|
|
2
|
+
import { Cartesian3, Math as CesiumMath, WebMercatorProjection, ScreenSpaceEventType } from 'cesium';
|
|
3
3
|
import { CesiumViewer, useCesiumMap } from '../map';
|
|
4
4
|
|
|
5
5
|
import './coordinates-tracker.tool.css';
|
|
@@ -21,17 +21,17 @@ export const CoordinatesTrackerTool: React.FC<RCoordinatesTrackerToolProps> = (
|
|
|
21
21
|
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
22
22
|
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
mapViewer.screenSpaceEventHandler.setInputAction(
|
|
25
|
+
(evt?: Record<string, unknown>) => {
|
|
26
|
+
if (evt?.endPosition) {
|
|
27
|
+
setPosition({ ...(evt.endPosition as { x: number; y: number }) } as {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
ScreenSpaceEventType.MOUSE_MOVE
|
|
34
|
+
);
|
|
35
35
|
}, [ref, mapViewer]);
|
|
36
36
|
|
|
37
37
|
useEffect(() => {
|
|
@@ -41,6 +41,7 @@ export const CoordinatesTrackerTool: React.FC<RCoordinatesTrackerToolProps> = (
|
|
|
41
41
|
new Cartesian3(position.x, position.y),
|
|
42
42
|
ellipsoid
|
|
43
43
|
);
|
|
44
|
+
|
|
44
45
|
if (cartesian) {
|
|
45
46
|
const cartographic = ellipsoid.cartesianToCartographic(cartesian);
|
|
46
47
|
if (ref.current) {
|
|
@@ -1,20 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Math as CesiumMath,
|
|
3
|
+
Cartesian3,
|
|
4
|
+
Cartographic,
|
|
5
|
+
SceneMode,
|
|
6
|
+
Cartesian2,
|
|
7
|
+
} from 'cesium';
|
|
2
8
|
import { GeoJSON } from 'geojson';
|
|
3
9
|
import { CesiumViewer } from '../../map';
|
|
4
10
|
|
|
11
|
+
const pointToCartographic = (
|
|
12
|
+
mapViewer: CesiumViewer,
|
|
13
|
+
x: number,
|
|
14
|
+
y: number
|
|
15
|
+
): Cartographic => {
|
|
16
|
+
let cartesian;
|
|
17
|
+
|
|
18
|
+
if (mapViewer.scene.mode !== SceneMode.SCENE2D) {
|
|
19
|
+
cartesian = mapViewer.scene.pickPosition(new Cartesian2(x, y));
|
|
20
|
+
} else {
|
|
21
|
+
const ellipsoid = mapViewer.scene.globe.ellipsoid;
|
|
22
|
+
cartesian = mapViewer.camera.pickEllipsoid(new Cartesian2(x, y), ellipsoid);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return Cartographic.fromCartesian(cartesian as Cartesian3);
|
|
26
|
+
};
|
|
27
|
+
|
|
5
28
|
export const pointToGeoJSON = (
|
|
6
29
|
mapViewer: CesiumViewer,
|
|
7
30
|
x: number,
|
|
8
31
|
y: number
|
|
9
32
|
): GeoJSON => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
new Cartesian3(x, y),
|
|
13
|
-
ellipsoid
|
|
14
|
-
);
|
|
15
|
-
const cartographic = ellipsoid.cartesianToCartographic(
|
|
16
|
-
cartesian as Cartesian3
|
|
17
|
-
);
|
|
33
|
+
const cartographic = pointToCartographic(mapViewer, x, y);
|
|
34
|
+
|
|
18
35
|
return {
|
|
19
36
|
type: 'Feature',
|
|
20
37
|
properties: {},
|
|
@@ -27,3 +44,20 @@ export const pointToGeoJSON = (
|
|
|
27
44
|
},
|
|
28
45
|
};
|
|
29
46
|
};
|
|
47
|
+
|
|
48
|
+
export const pointToLonLat = (
|
|
49
|
+
mapViewer: CesiumViewer,
|
|
50
|
+
x: number,
|
|
51
|
+
y: number
|
|
52
|
+
): { longitude: number; latitude: number } | undefined => {
|
|
53
|
+
try {
|
|
54
|
+
const cartographic = pointToCartographic(mapViewer, x, y);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
longitude: CesiumMath.toDegrees(cartographic.longitude),
|
|
58
|
+
latitude: CesiumMath.toDegrees(cartographic.latitude),
|
|
59
|
+
};
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
};
|