@map-colonies/react-components 3.6.5 → 3.7.4
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 +52 -0
- package/dist/autocomplete/autocomplete.css +25 -0
- package/dist/autocomplete/autocomplete.d.ts +34 -0
- package/dist/autocomplete/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete/autocomplete.js +467 -0
- package/dist/autocomplete/autocomplete.js.map +1 -0
- package/dist/autocomplete/index.d.ts +2 -0
- package/dist/autocomplete/index.d.ts.map +1 -0
- package/dist/autocomplete/index.js +5 -0
- package/dist/autocomplete/index.js.map +1 -0
- package/dist/cesium-map/layers-manager.d.ts +3 -0
- package/dist/cesium-map/layers-manager.d.ts.map +1 -1
- package/dist/cesium-map/layers-manager.js +63 -0
- package/dist/cesium-map/layers-manager.js.map +1 -1
- package/dist/cesium-map/map.d.ts +20 -1
- package/dist/cesium-map/map.d.ts.map +1 -1
- package/dist/cesium-map/map.js +55 -11
- package/dist/cesium-map/map.js.map +1 -1
- package/dist/cesium-map/tools/geojson/point.geojson.d.ts +4 -0
- package/dist/cesium-map/tools/geojson/point.geojson.d.ts.map +1 -0
- package/dist/cesium-map/tools/geojson/point.geojson.js +20 -0
- package/dist/cesium-map/tools/geojson/point.geojson.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
- package/src/lib/autocomplete/autocomplete.css +25 -0
- package/src/lib/autocomplete/autocomplete.stories.tsx +101 -0
- package/src/lib/autocomplete/autocomplete.tsx +683 -0
- package/src/lib/autocomplete/get-input-selection.d.ts +1 -0
- package/src/lib/autocomplete/index.ts +1 -0
- package/src/lib/cesium-map/context-menu.stories.tsx +445 -0
- package/src/lib/cesium-map/layers-manager.ts +76 -0
- package/src/lib/cesium-map/map.tsx +94 -3
- package/src/lib/cesium-map/tools/geojson/point.geojson.ts +29 -0
- package/src/lib/index.ts +1 -0
|
@@ -16,18 +16,23 @@ import {
|
|
|
16
16
|
PerspectiveFrustum,
|
|
17
17
|
PerspectiveOffCenterFrustum,
|
|
18
18
|
OrthographicFrustum,
|
|
19
|
+
ScreenSpaceEventType,
|
|
19
20
|
} from 'cesium';
|
|
20
21
|
import { isNumber, isArray } from 'lodash';
|
|
21
|
-
|
|
22
22
|
import { getAltitude, toDegrees } from '../utils/map';
|
|
23
23
|
import { Box } from '../box';
|
|
24
|
-
import './map.css';
|
|
25
24
|
import { CoordinatesTrackerTool } from './tools/coordinates-tracker.tool';
|
|
26
25
|
import { ScaleTrackerTool } from './tools/scale-tracker.tool';
|
|
27
26
|
import { CesiumSettings, IBaseMap, IBaseMaps } from './settings/settings';
|
|
28
27
|
import LayerManager from './layers-manager';
|
|
29
28
|
import { CesiumSceneMode, CesiumSceneModeEnum, Proj } from '.';
|
|
30
29
|
|
|
30
|
+
import './map.css';
|
|
31
|
+
|
|
32
|
+
const DEFAULT_HEIGHT = 212;
|
|
33
|
+
const DEFAULT_WIDTH = 260;
|
|
34
|
+
const DEFAULT_DYNAMIC_HEIGHT_INCREMENT = 0;
|
|
35
|
+
|
|
31
36
|
interface ICameraPosition {
|
|
32
37
|
longitude: number;
|
|
33
38
|
latitude: number;
|
|
@@ -59,6 +64,20 @@ const mapContext = createContext<CesiumViewer | null>(null);
|
|
|
59
64
|
const MapViewProvider = mapContext.Provider;
|
|
60
65
|
const cameraPositionRefreshRate = 10000;
|
|
61
66
|
|
|
67
|
+
export interface IContextMenuData {
|
|
68
|
+
data: Record<string, unknown>[];
|
|
69
|
+
position: {
|
|
70
|
+
x: number;
|
|
71
|
+
y: number;
|
|
72
|
+
};
|
|
73
|
+
style?: Record<string, string>;
|
|
74
|
+
size?: {
|
|
75
|
+
height: number;
|
|
76
|
+
width: number;
|
|
77
|
+
};
|
|
78
|
+
handleClose: () => void;
|
|
79
|
+
}
|
|
80
|
+
|
|
62
81
|
export interface CesiumMapProps extends ViewerProps {
|
|
63
82
|
showMousePosition?: boolean;
|
|
64
83
|
showScale?: boolean;
|
|
@@ -68,6 +87,12 @@ export interface CesiumMapProps extends ViewerProps {
|
|
|
68
87
|
locale?: { [key: string]: string };
|
|
69
88
|
sceneModes?: CesiumSceneModeEnum[];
|
|
70
89
|
baseMaps?: IBaseMaps;
|
|
90
|
+
imageryContextMenu?: React.ReactElement<IContextMenuData>;
|
|
91
|
+
imageryContextMenuSize?: {
|
|
92
|
+
height: number;
|
|
93
|
+
width: number;
|
|
94
|
+
dynamicHeightIncrement?: number;
|
|
95
|
+
};
|
|
71
96
|
}
|
|
72
97
|
|
|
73
98
|
export const useCesiumMap = (): CesiumViewer => {
|
|
@@ -92,6 +117,10 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
92
117
|
CesiumSceneModeEnum[] | undefined
|
|
93
118
|
>();
|
|
94
119
|
const [baseMaps, setBaseMaps] = useState<IBaseMaps | undefined>();
|
|
120
|
+
const [showImageryMenu, setShowImageryMenu] = useState<boolean>(false);
|
|
121
|
+
const [imageryMenuPosition, setImageryMenuPosition] = useState<
|
|
122
|
+
Record<string, unknown> | undefined
|
|
123
|
+
>(undefined);
|
|
95
124
|
|
|
96
125
|
const viewerProps = {
|
|
97
126
|
fullscreenButton: true,
|
|
@@ -105,13 +134,47 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
105
134
|
...(props as ViewerProps),
|
|
106
135
|
};
|
|
107
136
|
|
|
137
|
+
const getImageryMenuStyle = (
|
|
138
|
+
x: number,
|
|
139
|
+
y: number,
|
|
140
|
+
menuWidth: number,
|
|
141
|
+
menuHeight: number,
|
|
142
|
+
menuDynamicHeightIncrement: number
|
|
143
|
+
): Record<string, string> => {
|
|
144
|
+
const container = (mapViewRef as CesiumViewer).container;
|
|
145
|
+
const mapWidth = container.clientWidth;
|
|
146
|
+
const mapHeight = container.clientHeight;
|
|
147
|
+
const calculatedHeight = menuHeight + menuDynamicHeightIncrement;
|
|
148
|
+
return {
|
|
149
|
+
left: `${
|
|
150
|
+
mapWidth - x < menuWidth ? x - (menuWidth - (mapWidth - x)) : x
|
|
151
|
+
}px`,
|
|
152
|
+
top: `${
|
|
153
|
+
mapHeight - y < calculatedHeight
|
|
154
|
+
? y - (calculatedHeight - (mapHeight - y))
|
|
155
|
+
: y
|
|
156
|
+
}px`,
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
|
|
108
160
|
useEffect(() => {
|
|
109
161
|
if (ref.current) {
|
|
110
162
|
const viewer = ref.current.cesiumElement as CesiumViewer;
|
|
111
163
|
viewer.layersManager = new LayerManager(viewer);
|
|
164
|
+
if (props.imageryContextMenu) {
|
|
165
|
+
viewer.screenSpaceEventHandler.setInputAction(
|
|
166
|
+
(evt: Record<string, unknown>) => {
|
|
167
|
+
// console.log('RIGHT click', evt.position);
|
|
168
|
+
setShowImageryMenu(false);
|
|
169
|
+
setImageryMenuPosition(evt.position as Record<string, unknown>);
|
|
170
|
+
setShowImageryMenu(true);
|
|
171
|
+
},
|
|
172
|
+
ScreenSpaceEventType.RIGHT_CLICK
|
|
173
|
+
);
|
|
174
|
+
}
|
|
112
175
|
}
|
|
113
176
|
setMapViewRef(ref.current?.cesiumElement);
|
|
114
|
-
}, [ref]);
|
|
177
|
+
}, [ref, props.imageryContextMenu]);
|
|
115
178
|
|
|
116
179
|
useEffect(() => {
|
|
117
180
|
setSceneModes(
|
|
@@ -272,6 +335,34 @@ export const CesiumMap: React.FC<CesiumMapProps> = (props) => {
|
|
|
272
335
|
)}
|
|
273
336
|
{showScale === true ? <ScaleTrackerTool locale={locale} /> : <></>}
|
|
274
337
|
</Box>
|
|
338
|
+
{props.imageryContextMenu &&
|
|
339
|
+
showImageryMenu &&
|
|
340
|
+
imageryMenuPosition &&
|
|
341
|
+
React.cloneElement(props.imageryContextMenu, {
|
|
342
|
+
data: (mapViewRef?.layersManager?.findLayerByPOI(
|
|
343
|
+
imageryMenuPosition.x as number,
|
|
344
|
+
imageryMenuPosition.y as number
|
|
345
|
+
) as unknown) as Record<string, unknown>[],
|
|
346
|
+
position: {
|
|
347
|
+
x: imageryMenuPosition.x as number,
|
|
348
|
+
y: imageryMenuPosition.y as number,
|
|
349
|
+
},
|
|
350
|
+
style: getImageryMenuStyle(
|
|
351
|
+
imageryMenuPosition.x as number,
|
|
352
|
+
imageryMenuPosition.y as number,
|
|
353
|
+
props.imageryContextMenuSize?.width ?? DEFAULT_WIDTH,
|
|
354
|
+
props.imageryContextMenuSize?.height ?? DEFAULT_HEIGHT,
|
|
355
|
+
props.imageryContextMenuSize?.dynamicHeightIncrement ??
|
|
356
|
+
DEFAULT_DYNAMIC_HEIGHT_INCREMENT
|
|
357
|
+
),
|
|
358
|
+
size: props.imageryContextMenuSize ?? {
|
|
359
|
+
height: DEFAULT_HEIGHT,
|
|
360
|
+
width: DEFAULT_WIDTH,
|
|
361
|
+
},
|
|
362
|
+
handleClose: () => {
|
|
363
|
+
setShowImageryMenu(!showImageryMenu);
|
|
364
|
+
},
|
|
365
|
+
})}
|
|
275
366
|
</MapViewProvider>
|
|
276
367
|
</Viewer>
|
|
277
368
|
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Math as CesiumMath, Cartesian3 } from 'cesium';
|
|
2
|
+
import { GeoJSON } from 'geojson';
|
|
3
|
+
import { CesiumViewer } from '../../map';
|
|
4
|
+
|
|
5
|
+
export const pointToGeoJSON = (
|
|
6
|
+
mapViewer: CesiumViewer,
|
|
7
|
+
x: number,
|
|
8
|
+
y: number
|
|
9
|
+
): GeoJSON => {
|
|
10
|
+
const ellipsoid = mapViewer.scene.globe.ellipsoid;
|
|
11
|
+
const cartesian = mapViewer.camera.pickEllipsoid(
|
|
12
|
+
new Cartesian3(x, y),
|
|
13
|
+
ellipsoid
|
|
14
|
+
);
|
|
15
|
+
const cartographic = ellipsoid.cartesianToCartographic(
|
|
16
|
+
cartesian as Cartesian3
|
|
17
|
+
);
|
|
18
|
+
return {
|
|
19
|
+
type: 'Feature',
|
|
20
|
+
properties: {},
|
|
21
|
+
geometry: {
|
|
22
|
+
type: 'Point',
|
|
23
|
+
coordinates: [
|
|
24
|
+
CesiumMath.toDegrees(cartographic.longitude),
|
|
25
|
+
CesiumMath.toDegrees(cartographic.latitude),
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
};
|
package/src/lib/index.ts
CHANGED