mahal_map 1.0.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/.vscode/settings.json +3 -0
- package/README.md +41 -0
- package/dist/app/config/constants.d.ts +9 -0
- package/dist/app/config/constants.d.ts.map +1 -0
- package/dist/app/config/constants.js +9 -0
- package/dist/app/config/constants.js.map +1 -0
- package/dist/app/config/geojson-polyline.d.ts +3 -0
- package/dist/app/config/geojson-polyline.d.ts.map +1 -0
- package/dist/app/config/geojson-polyline.js +36 -0
- package/dist/app/config/geojson-polyline.js.map +1 -0
- package/dist/app/config/geometry-polyline.d.ts +3 -0
- package/dist/app/config/geometry-polyline.d.ts.map +1 -0
- package/dist/app/config/geometry-polyline.js +46 -0
- package/dist/app/config/geometry-polyline.js.map +1 -0
- package/dist/app/config/index.d.ts +4 -0
- package/dist/app/config/index.d.ts.map +1 -0
- package/dist/app/config/index.js +4 -0
- package/dist/app/config/index.js.map +1 -0
- package/dist/app/lib/axios/api/axios.d.ts +2 -0
- package/dist/app/lib/axios/api/axios.d.ts.map +1 -0
- package/dist/app/lib/axios/api/axios.js +13 -0
- package/dist/app/lib/axios/api/axios.js.map +1 -0
- package/dist/app/lib/axios/api/index.d.ts +2 -0
- package/dist/app/lib/axios/api/index.d.ts.map +1 -0
- package/dist/app/lib/axios/api/index.js +2 -0
- package/dist/app/lib/axios/api/index.js.map +1 -0
- package/dist/app/lib/axios/index.d.ts +2 -0
- package/dist/app/lib/axios/index.d.ts.map +1 -0
- package/dist/app/lib/axios/index.js +2 -0
- package/dist/app/lib/axios/index.js.map +1 -0
- package/dist/app/lib/checking-coordinates/index.d.ts +2 -0
- package/dist/app/lib/checking-coordinates/index.d.ts.map +1 -0
- package/dist/app/lib/checking-coordinates/index.js +2 -0
- package/dist/app/lib/checking-coordinates/index.js.map +1 -0
- package/dist/app/lib/checking-coordinates/utils.d.ts +5 -0
- package/dist/app/lib/checking-coordinates/utils.d.ts.map +1 -0
- package/dist/app/lib/checking-coordinates/utils.js +22 -0
- package/dist/app/lib/checking-coordinates/utils.js.map +1 -0
- package/dist/app/lib/index.d.ts +4 -0
- package/dist/app/lib/index.d.ts.map +1 -0
- package/dist/app/lib/index.js +4 -0
- package/dist/app/lib/index.js.map +1 -0
- package/dist/app/lib/saveKey/index.d.ts +2 -0
- package/dist/app/lib/saveKey/index.d.ts.map +1 -0
- package/dist/app/lib/saveKey/index.js +2 -0
- package/dist/app/lib/saveKey/index.js.map +1 -0
- package/dist/app/lib/saveKey/utils.d.ts +5 -0
- package/dist/app/lib/saveKey/utils.d.ts.map +1 -0
- package/dist/app/lib/saveKey/utils.js +15 -0
- package/dist/app/lib/saveKey/utils.js.map +1 -0
- package/dist/app/types/additional-param/index.d.ts +6 -0
- package/dist/app/types/additional-param/index.d.ts.map +1 -0
- package/dist/app/types/additional-param/index.js +2 -0
- package/dist/app/types/additional-param/index.js.map +1 -0
- package/dist/app/types/index.d.ts +5 -0
- package/dist/app/types/index.d.ts.map +1 -0
- package/dist/app/types/index.js +6 -0
- package/dist/app/types/index.js.map +1 -0
- package/dist/app/types/map/index.d.ts +10 -0
- package/dist/app/types/map/index.d.ts.map +1 -0
- package/dist/app/types/map/index.js +2 -0
- package/dist/app/types/map/index.js.map +1 -0
- package/dist/app/types/router-param/index.d.ts +33 -0
- package/dist/app/types/router-param/index.d.ts.map +1 -0
- package/dist/app/types/router-param/index.js +2 -0
- package/dist/app/types/router-param/index.js.map +1 -0
- package/dist/app/types/search-param/index.d.ts +13 -0
- package/dist/app/types/search-param/index.d.ts.map +1 -0
- package/dist/app/types/search-param/index.js +2 -0
- package/dist/app/types/search-param/index.js.map +1 -0
- package/dist/app/types/window/index.d.ts +1 -0
- package/dist/app/types/window/index.d.ts.map +1 -0
- package/dist/app/types/window/index.js +2 -0
- package/dist/app/types/window/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/map/utils.d.ts +5 -0
- package/dist/lib/map/utils.d.ts.map +1 -0
- package/dist/lib/map/utils.js +27 -0
- package/dist/lib/map/utils.js.map +1 -0
- package/dist/lib/routing/api.d.ts +3 -0
- package/dist/lib/routing/api.d.ts.map +1 -0
- package/dist/lib/routing/api.js +17 -0
- package/dist/lib/routing/api.js.map +1 -0
- package/dist/lib/routing/utils.d.ts +4 -0
- package/dist/lib/routing/utils.d.ts.map +1 -0
- package/dist/lib/routing/utils.js +28 -0
- package/dist/lib/routing/utils.js.map +1 -0
- package/dist/lib/search/api.d.ts +3 -0
- package/dist/lib/search/api.d.ts.map +1 -0
- package/dist/lib/search/api.js +13 -0
- package/dist/lib/search/api.js.map +1 -0
- package/dist/lib/search/utils.d.ts +4 -0
- package/dist/lib/search/utils.d.ts.map +1 -0
- package/dist/lib/search/utils.js +36 -0
- package/dist/lib/search/utils.js.map +1 -0
- package/dist/mahal_map.esm.js +2 -0
- package/dist/mahal_map.esm.js.map +1 -0
- package/dist/mahal_map.umd.js +2 -0
- package/dist/mahal_map.umd.js.map +1 -0
- package/index.html +465 -0
- package/package.json +60 -0
- package/rollup.config.js +36 -0
- package/src/app/config/constants.ts +15 -0
- package/src/app/config/geojson-polyline.ts +47 -0
- package/src/app/config/geometry-polyline.ts +58 -0
- package/src/app/config/index.ts +3 -0
- package/src/app/lib/axios/api/axios.ts +17 -0
- package/src/app/lib/axios/api/index.ts +1 -0
- package/src/app/lib/axios/index.ts +1 -0
- package/src/app/lib/checking-coordinates/index.ts +1 -0
- package/src/app/lib/checking-coordinates/utils.ts +20 -0
- package/src/app/lib/index.ts +3 -0
- package/src/app/lib/saveKey/index.ts +1 -0
- package/src/app/lib/saveKey/utils.ts +18 -0
- package/src/app/types/additional-param/index.ts +6 -0
- package/src/app/types/index.ts +5 -0
- package/src/app/types/map/index.ts +10 -0
- package/src/app/types/router-param/index.ts +33 -0
- package/src/app/types/search-param/index.ts +13 -0
- package/src/app/types/window/index.ts +7 -0
- package/src/index.d.ts +4 -0
- package/src/index.ts +26 -0
- package/src/lib/map/utils.ts +35 -0
- package/src/lib/routing/api.ts +17 -0
- package/src/lib/routing/utils.ts +37 -0
- package/src/lib/search/api.ts +13 -0
- package/src/lib/search/utils.ts +40 -0
- package/tsconfig.json +25 -0
package/index.html
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link
|
|
6
|
+
rel="stylesheet"
|
|
7
|
+
href="https://unpkg.com/maplibre-gl@5.3.0/dist/maplibre-gl.css"
|
|
8
|
+
/>
|
|
9
|
+
<script src="https://unpkg.com/maplibre-gl@5.3.0/dist/maplibre-gl.js"></script>
|
|
10
|
+
<script src="dist/mahal_map.umd.js?apikey=4|3wfLEwkl6d5PZWMKrUDbakyVCiylF0Iqs5iehPEk388cd6eb"></script>
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
12
|
+
<title>Mahal Map</title>
|
|
13
|
+
<style>
|
|
14
|
+
body {
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
height: 100%;
|
|
18
|
+
display: flex;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
align-items: center;
|
|
21
|
+
}
|
|
22
|
+
html,
|
|
23
|
+
body,
|
|
24
|
+
#map {
|
|
25
|
+
height: 100%;
|
|
26
|
+
width: 100%;
|
|
27
|
+
}
|
|
28
|
+
.loading {
|
|
29
|
+
content: url("https://api.iconify.design/svg-spinners:180-ring.svg");
|
|
30
|
+
}
|
|
31
|
+
.search-container {
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 20px;
|
|
34
|
+
left: 20px;
|
|
35
|
+
z-index: 10;
|
|
36
|
+
width: 300px;
|
|
37
|
+
}
|
|
38
|
+
.search-input {
|
|
39
|
+
width: 250px;
|
|
40
|
+
padding: 10px 40px 10px 15px;
|
|
41
|
+
font-size: 16px;
|
|
42
|
+
border: 2px solid #ccc;
|
|
43
|
+
border-radius: 25px;
|
|
44
|
+
outline: none;
|
|
45
|
+
transition: 0.3s;
|
|
46
|
+
}
|
|
47
|
+
.search-input:focus {
|
|
48
|
+
border-color: #007bff;
|
|
49
|
+
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
|
|
50
|
+
}
|
|
51
|
+
.search-icon {
|
|
52
|
+
position: absolute;
|
|
53
|
+
right: 10px;
|
|
54
|
+
top: 50%;
|
|
55
|
+
transform: translateY(-50%);
|
|
56
|
+
width: 20px;
|
|
57
|
+
height: 20px;
|
|
58
|
+
opacity: 0.6;
|
|
59
|
+
}
|
|
60
|
+
.search-results {
|
|
61
|
+
list-style: none;
|
|
62
|
+
padding: 0;
|
|
63
|
+
margin-top: 5px;
|
|
64
|
+
background: white;
|
|
65
|
+
border: 1px solid #ddd;
|
|
66
|
+
max-height: 200px;
|
|
67
|
+
overflow-y: auto;
|
|
68
|
+
display: none;
|
|
69
|
+
position: absolute;
|
|
70
|
+
width: 100%;
|
|
71
|
+
border-radius: 5px;
|
|
72
|
+
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
|
|
73
|
+
}
|
|
74
|
+
.search-results li {
|
|
75
|
+
padding: 8px;
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
}
|
|
78
|
+
.search-results li:hover {
|
|
79
|
+
background: #f0f0f0;
|
|
80
|
+
}
|
|
81
|
+
#routerPanel {
|
|
82
|
+
position: absolute;
|
|
83
|
+
top: 100px;
|
|
84
|
+
right: 20px;
|
|
85
|
+
background: white;
|
|
86
|
+
padding: 12px;
|
|
87
|
+
border-radius: 8px;
|
|
88
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
|
|
89
|
+
z-index: 1000;
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.route-button {
|
|
94
|
+
position: absolute;
|
|
95
|
+
top: 20px;
|
|
96
|
+
right: 20px;
|
|
97
|
+
z-index: 1001;
|
|
98
|
+
padding: 10px 20px;
|
|
99
|
+
font-size: 16px;
|
|
100
|
+
background: linear-gradient(135deg, #1e90ff, #007bff);
|
|
101
|
+
color: white;
|
|
102
|
+
border: none;
|
|
103
|
+
border-radius: 8px;
|
|
104
|
+
box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
transition: all 0.2s ease-in-out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.route-button:hover {
|
|
110
|
+
background: linear-gradient(135deg, #007bff, #0056b3);
|
|
111
|
+
box-shadow: 0 6px 14px rgba(0, 123, 255, 0.4);
|
|
112
|
+
transform: translateY(-1px);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.route-button:active {
|
|
116
|
+
transform: scale(0.98);
|
|
117
|
+
box-shadow: 0 2px 6px rgba(0, 123, 255, 0.2);
|
|
118
|
+
}
|
|
119
|
+
#routerPanel {
|
|
120
|
+
position: absolute;
|
|
121
|
+
top: 100px;
|
|
122
|
+
right: 20px;
|
|
123
|
+
background: white;
|
|
124
|
+
padding: 16px 20px;
|
|
125
|
+
border-radius: 12px;
|
|
126
|
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
|
|
127
|
+
z-index: 1000;
|
|
128
|
+
display: none;
|
|
129
|
+
min-width: 200px;
|
|
130
|
+
font-family: "Segoe UI", sans-serif;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#routerPanel label {
|
|
134
|
+
font-size: 14px;
|
|
135
|
+
font-weight: 500;
|
|
136
|
+
margin-bottom: 8px;
|
|
137
|
+
display: block;
|
|
138
|
+
color: #333;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#routerPanel select {
|
|
142
|
+
width: 100%;
|
|
143
|
+
padding: 8px 10px;
|
|
144
|
+
font-size: 14px;
|
|
145
|
+
border: 1px solid #ccc;
|
|
146
|
+
border-radius: 6px;
|
|
147
|
+
margin-bottom: 12px;
|
|
148
|
+
background-color: #f9f9f9;
|
|
149
|
+
transition: border-color 0.2s;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#routerPanel select:focus {
|
|
153
|
+
outline: none;
|
|
154
|
+
border-color: #007bff;
|
|
155
|
+
box-shadow: 0 0 4px rgba(0, 123, 255, 0.3);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#clearRoute {
|
|
159
|
+
width: 100%;
|
|
160
|
+
padding: 10px 0;
|
|
161
|
+
font-size: 14px;
|
|
162
|
+
background-color: #f44336;
|
|
163
|
+
color: white;
|
|
164
|
+
border: none;
|
|
165
|
+
border-radius: 6px;
|
|
166
|
+
cursor: pointer;
|
|
167
|
+
transition: background-color 0.2s ease-in-out, transform 0.1s ease;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#clearRoute:hover {
|
|
171
|
+
background-color: #d32f2f;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#clearRoute:active {
|
|
175
|
+
transform: scale(0.97);
|
|
176
|
+
}
|
|
177
|
+
</style>
|
|
178
|
+
</head>
|
|
179
|
+
<body>
|
|
180
|
+
<div id="map"></div>
|
|
181
|
+
<div class="search-container">
|
|
182
|
+
<input
|
|
183
|
+
type="text"
|
|
184
|
+
id="search"
|
|
185
|
+
class="search-input"
|
|
186
|
+
placeholder="Поиск..."
|
|
187
|
+
/>
|
|
188
|
+
<img
|
|
189
|
+
id="search-icon"
|
|
190
|
+
class="search-icon"
|
|
191
|
+
src="https://cdn-icons-png.flaticon.com/512/622/622669.png"
|
|
192
|
+
alt="🔍"
|
|
193
|
+
/>
|
|
194
|
+
<ul id="search-results" class="search-results"></ul>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div id="routerPanel">
|
|
198
|
+
<label>Тип транспорта:</label>
|
|
199
|
+
<select id="transportType"></select>
|
|
200
|
+
<button id="clearRoute">Очистить</button>
|
|
201
|
+
</div>
|
|
202
|
+
|
|
203
|
+
<button id="startRouting" class="route-button">Маршрут</button>
|
|
204
|
+
|
|
205
|
+
<script>
|
|
206
|
+
const map = mmaps.Map.createMap({});
|
|
207
|
+
const routePoints = [];
|
|
208
|
+
const markerss = [];
|
|
209
|
+
const routeLayerId = "route-line-layer";
|
|
210
|
+
let isRouting = false;
|
|
211
|
+
let selectedRouteType = "";
|
|
212
|
+
let routeVariants = [];
|
|
213
|
+
const positionClient = {
|
|
214
|
+
lat: 0,
|
|
215
|
+
lng: 0,
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
if (navigator.geolocation) {
|
|
219
|
+
navigator.geolocation.watchPosition(
|
|
220
|
+
(position) => {
|
|
221
|
+
positionClient.lat = position.coords.latitude;
|
|
222
|
+
positionClient.lng = position.coords.longitude;
|
|
223
|
+
console.log("📍 Новая позиция:", positionClient);
|
|
224
|
+
},
|
|
225
|
+
(error) => {
|
|
226
|
+
console.error("Ошибка геолокации:", error.message);
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
enableHighAccuracy: true, // точность GPS
|
|
230
|
+
maximumAge: 0, // не использовать кэш
|
|
231
|
+
timeout: 5000, // время ожидания
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
} else {
|
|
235
|
+
console.log("Геолокация не поддерживается вашим браузером");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const routerPanel = document.getElementById("routerPanel");
|
|
239
|
+
const transportSelect = document.getElementById("transportType");
|
|
240
|
+
const startBtn = document.getElementById("startRouting");
|
|
241
|
+
const clearBtn = document.getElementById("clearRoute");
|
|
242
|
+
|
|
243
|
+
startBtn.onclick = async () => {
|
|
244
|
+
isRouting = true;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
transportSelect.onchange = async (e) => {
|
|
248
|
+
selectedRouteType = e.target.value;
|
|
249
|
+
|
|
250
|
+
const selectedRoute = routeVariants.find(
|
|
251
|
+
(r) => r.type === selectedRouteType
|
|
252
|
+
);
|
|
253
|
+
if (!selectedRoute) return;
|
|
254
|
+
|
|
255
|
+
const geometry = selectedRoute?.route?.routes[0]?.geometry;
|
|
256
|
+
if (!geometry || !Array.isArray(geometry)) return;
|
|
257
|
+
|
|
258
|
+
if (map.getLayer(routeLayerId)) map.removeLayer(routeLayerId);
|
|
259
|
+
if (map.getSource(routeLayerId)) map.removeSource(routeLayerId);
|
|
260
|
+
|
|
261
|
+
map.addSource(routeLayerId, {
|
|
262
|
+
type: "geojson",
|
|
263
|
+
data: {
|
|
264
|
+
type: "Feature",
|
|
265
|
+
geometry: {
|
|
266
|
+
type: "LineString",
|
|
267
|
+
coordinates: geometry,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
map.addLayer({
|
|
273
|
+
id: routeLayerId,
|
|
274
|
+
type: "line",
|
|
275
|
+
source: routeLayerId,
|
|
276
|
+
layout: {
|
|
277
|
+
"line-join": "round",
|
|
278
|
+
"line-cap": "round",
|
|
279
|
+
},
|
|
280
|
+
paint: {
|
|
281
|
+
"line-color": "#007bff",
|
|
282
|
+
"line-width": 4,
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
map.on("click", async (e) => {
|
|
288
|
+
if (!isRouting) return;
|
|
289
|
+
|
|
290
|
+
const coord = [e.lngLat.lng, e.lngLat.lat];
|
|
291
|
+
routePoints.push(coord);
|
|
292
|
+
|
|
293
|
+
const marker = new maplibregl.Marker({ color: "#1E90FF" })
|
|
294
|
+
.setLngLat(coord)
|
|
295
|
+
.addTo(map);
|
|
296
|
+
markerss.push(marker);
|
|
297
|
+
|
|
298
|
+
if (routePoints.length >= 2) {
|
|
299
|
+
try {
|
|
300
|
+
const result = await mmaps.routerUtils.getrouter(
|
|
301
|
+
routePoints,
|
|
302
|
+
"geojson"
|
|
303
|
+
);
|
|
304
|
+
routeVariants = result;
|
|
305
|
+
routerPanel.style.display = "block";
|
|
306
|
+
transportSelect.innerHTML = "";
|
|
307
|
+
|
|
308
|
+
result.forEach((route) => {
|
|
309
|
+
const opt = document.createElement("option");
|
|
310
|
+
opt.value = route.type;
|
|
311
|
+
opt.textContent = route.name;
|
|
312
|
+
transportSelect.appendChild(opt);
|
|
313
|
+
});
|
|
314
|
+
selectedRouteType = result[0].type;
|
|
315
|
+
transportSelect.value = selectedRouteType;
|
|
316
|
+
|
|
317
|
+
transportSelect.dispatchEvent(new Event("change"));
|
|
318
|
+
} catch (err) {
|
|
319
|
+
console.error(err);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
clearBtn.onclick = () => {
|
|
325
|
+
isRouting = false;
|
|
326
|
+
routePoints.length = 0;
|
|
327
|
+
markerss.forEach((m) => m.remove());
|
|
328
|
+
markerss.length = 0;
|
|
329
|
+
if (map.getLayer(routeLayerId)) map.removeLayer(routeLayerId);
|
|
330
|
+
if (map.getSource(routeLayerId)) map.removeSource(routeLayerId);
|
|
331
|
+
routerPanel.style.display = "none";
|
|
332
|
+
transportSelect.innerHTML = "";
|
|
333
|
+
selectedRouteType = "";
|
|
334
|
+
routeVariants = [];
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const searchInput = document.getElementById("search");
|
|
338
|
+
const searchIcon = document.getElementById("search-icon");
|
|
339
|
+
const searchResults = document.getElementById("search-results");
|
|
340
|
+
|
|
341
|
+
let markers = [];
|
|
342
|
+
function clearMarkers() {
|
|
343
|
+
if (markers.length > 0) {
|
|
344
|
+
markers.forEach((marker) => {
|
|
345
|
+
marker.remove();
|
|
346
|
+
});
|
|
347
|
+
markers = [];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
352
|
+
const searchInput = document.getElementById("search");
|
|
353
|
+
const searchIcon = document.getElementById("search-icon");
|
|
354
|
+
const searchResults = document.getElementById("search-results");
|
|
355
|
+
let markers = [];
|
|
356
|
+
|
|
357
|
+
function clearMarkers() {
|
|
358
|
+
markers.forEach((marker) => marker.remove());
|
|
359
|
+
markers = [];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function clearResults() {
|
|
363
|
+
searchResults.innerHTML = "";
|
|
364
|
+
searchResults.style.display = "none";
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const getLatLng = (item) => {
|
|
368
|
+
const lat = parseFloat(item.latitude);
|
|
369
|
+
const lng = parseFloat(item.longitude);
|
|
370
|
+
return isNaN(lat) || isNaN(lng) ? null : [lng, lat];
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const buildDisplayName = (item) => {
|
|
374
|
+
return (
|
|
375
|
+
item.fullAddress ||
|
|
376
|
+
[
|
|
377
|
+
item.subject_name,
|
|
378
|
+
item.region,
|
|
379
|
+
item.city,
|
|
380
|
+
item.settlement,
|
|
381
|
+
item.village,
|
|
382
|
+
item.street_name,
|
|
383
|
+
item.name,
|
|
384
|
+
]
|
|
385
|
+
.filter(Boolean)
|
|
386
|
+
.join(", ")
|
|
387
|
+
);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
async function handleSearch(query) {
|
|
391
|
+
if (!query) {
|
|
392
|
+
clearMarkers();
|
|
393
|
+
clearResults();
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
searchIcon.classList.add("loading");
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
const res = await mmaps.searchUtils.search(
|
|
401
|
+
query,
|
|
402
|
+
positionClient.lat !== 0 ? positionClient : null
|
|
403
|
+
);
|
|
404
|
+
if (res.data.length == 0) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const items = res.data || [];
|
|
409
|
+
clearMarkers();
|
|
410
|
+
clearResults();
|
|
411
|
+
|
|
412
|
+
items.forEach((item) => {
|
|
413
|
+
const coords = getLatLng(item);
|
|
414
|
+
if (!coords) return;
|
|
415
|
+
|
|
416
|
+
const marker = new maplibregl.Marker()
|
|
417
|
+
.setLngLat(coords)
|
|
418
|
+
.addTo(map);
|
|
419
|
+
markers.push(marker);
|
|
420
|
+
|
|
421
|
+
const li = document.createElement("li");
|
|
422
|
+
li.textContent = buildDisplayName(item);
|
|
423
|
+
li.addEventListener("click", () => {
|
|
424
|
+
clearMarkers();
|
|
425
|
+
|
|
426
|
+
const newMarker = new maplibregl.Marker()
|
|
427
|
+
.setLngLat(coords)
|
|
428
|
+
.addTo(map);
|
|
429
|
+
markers.push(newMarker);
|
|
430
|
+
|
|
431
|
+
searchInput.value = li.textContent;
|
|
432
|
+
searchResults.style.display = "none";
|
|
433
|
+
|
|
434
|
+
map.flyTo({ center: coords, zoom: 15 });
|
|
435
|
+
});
|
|
436
|
+
searchResults.appendChild(li);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
if (items.length) searchResults.style.display = "block";
|
|
440
|
+
|
|
441
|
+
// Центр карты на первый результат
|
|
442
|
+
const firstCoords = getLatLng(items[0]);
|
|
443
|
+
if (firstCoords) map.flyTo({ center: firstCoords, zoom: 10 });
|
|
444
|
+
} catch (err) {
|
|
445
|
+
console.error(err);
|
|
446
|
+
} finally {
|
|
447
|
+
searchIcon.classList.remove("loading");
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
searchInput.addEventListener("input", (e) =>
|
|
452
|
+
handleSearch(e.target.value.trim())
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
// Делегирование клика по li (на всякий случай)
|
|
456
|
+
searchResults.addEventListener("click", (e) => {
|
|
457
|
+
if (e.target.tagName === "LI") {
|
|
458
|
+
searchInput.value = e.target.textContent;
|
|
459
|
+
searchResults.style.display = "none";
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
</script>
|
|
464
|
+
</body>
|
|
465
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mahal_map",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "mahal_map",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"map",
|
|
7
|
+
"javascript",
|
|
8
|
+
"API",
|
|
9
|
+
"MapLibre GL JS"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/ioyandasoz/mahal_map#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ioyandasoz/mahal_map/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/ioyandasoz/mahal_map.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"author": "io",
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/mahal_map.esm.js",
|
|
25
|
+
"require": "./dist/mahal_map.umd.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "dist/mahal_map.umd.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
32
|
+
"build": "rollup -c rollup.config.js",
|
|
33
|
+
"dev": "rollup -c rollup.config.js -w"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
37
|
+
"axios": "^1.8.4",
|
|
38
|
+
"body-parser": "^2.2.0",
|
|
39
|
+
"cors": "^2.8.5",
|
|
40
|
+
"dotenv": "^17.2.3",
|
|
41
|
+
"express": "^5.1.0",
|
|
42
|
+
"maplibre-gl": "^5.3.0",
|
|
43
|
+
"rollup-plugin-json": "^4.0.0",
|
|
44
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
45
|
+
"tslib": "^2.8.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
49
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
50
|
+
"@types/cors": "^2.8.19",
|
|
51
|
+
"@types/express": "^5.0.3",
|
|
52
|
+
"@types/node": "^24.8.1",
|
|
53
|
+
"rollup": "^2.79.2",
|
|
54
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"ts-node-dev": "^2.0.0",
|
|
57
|
+
"typescript": "^5.9.3"
|
|
58
|
+
},
|
|
59
|
+
"module": "dist/mahal_map.esm.js"
|
|
60
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
2
|
+
import typescript from "@rollup/plugin-typescript";
|
|
3
|
+
import { terser } from "rollup-plugin-terser";
|
|
4
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
input: "src/index.ts",
|
|
8
|
+
output: [
|
|
9
|
+
{
|
|
10
|
+
file: "dist/mahal_map.esm.js",
|
|
11
|
+
format: "esm",
|
|
12
|
+
sourcemap: true,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
file: "dist/mahal_map.umd.js",
|
|
16
|
+
format: "umd",
|
|
17
|
+
name: "mmaps",
|
|
18
|
+
sourcemap: true,
|
|
19
|
+
globals: {
|
|
20
|
+
"maplibre-gl": "maplibregl",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
external: ["maplibre-gl"],
|
|
25
|
+
context: "window",
|
|
26
|
+
plugins: [
|
|
27
|
+
resolve({ browser: true, preferBuiltins: false }),
|
|
28
|
+
commonjs(),
|
|
29
|
+
typescript({
|
|
30
|
+
tsconfig: "./tsconfig.json",
|
|
31
|
+
declaration: true,
|
|
32
|
+
declarationDir: "dist",
|
|
33
|
+
}),
|
|
34
|
+
terser(),
|
|
35
|
+
],
|
|
36
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const BASE_URL = "https://platform.mahal.tj/api/";
|
|
2
|
+
const LATLNGREGEX =
|
|
3
|
+
/^([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)),\s*([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))$/;
|
|
4
|
+
const LNGLATREGEX =
|
|
5
|
+
/^([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)),\s*([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))$/;
|
|
6
|
+
|
|
7
|
+
const REGEX =
|
|
8
|
+
/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/;
|
|
9
|
+
|
|
10
|
+
const DARK = "https://mtile.gram.tj/custom-styles/dark-style.json";
|
|
11
|
+
const LIGHT = "https://mtile.gram.tj/custom-styles/mapstyle.json";
|
|
12
|
+
const VECTOR =
|
|
13
|
+
"https://mtile.gram.tj/custom-styles/style_maptiler_basic_hn.json";
|
|
14
|
+
|
|
15
|
+
export { BASE_URL, LATLNGREGEX, LNGLATREGEX, REGEX, DARK, LIGHT, VECTOR };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function geojsonPolyline(encoded: string): number[][] {
|
|
2
|
+
let points = [];
|
|
3
|
+
let index = 0,
|
|
4
|
+
len = encoded.length;
|
|
5
|
+
let lat = 0,
|
|
6
|
+
lng = 0;
|
|
7
|
+
|
|
8
|
+
while (index < len) {
|
|
9
|
+
let b,
|
|
10
|
+
shift = 0,
|
|
11
|
+
result = 0;
|
|
12
|
+
do {
|
|
13
|
+
b = encoded.charCodeAt(index++) - 63;
|
|
14
|
+
result |= (b & 0x1f) << shift;
|
|
15
|
+
shift += 5;
|
|
16
|
+
} while (b >= 0x20);
|
|
17
|
+
let dlat = result & 1 ? ~(result >> 1) : result >> 1;
|
|
18
|
+
lat += dlat;
|
|
19
|
+
|
|
20
|
+
shift = 0;
|
|
21
|
+
result = 0;
|
|
22
|
+
do {
|
|
23
|
+
b = encoded.charCodeAt(index++) - 63;
|
|
24
|
+
result |= (b & 0x1f) << shift;
|
|
25
|
+
shift += 5;
|
|
26
|
+
} while (b >= 0x20);
|
|
27
|
+
let dlng = result & 1 ? ~(result >> 1) : result >> 1;
|
|
28
|
+
lng += dlng;
|
|
29
|
+
|
|
30
|
+
points.push([lng * 1e-5, lat * 1e-5]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return points;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { geojsonPolyline };
|
|
37
|
+
|
|
38
|
+
// Пример использования:
|
|
39
|
+
|
|
40
|
+
// geojsonPolyline("yzocFzynhVq}@n}@o}@nzD")
|
|
41
|
+
|
|
42
|
+
// Вернёт массив вида [
|
|
43
|
+
// [102.0, 0.5],
|
|
44
|
+
// [103.0, 1.0],
|
|
45
|
+
// [104.0, 0.5],
|
|
46
|
+
// [105.0, 0.0]
|
|
47
|
+
// ].
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function geometryPolyline(coordinates: number[][]): string {
|
|
2
|
+
let encoded = '';
|
|
3
|
+
let prevLat = 0;
|
|
4
|
+
let prevLng = 0;
|
|
5
|
+
|
|
6
|
+
for (let i = 0; i < coordinates.length; i++) {
|
|
7
|
+
const [lng, lat] = coordinates[i];
|
|
8
|
+
|
|
9
|
+
// Умножаем координаты на 1e5 и округляем
|
|
10
|
+
const latE5 = Math.round(lat * 1e5);
|
|
11
|
+
const lngE5 = Math.round(lng * 1e5);
|
|
12
|
+
|
|
13
|
+
// Вычисляем разницу от предыдущих значений
|
|
14
|
+
const dLat = latE5 - prevLat;
|
|
15
|
+
const dLng = lngE5 - prevLng;
|
|
16
|
+
|
|
17
|
+
// Обновляем предыдущие значения
|
|
18
|
+
prevLat = latE5;
|
|
19
|
+
prevLng = lngE5;
|
|
20
|
+
|
|
21
|
+
// Добавляем к закодированной строке
|
|
22
|
+
encoded += encodeSignedNumber(dLat) + encodeSignedNumber(dLng);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return encoded;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function encodeSignedNumber(num: number) {
|
|
29
|
+
let sgnNum = num << 1;
|
|
30
|
+
if (num < 0) {
|
|
31
|
+
sgnNum = ~sgnNum;
|
|
32
|
+
}
|
|
33
|
+
return encodeNumber(sgnNum);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function encodeNumber(num :number) {
|
|
37
|
+
let encoded = '';
|
|
38
|
+
while (num >= 0x20) {
|
|
39
|
+
encoded += String.fromCharCode((0x20 | (num & 0x1f)) + 63);
|
|
40
|
+
num >>= 5;
|
|
41
|
+
}
|
|
42
|
+
encoded += String.fromCharCode(num + 63);
|
|
43
|
+
return encoded;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default geometryPolyline
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// Пример использования:
|
|
50
|
+
|
|
51
|
+
// geometryPolyline([
|
|
52
|
+
// [102.0, 0.5],
|
|
53
|
+
// [103.0, 1.0],
|
|
54
|
+
// [104.0, 0.5],
|
|
55
|
+
// [105.0, 0.0]
|
|
56
|
+
// ])
|
|
57
|
+
|
|
58
|
+
// Вернёт строку вида "yzocFzynhVq}@n}@o}@nzD".
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { BASE_URL } from "@app/config/index";
|
|
3
|
+
import { clearKey } from "@app/lib";
|
|
4
|
+
|
|
5
|
+
export const api = axios.create({
|
|
6
|
+
baseURL: BASE_URL,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
api.interceptors.request.use(
|
|
10
|
+
(response) => response,
|
|
11
|
+
(error) => {
|
|
12
|
+
if (error.request?.status === 401) {
|
|
13
|
+
clearKey();
|
|
14
|
+
}
|
|
15
|
+
return Promise.reject(error);
|
|
16
|
+
}
|
|
17
|
+
);
|