-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmapping.ts
More file actions
192 lines (162 loc) · 6.46 KB
/
mapping.ts
File metadata and controls
192 lines (162 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { type FeatureCollection } from 'geojson';
import { type GetMapDataAndMarkersResult } from '@/models/v4/mapping/getMapDataAndMarkersResult';
import { type GetMapLayersResult } from '@/models/v4/mapping/getMapLayersResult';
import {
type GetAllActiveLayersResult,
type GetCustomMapResult,
type GetCustomMapsResult,
type GetGeoJSONResult,
type GetIndoorMapFloorResult,
type GetIndoorMapResult,
type GetIndoorMapsResult,
type SearchAllMapFeaturesResult,
type SearchCustomMapRegionsResult,
type SearchIndoorLocationsResult,
} from '@/models/v4/mapping/mappingResults';
import { createCachedApiEndpoint } from '../common/cached-client';
import { createApiEndpoint } from '../common/client';
const getMayLayersApi = createApiEndpoint('/Mapping/GetMayLayers');
const getMapDataAndMarkersApi = createApiEndpoint('/Mapping/GetMapDataAndMarkers');
// Indoor map endpoints
const getIndoorMapsApi = createCachedApiEndpoint('/Mapping/GetIndoorMaps', {
ttl: 5 * 60 * 1000,
enabled: true,
});
const getIndoorMapApi = createApiEndpoint('/Mapping/GetIndoorMap');
const getIndoorMapFloorApi = createApiEndpoint('/Mapping/GetIndoorMapFloor');
const getIndoorMapZonesGeoJSONApi = createApiEndpoint('/Mapping/GetIndoorMapZonesGeoJSON');
const searchIndoorLocationsApi = createApiEndpoint('/Mapping/SearchIndoorLocations');
const getNearbyIndoorMapsApi = createApiEndpoint('/Mapping/GetNearbyIndoorMaps');
// Custom map endpoints
const getCustomMapsApi = createCachedApiEndpoint('/Mapping/GetCustomMaps', {
ttl: 5 * 60 * 1000,
enabled: true,
});
const getCustomMapApi = createApiEndpoint('/Mapping/GetCustomMap');
const getCustomMapLayerApi = createApiEndpoint('/Mapping/GetCustomMapLayer');
const getMapLayerGeoJSONApi = createApiEndpoint('/Mapping/GetMapLayerGeoJSON');
const getCustomMapRegionsGeoJSONApi = createApiEndpoint('/Mapping/GetCustomMapRegionsGeoJSON');
const searchCustomMapRegionsApi = createApiEndpoint('/Mapping/SearchCustomMapRegions');
// Discovery endpoints
const getAllActiveLayersApi = createCachedApiEndpoint('/Mapping/GetAllActiveLayers', {
ttl: 5 * 60 * 1000,
enabled: true,
});
const searchAllMapFeaturesApi = createApiEndpoint('/Mapping/SearchAllMapFeatures');
// --- Existing Endpoints ---
export const getMapDataAndMarkers = async (signal?: AbortSignal) => {
const response = await getMapDataAndMarkersApi.get<GetMapDataAndMarkersResult>(undefined, signal);
return response.data;
};
export const getMayLayers = async (type: number, signal?: AbortSignal) => {
const response = await getMayLayersApi.get<GetMapLayersResult>(
{
type: encodeURIComponent(type),
},
signal
);
return response.data;
};
// --- Indoor Maps ---
export const getIndoorMaps = async () => {
const response = await getIndoorMapsApi.get<GetIndoorMapsResult>();
return response.data;
};
export const getIndoorMap = async (mapId: string) => {
const response = await getIndoorMapApi.get<GetIndoorMapResult>({
id: encodeURIComponent(mapId),
});
return response.data;
};
export const getIndoorMapFloor = async (floorId: string) => {
const response = await getIndoorMapFloorApi.get<GetIndoorMapFloorResult>({
floorId: encodeURIComponent(floorId),
});
return response.data;
};
export const getIndoorMapZonesGeoJSON = async (floorId: string) => {
const response = await getIndoorMapZonesGeoJSONApi.get<GetGeoJSONResult>({
floorId: encodeURIComponent(floorId),
});
return response.data;
};
export const searchIndoorLocations = async (term: string, mapId?: string) => {
const params: Record<string, unknown> = { term: encodeURIComponent(term) };
if (mapId) {
params.mapId = encodeURIComponent(mapId);
}
const response = await searchIndoorLocationsApi.get<SearchIndoorLocationsResult>(params);
return response.data;
};
export const getNearbyIndoorMaps = async (lat: number, lon: number, radiusMeters: number) => {
const response = await getNearbyIndoorMapsApi.get<GetIndoorMapsResult>({
lat,
lon,
radiusMeters,
});
return response.data;
};
// --- Custom Maps ---
export const getCustomMaps = async (type?: number) => {
const params: Record<string, unknown> = {};
if (type !== undefined) {
params.type = encodeURIComponent(type);
}
const response = await getCustomMapsApi.get<GetCustomMapsResult>(params);
return response.data;
};
export const getCustomMap = async (mapId: string) => {
const response = await getCustomMapApi.get<GetCustomMapResult>({
id: encodeURIComponent(mapId),
});
return response.data;
};
export const getCustomMapLayer = async (layerId: string) => {
const response = await getCustomMapLayerApi.get<GetGeoJSONResult>({
layerId: encodeURIComponent(layerId),
});
return response.data;
};
export const getMapLayerGeoJSON = async (layerId: string) => {
const response = await getMapLayerGeoJSONApi.get<GetGeoJSONResult>({
layerId: encodeURIComponent(layerId),
});
return response.data;
};
export const getCustomMapRegionsGeoJSON = async (layerId: string) => {
const response = await getCustomMapRegionsGeoJSONApi.get<GetGeoJSONResult>({
layerId: encodeURIComponent(layerId),
});
return response.data;
};
export const searchCustomMapRegions = async (term: string, layerId?: string) => {
const params: Record<string, unknown> = { term: encodeURIComponent(term) };
if (layerId) {
params.layerId = encodeURIComponent(layerId);
}
const response = await searchCustomMapRegionsApi.get<SearchCustomMapRegionsResult>(params);
return response.data;
};
// --- Discovery & Search ---
export const getAllActiveLayers = async () => {
const response = await getAllActiveLayersApi.get<GetAllActiveLayersResult>();
return response.data;
};
export const searchAllMapFeatures = async (term: string, type?: 'all' | 'indoor' | 'custom') => {
const params: Record<string, unknown> = { term: encodeURIComponent(term) };
if (type) {
params.type = type;
}
const response = await searchAllMapFeaturesApi.get<SearchAllMapFeaturesResult>(params);
return response.data;
};
// --- URL Helpers (no fetch needed, constructs URLs for components) ---
export const getFloorImageUrl = (floorId: string): string => {
return `/api/v4/Mapping/GetIndoorMapFloorImage/${encodeURIComponent(floorId)}`;
};
export const getCustomMapLayerImageUrl = (layerId: string): string => {
return `/api/v4/Mapping/GetCustomMapLayerImage/${encodeURIComponent(layerId)}`;
};
export const getCustomMapTileUrl = (layerId: string): string => {
return `/api/v4/Mapping/GetCustomMapTile/${encodeURIComponent(layerId)}/{z}/{x}/{y}`;
};