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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./axios";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LATLNGREGEX, LNGLATREGEX } from "@app/config/index";
|
|
2
|
+
|
|
3
|
+
export function checkCoordinates(coordinates: string) {
|
|
4
|
+
let lat, lng;
|
|
5
|
+
if (LATLNGREGEX.test(coordinates)) {
|
|
6
|
+
const match = coordinates.match(LATLNGREGEX);
|
|
7
|
+
if (match) {
|
|
8
|
+
[, lat, lng] = match; // Первый элемент — полное совпадение, пропускаем его
|
|
9
|
+
}
|
|
10
|
+
} else if (LNGLATREGEX.test(coordinates)) {
|
|
11
|
+
const match = coordinates.match(LNGLATREGEX);
|
|
12
|
+
if (match) {
|
|
13
|
+
[, lng, lat] = match; // Меняем местами
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
console.log("Неверный формат координат");
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return { lat, lng };
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { api } from "@app/lib";
|
|
2
|
+
|
|
3
|
+
let apiKey: string = "";
|
|
4
|
+
|
|
5
|
+
function saveKey(param: string) {
|
|
6
|
+
if (param === "") return;
|
|
7
|
+
apiKey = param;
|
|
8
|
+
api.defaults.headers.common["Authorization"] = `Bearer ${param}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function clearKey() {
|
|
12
|
+
apiKey = "";
|
|
13
|
+
api.defaults.headers.common["Authorization"] = "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getApiKey = () => apiKey;
|
|
17
|
+
|
|
18
|
+
export { saveKey, clearKey, getApiKey };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface IRoute {
|
|
2
|
+
id: number;
|
|
3
|
+
type: string;
|
|
4
|
+
name: string;
|
|
5
|
+
icon: string;
|
|
6
|
+
success: boolean;
|
|
7
|
+
coords: string;
|
|
8
|
+
route?: {
|
|
9
|
+
code: string;
|
|
10
|
+
routes: {
|
|
11
|
+
geometry: string | number[][];
|
|
12
|
+
legs: {
|
|
13
|
+
steps: [];
|
|
14
|
+
summary: string;
|
|
15
|
+
weight: number;
|
|
16
|
+
duration: number;
|
|
17
|
+
distance: number;
|
|
18
|
+
}[];
|
|
19
|
+
weight_name: string;
|
|
20
|
+
distance: number;
|
|
21
|
+
duration: number;
|
|
22
|
+
weight: number;
|
|
23
|
+
}[];
|
|
24
|
+
waypoints: {
|
|
25
|
+
hint: string;
|
|
26
|
+
distance: any;
|
|
27
|
+
name: string;
|
|
28
|
+
location: number[];
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type { IRoute };
|
package/src/index.d.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Map from "@lib/map/utils";
|
|
2
|
+
import * as keyUtils from "@app/lib/saveKey";
|
|
3
|
+
import * as searchUtils from "@lib/search/utils";
|
|
4
|
+
import * as routerUtils from "@lib/routing/utils";
|
|
5
|
+
|
|
6
|
+
export { Map, keyUtils, searchUtils, routerUtils };
|
|
7
|
+
|
|
8
|
+
function loadKeyFromScriptUrl(): string | "" {
|
|
9
|
+
const scripts: HTMLCollectionOf<HTMLScriptElement> =
|
|
10
|
+
document.getElementsByTagName("script");
|
|
11
|
+
|
|
12
|
+
for (const script of scripts) {
|
|
13
|
+
if (script.src.includes("mahal_map.umd.js")) {
|
|
14
|
+
const url = new URL(script.src);
|
|
15
|
+
const apikey = url.searchParams.get("apikey");
|
|
16
|
+
|
|
17
|
+
if (apikey) {
|
|
18
|
+
return apikey;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
keyUtils.saveKey(loadKeyFromScriptUrl());
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Map as MapType } from "maplibre-gl";
|
|
2
|
+
import type { IMahalMapOptions } from "@app/types";
|
|
3
|
+
import { DARK, LIGHT, VECTOR } from "@app/config";
|
|
4
|
+
import maplibregl from "maplibre-gl";
|
|
5
|
+
|
|
6
|
+
const defaultStyles = { dark: DARK, light: LIGHT };
|
|
7
|
+
|
|
8
|
+
function createMap(options: IMahalMapOptions): MapType {
|
|
9
|
+
let finalStyle;
|
|
10
|
+
|
|
11
|
+
if (options.autoAddVectorSource) {
|
|
12
|
+
finalStyle = VECTOR;
|
|
13
|
+
} else {
|
|
14
|
+
finalStyle = options.style
|
|
15
|
+
? options.style
|
|
16
|
+
: options.theme === "dark"
|
|
17
|
+
? defaultStyles.dark
|
|
18
|
+
: defaultStyles.light;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const map: MapType = new maplibregl.Map({
|
|
22
|
+
container: options.container || "map",
|
|
23
|
+
style: finalStyle as string,
|
|
24
|
+
center: options.center || [69.624024, 40.279687],
|
|
25
|
+
zoom: options.zoom || 5,
|
|
26
|
+
});
|
|
27
|
+
const compactEl = document.getElementsByClassName(
|
|
28
|
+
"maplibregl-compact-show"
|
|
29
|
+
)[0] as HTMLElement;
|
|
30
|
+
if (compactEl) compactEl.style.display = "none";
|
|
31
|
+
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { createMap };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { api } from "@app/lib";
|
|
2
|
+
|
|
3
|
+
const routingApi = async (param: number[][]) => {
|
|
4
|
+
try {
|
|
5
|
+
const points: { lng: number; lat: number }[] = [];
|
|
6
|
+
param.forEach((e) => {
|
|
7
|
+
points.push({ lng: e[0], lat: e[1] });
|
|
8
|
+
});
|
|
9
|
+
const response = await api.post("services/getRoutes", { points });
|
|
10
|
+
return response.data;
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.error(err);
|
|
13
|
+
throw err;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { routingApi };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { routingApi } from "@lib/routing/api";
|
|
2
|
+
import { geojsonPolyline } from "@app/config/index";
|
|
3
|
+
import type { IRoute } from "@app/types/index";
|
|
4
|
+
|
|
5
|
+
async function getrouter(
|
|
6
|
+
param: number[][],
|
|
7
|
+
typeData: string
|
|
8
|
+
): Promise<IRoute[]> {
|
|
9
|
+
try {
|
|
10
|
+
const res = await routingApi(param);
|
|
11
|
+
|
|
12
|
+
if (!res?.data) return res;
|
|
13
|
+
|
|
14
|
+
const data: IRoute[] = res.data;
|
|
15
|
+
|
|
16
|
+
return data.map((route) => {
|
|
17
|
+
const updated = { ...route };
|
|
18
|
+
|
|
19
|
+
if (updated.route?.routes?.length) {
|
|
20
|
+
updated.route.routes = updated.route.routes.map((r) => ({
|
|
21
|
+
...r,
|
|
22
|
+
geometry:
|
|
23
|
+
typeData === "geojson" && typeof r.geometry === "string"
|
|
24
|
+
? geojsonPolyline(r.geometry)
|
|
25
|
+
: r.geometry,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return updated as IRoute;
|
|
30
|
+
});
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { getrouter };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { api } from "@app/lib";
|
|
2
|
+
import type { ISearchParam } from "@app/types";
|
|
3
|
+
|
|
4
|
+
export const searchPost = async (param: ISearchParam) => {
|
|
5
|
+
try {
|
|
6
|
+
const params = { params: param };
|
|
7
|
+
const response = await api.get("elastic/search", params);
|
|
8
|
+
return response.data;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error("Ошибка при поиске адреса:", error);
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { searchPost } from "./api";
|
|
2
|
+
import { IAdditionalParamType } from "@app/types/index";
|
|
3
|
+
import { checkCoordinates } from "@app/lib/index";
|
|
4
|
+
import { REGEX } from "@app/config";
|
|
5
|
+
|
|
6
|
+
async function search(
|
|
7
|
+
param: string,
|
|
8
|
+
additionalParam?: IAdditionalParamType
|
|
9
|
+
): Promise<any> {
|
|
10
|
+
let searchData: any = {
|
|
11
|
+
text: "",
|
|
12
|
+
...additionalParam,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
if (param !== "") {
|
|
16
|
+
if (REGEX.test(param)) {
|
|
17
|
+
let coordinates = await checkCoordinates(param);
|
|
18
|
+
if (coordinates) {
|
|
19
|
+
searchData = {
|
|
20
|
+
lat: coordinates.lat ?? "",
|
|
21
|
+
lng: coordinates.lng ?? "",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
searchData.text = param;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
searchData.text = "";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const res = await searchPost(searchData);
|
|
33
|
+
return res;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error("Ошибка при выполнении поиска:", error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { search };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"target": "ES2020",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"emitDeclarationOnly": false,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"allowSyntheticDefaultImports": true,
|
|
17
|
+
"paths": {
|
|
18
|
+
"@app/*": ["./src/app/*"],
|
|
19
|
+
"@lib/*": ["./src/lib/*"],
|
|
20
|
+
"*": ["./src/*"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*.ts"],
|
|
24
|
+
"exclude": ["node_modules"]
|
|
25
|
+
}
|