@tmlmobilidade/ui 20250307.1656.54 → 20250307.1723.25
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/dist/index.d.ts +29 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/map.utils.js +90 -3
- package/dist/src/lib/map.utils.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -644,4 +644,32 @@ declare function useSearchQuery<T>(data: T[], { accessors, customSearch, debounc
|
|
644
644
|
setSearchQuery: React$1.Dispatch<React$1.SetStateAction<string | undefined>>;
|
645
645
|
};
|
646
646
|
|
647
|
-
|
647
|
+
interface CenterMapOptions {
|
648
|
+
padding: number;
|
649
|
+
}
|
650
|
+
/**
|
651
|
+
*
|
652
|
+
* @param mapObject The map that should be manipulated
|
653
|
+
* @param features The features to center the map on
|
654
|
+
* @param options Optional settings to customize the centering
|
655
|
+
*/
|
656
|
+
declare const centerMap: (mapObject: any, features: GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>[], options?: CenterMapOptions) => void;
|
657
|
+
/**
|
658
|
+
*
|
659
|
+
* @param mapObject THe map that should be manipulated
|
660
|
+
* @param coordinates The destination coordinates to move the map to
|
661
|
+
* @param options Optional settings to customize the movement
|
662
|
+
*/
|
663
|
+
declare const moveMap: (mapObject: any, coordinates: GeoJSON.Position) => void;
|
664
|
+
/**
|
665
|
+
* Return a base GeoJSON Feature for LineString object
|
666
|
+
* @returns A GeoJSON Feature for LineString object with an empty features array
|
667
|
+
*/
|
668
|
+
declare const getBaseGeoJsonFeatureLineString: () => GeoJSON.Feature<GeoJSON.LineString>;
|
669
|
+
/**
|
670
|
+
* Return a base GeoJSON FeatureCollection object
|
671
|
+
* @returns A GeoJSON FeatureCollection object with an empty features array
|
672
|
+
*/
|
673
|
+
declare const getBaseGeoJsonFeatureCollection: () => GeoJSON.FeatureCollection<GeoJSON.LineString | GeoJSON.Point, GeoJSON.GeoJsonProperties>;
|
674
|
+
|
675
|
+
export { ActionIcon, AppProvider, type AppProviderProps, AppWrapper, Badge, Button, CMIcon, CMLogo, Checkbox, ComboboxComponent as Combobox, type DataItem, DataTable, type DataTableColumn, type DataTableColumnProps, type DataTableHeaderProps, type DataTableProps, type DataTableRowProps, type DataTableSearchProps, type DataTableTitleProps, DateTimePicker, DeleteActionIcon, Description, FileButton, Grid, Label, type MapStyle, MapView, MapViewStyleActiveStops, MapViewStyleActiveStopsInteractiveLayerId, MapViewStyleActiveStopsPrimaryLayerId, MapViewStylePath, MapViewStylePathInteractiveLayerId, MapViewStylePathPrimaryLayerId, MapViewStyleStops, MapViewStyleStopsInteractiveLayerId, MapViewStyleStopsPrimaryLayerId, MapViewStyleVehicles, MapViewStyleVehiclesInteractiveLayerId, MapViewStyleVehiclesPrimaryLayerId, Menu, PasswordInput, Section, SegmentedControl, Sidebar, type SidebarItemProps, SimpleSurface, Slider, Spacer, Surface, Switch, TMLogo, TMLogoDark, TMLogoLight, Tag, Text, Component$1 as TextArea, Component as TextInput, ThemeDark, ThemeLight, ThemeProvider, type ThemeProviderProps, ThemeSwitcher, Themer, type ToastPromiseParams, type ToastProps, Tooltip, centerMap, getBaseGeoJsonFeatureCollection, getBaseGeoJsonFeatureLineString, moveMap, useScreenSize, useSearchQuery, useTheme, useToast };
|
package/dist/src/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ export * from './components';
|
|
3
3
|
export * from './hooks/toast';
|
4
4
|
export * from './hooks/use-screen-size';
|
5
5
|
export * from './hooks/use-search-query';
|
6
|
+
export * from './lib/map.utils';
|
6
7
|
export * from '@mantine/form';
|
7
8
|
export * from '@mantine/hooks';
|
8
9
|
export * from '@mantine/modals';
|
package/dist/src/index.js
CHANGED
@@ -41,6 +41,7 @@ export { default as ThemeSwitcher } from './components/theme/ThemeSwitcher/index
|
|
41
41
|
export { useToast } from './hooks/toast.js';
|
42
42
|
export { useScreenSize } from './hooks/use-screen-size.js';
|
43
43
|
export { useSearchQuery } from './hooks/use-search-query.js';
|
44
|
+
export { centerMap, getBaseGeoJsonFeatureCollection, getBaseGeoJsonFeatureLineString, moveMap } from './lib/map.utils.js';
|
44
45
|
export * from '@mantine/form';
|
45
46
|
export * from '@mantine/hooks';
|
46
47
|
export * from '@mantine/modals';
|
package/dist/src/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@@ -1,7 +1,94 @@
|
|
1
|
-
import '../settings/map.settings.js';
|
2
|
-
import '@turf/turf';
|
1
|
+
import { mapDefaultValues } from '../settings/map.settings.js';
|
2
|
+
import * as turf from '@turf/turf';
|
3
3
|
|
4
4
|
/* * */
|
5
|
+
/**
|
6
|
+
*
|
7
|
+
* @param mapObject The map that should be manipulated
|
8
|
+
* @param features The features to center the map on
|
9
|
+
* @param options Optional settings to customize the centering
|
10
|
+
*/
|
11
|
+
const centerMap = (mapObject, features, options) => {
|
12
|
+
//
|
13
|
+
//
|
14
|
+
// Validate input parameters
|
15
|
+
if (!mapObject)
|
16
|
+
return;
|
17
|
+
if (!features.length)
|
18
|
+
return;
|
19
|
+
//
|
20
|
+
// Create a feature collection from the given features, and get the corresponding envelope.
|
21
|
+
// Return if the envelope is not valid.
|
22
|
+
const featureCollection = turf.featureCollection(features);
|
23
|
+
const featureCollectionEnvelope = turf.envelope(featureCollection);
|
24
|
+
if (!featureCollectionEnvelope || !featureCollectionEnvelope.bbox)
|
25
|
+
return;
|
26
|
+
//
|
27
|
+
// Validate if the envelope is valid
|
28
|
+
if (featureCollectionEnvelope.bbox.length < 4)
|
29
|
+
return;
|
30
|
+
if (featureCollectionEnvelope.bbox[0] < 90 || featureCollectionEnvelope.bbox[0] > 90)
|
31
|
+
return;
|
32
|
+
if (featureCollectionEnvelope.bbox[1] < 180 || featureCollectionEnvelope.bbox[1] > 180)
|
33
|
+
return;
|
34
|
+
if (featureCollectionEnvelope.bbox[2] < 90 || featureCollectionEnvelope.bbox[2] > 90)
|
35
|
+
return;
|
36
|
+
if (featureCollectionEnvelope.bbox[3] < 180 || featureCollectionEnvelope.bbox[3] > 180)
|
37
|
+
return;
|
38
|
+
//
|
39
|
+
// Center the map on the envelope
|
40
|
+
mapObject.fitBounds([
|
41
|
+
featureCollectionEnvelope.bbox[0],
|
42
|
+
featureCollectionEnvelope.bbox[1],
|
43
|
+
featureCollectionEnvelope.bbox[2],
|
44
|
+
featureCollectionEnvelope.bbox[3],
|
45
|
+
], { padding: options?.padding || 25 });
|
46
|
+
//
|
47
|
+
};
|
48
|
+
/* * */
|
49
|
+
/**
|
50
|
+
*
|
51
|
+
* @param mapObject THe map that should be manipulated
|
52
|
+
* @param coordinates The destination coordinates to move the map to
|
53
|
+
* @param options Optional settings to customize the movement
|
54
|
+
*/
|
55
|
+
const moveMap = (mapObject, coordinates) => {
|
56
|
+
//
|
57
|
+
//
|
58
|
+
// Validate the input parameters
|
59
|
+
if (!mapObject)
|
60
|
+
return;
|
61
|
+
if (!coordinates || !coordinates.length)
|
62
|
+
return;
|
63
|
+
//
|
64
|
+
// Get map current zoom level
|
65
|
+
const currentZoom = mapObject.getZoom();
|
66
|
+
const currentZoomWithMargin = currentZoom + mapDefaultValues.zoom_margin;
|
67
|
+
const thresholdZoomWithMargin = mapDefaultValues.zoom + mapDefaultValues.zoom_margin;
|
68
|
+
//
|
69
|
+
// Check if the given coordinates are inside the currently rendered map bounds
|
70
|
+
const currentMapBounds = mapObject.getBounds().toArray();
|
71
|
+
const isInside = turf.booleanIntersects(turf.point(coordinates), turf.bboxPolygon([...currentMapBounds[0], ...currentMapBounds[1]]));
|
72
|
+
//
|
73
|
+
// If the given coordinates are visible and the zoom is not too far back (plus a little margin)...
|
74
|
+
if (isInside && currentZoomWithMargin > (thresholdZoomWithMargin * 1.15)) {
|
75
|
+
// ...then simply ease to it.
|
76
|
+
mapObject.easeTo({ center: coordinates, duration: mapDefaultValues.speed * 0.25, zoom: currentZoom });
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
// If the zoom is too far, or the given coordinates are not visible, then fly to it
|
80
|
+
mapObject.flyTo({ center: coordinates, duration: mapDefaultValues.speed, zoom: thresholdZoomWithMargin });
|
81
|
+
}
|
82
|
+
//
|
83
|
+
};
|
84
|
+
/* * */
|
85
|
+
/**
|
86
|
+
* Return a base GeoJSON Feature for LineString object
|
87
|
+
* @returns A GeoJSON Feature for LineString object with an empty features array
|
88
|
+
*/
|
89
|
+
const getBaseGeoJsonFeatureLineString = () => {
|
90
|
+
return Object.assign({ geometry: { coordinates: [], type: 'LineString' }, properties: {}, type: 'Feature' });
|
91
|
+
};
|
5
92
|
/**
|
6
93
|
* Return a base GeoJSON FeatureCollection object
|
7
94
|
* @returns A GeoJSON FeatureCollection object with an empty features array
|
@@ -10,5 +97,5 @@ const getBaseGeoJsonFeatureCollection = () => {
|
|
10
97
|
return Object.assign({ features: [], type: 'FeatureCollection' });
|
11
98
|
};
|
12
99
|
|
13
|
-
export { getBaseGeoJsonFeatureCollection };
|
100
|
+
export { centerMap, getBaseGeoJsonFeatureCollection, getBaseGeoJsonFeatureLineString, moveMap };
|
14
101
|
//# sourceMappingURL=map.utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"map.utils.js","sources":["../../../../src/lib/map.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;
|
1
|
+
{"version":3,"file":"map.utils.js","sources":["../../../../src/lib/map.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;AAWA;;;;;AAKG;AACU,MAAA,SAAS,GAAG,CAAC,SAAc,EAAE,QAAwE,EAAE,OAA0B,KAAI;;;;AAMjJ,IAAA,IAAI,CAAC,SAAS;QAAE;IAChB,IAAI,C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