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.
Files changed (131) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/README.md +41 -0
  3. package/dist/app/config/constants.d.ts +9 -0
  4. package/dist/app/config/constants.d.ts.map +1 -0
  5. package/dist/app/config/constants.js +9 -0
  6. package/dist/app/config/constants.js.map +1 -0
  7. package/dist/app/config/geojson-polyline.d.ts +3 -0
  8. package/dist/app/config/geojson-polyline.d.ts.map +1 -0
  9. package/dist/app/config/geojson-polyline.js +36 -0
  10. package/dist/app/config/geojson-polyline.js.map +1 -0
  11. package/dist/app/config/geometry-polyline.d.ts +3 -0
  12. package/dist/app/config/geometry-polyline.d.ts.map +1 -0
  13. package/dist/app/config/geometry-polyline.js +46 -0
  14. package/dist/app/config/geometry-polyline.js.map +1 -0
  15. package/dist/app/config/index.d.ts +4 -0
  16. package/dist/app/config/index.d.ts.map +1 -0
  17. package/dist/app/config/index.js +4 -0
  18. package/dist/app/config/index.js.map +1 -0
  19. package/dist/app/lib/axios/api/axios.d.ts +2 -0
  20. package/dist/app/lib/axios/api/axios.d.ts.map +1 -0
  21. package/dist/app/lib/axios/api/axios.js +13 -0
  22. package/dist/app/lib/axios/api/axios.js.map +1 -0
  23. package/dist/app/lib/axios/api/index.d.ts +2 -0
  24. package/dist/app/lib/axios/api/index.d.ts.map +1 -0
  25. package/dist/app/lib/axios/api/index.js +2 -0
  26. package/dist/app/lib/axios/api/index.js.map +1 -0
  27. package/dist/app/lib/axios/index.d.ts +2 -0
  28. package/dist/app/lib/axios/index.d.ts.map +1 -0
  29. package/dist/app/lib/axios/index.js +2 -0
  30. package/dist/app/lib/axios/index.js.map +1 -0
  31. package/dist/app/lib/checking-coordinates/index.d.ts +2 -0
  32. package/dist/app/lib/checking-coordinates/index.d.ts.map +1 -0
  33. package/dist/app/lib/checking-coordinates/index.js +2 -0
  34. package/dist/app/lib/checking-coordinates/index.js.map +1 -0
  35. package/dist/app/lib/checking-coordinates/utils.d.ts +5 -0
  36. package/dist/app/lib/checking-coordinates/utils.d.ts.map +1 -0
  37. package/dist/app/lib/checking-coordinates/utils.js +22 -0
  38. package/dist/app/lib/checking-coordinates/utils.js.map +1 -0
  39. package/dist/app/lib/index.d.ts +4 -0
  40. package/dist/app/lib/index.d.ts.map +1 -0
  41. package/dist/app/lib/index.js +4 -0
  42. package/dist/app/lib/index.js.map +1 -0
  43. package/dist/app/lib/saveKey/index.d.ts +2 -0
  44. package/dist/app/lib/saveKey/index.d.ts.map +1 -0
  45. package/dist/app/lib/saveKey/index.js +2 -0
  46. package/dist/app/lib/saveKey/index.js.map +1 -0
  47. package/dist/app/lib/saveKey/utils.d.ts +5 -0
  48. package/dist/app/lib/saveKey/utils.d.ts.map +1 -0
  49. package/dist/app/lib/saveKey/utils.js +15 -0
  50. package/dist/app/lib/saveKey/utils.js.map +1 -0
  51. package/dist/app/types/additional-param/index.d.ts +6 -0
  52. package/dist/app/types/additional-param/index.d.ts.map +1 -0
  53. package/dist/app/types/additional-param/index.js +2 -0
  54. package/dist/app/types/additional-param/index.js.map +1 -0
  55. package/dist/app/types/index.d.ts +5 -0
  56. package/dist/app/types/index.d.ts.map +1 -0
  57. package/dist/app/types/index.js +6 -0
  58. package/dist/app/types/index.js.map +1 -0
  59. package/dist/app/types/map/index.d.ts +10 -0
  60. package/dist/app/types/map/index.d.ts.map +1 -0
  61. package/dist/app/types/map/index.js +2 -0
  62. package/dist/app/types/map/index.js.map +1 -0
  63. package/dist/app/types/router-param/index.d.ts +33 -0
  64. package/dist/app/types/router-param/index.d.ts.map +1 -0
  65. package/dist/app/types/router-param/index.js +2 -0
  66. package/dist/app/types/router-param/index.js.map +1 -0
  67. package/dist/app/types/search-param/index.d.ts +13 -0
  68. package/dist/app/types/search-param/index.d.ts.map +1 -0
  69. package/dist/app/types/search-param/index.js +2 -0
  70. package/dist/app/types/search-param/index.js.map +1 -0
  71. package/dist/app/types/window/index.d.ts +1 -0
  72. package/dist/app/types/window/index.d.ts.map +1 -0
  73. package/dist/app/types/window/index.js +2 -0
  74. package/dist/app/types/window/index.js.map +1 -0
  75. package/dist/index.d.ts +6 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +20 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/lib/map/utils.d.ts +5 -0
  80. package/dist/lib/map/utils.d.ts.map +1 -0
  81. package/dist/lib/map/utils.js +27 -0
  82. package/dist/lib/map/utils.js.map +1 -0
  83. package/dist/lib/routing/api.d.ts +3 -0
  84. package/dist/lib/routing/api.d.ts.map +1 -0
  85. package/dist/lib/routing/api.js +17 -0
  86. package/dist/lib/routing/api.js.map +1 -0
  87. package/dist/lib/routing/utils.d.ts +4 -0
  88. package/dist/lib/routing/utils.d.ts.map +1 -0
  89. package/dist/lib/routing/utils.js +28 -0
  90. package/dist/lib/routing/utils.js.map +1 -0
  91. package/dist/lib/search/api.d.ts +3 -0
  92. package/dist/lib/search/api.d.ts.map +1 -0
  93. package/dist/lib/search/api.js +13 -0
  94. package/dist/lib/search/api.js.map +1 -0
  95. package/dist/lib/search/utils.d.ts +4 -0
  96. package/dist/lib/search/utils.d.ts.map +1 -0
  97. package/dist/lib/search/utils.js +36 -0
  98. package/dist/lib/search/utils.js.map +1 -0
  99. package/dist/mahal_map.esm.js +2 -0
  100. package/dist/mahal_map.esm.js.map +1 -0
  101. package/dist/mahal_map.umd.js +2 -0
  102. package/dist/mahal_map.umd.js.map +1 -0
  103. package/index.html +465 -0
  104. package/package.json +60 -0
  105. package/rollup.config.js +36 -0
  106. package/src/app/config/constants.ts +15 -0
  107. package/src/app/config/geojson-polyline.ts +47 -0
  108. package/src/app/config/geometry-polyline.ts +58 -0
  109. package/src/app/config/index.ts +3 -0
  110. package/src/app/lib/axios/api/axios.ts +17 -0
  111. package/src/app/lib/axios/api/index.ts +1 -0
  112. package/src/app/lib/axios/index.ts +1 -0
  113. package/src/app/lib/checking-coordinates/index.ts +1 -0
  114. package/src/app/lib/checking-coordinates/utils.ts +20 -0
  115. package/src/app/lib/index.ts +3 -0
  116. package/src/app/lib/saveKey/index.ts +1 -0
  117. package/src/app/lib/saveKey/utils.ts +18 -0
  118. package/src/app/types/additional-param/index.ts +6 -0
  119. package/src/app/types/index.ts +5 -0
  120. package/src/app/types/map/index.ts +10 -0
  121. package/src/app/types/router-param/index.ts +33 -0
  122. package/src/app/types/search-param/index.ts +13 -0
  123. package/src/app/types/window/index.ts +7 -0
  124. package/src/index.d.ts +4 -0
  125. package/src/index.ts +26 -0
  126. package/src/lib/map/utils.ts +35 -0
  127. package/src/lib/routing/api.ts +17 -0
  128. package/src/lib/routing/utils.ts +37 -0
  129. package/src/lib/search/api.ts +13 -0
  130. package/src/lib/search/utils.ts +40 -0
  131. 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,3 @@
1
+ export * from "./axios";
2
+ export * from "./checking-coordinates";
3
+ export * from "./saveKey";
@@ -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,6 @@
1
+ interface IAdditionalParamType {
2
+ lat: string;
3
+ lng: string;
4
+ }
5
+
6
+ export type { IAdditionalParamType };
@@ -0,0 +1,5 @@
1
+ // export * from "./window";
2
+ export * from "./search-param";
3
+ export * from "./additional-param";
4
+ export * from "./router-param";
5
+ export * from "./map";
@@ -0,0 +1,10 @@
1
+ interface IMahalMapOptions {
2
+ container?: string;
3
+ style?: string;
4
+ theme?: "dark" | "light";
5
+ center?: [number, number];
6
+ zoom?: number;
7
+ autoAddVectorSource?: boolean;
8
+ }
9
+
10
+ export type { IMahalMapOptions };
@@ -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 };
@@ -0,0 +1,13 @@
1
+ interface ISearchParam {
2
+ id?: string;
3
+ text?: string;
4
+ lat?: string;
5
+ lng?: string;
6
+ radius?: string;
7
+ user_lat?: string;
8
+ user_lng?: string;
9
+ limit?: string;
10
+ page?: string;
11
+ }
12
+
13
+ export type { ISearchParam };
@@ -0,0 +1,7 @@
1
+ // declare global {
2
+ // interface Window {
3
+ // maplibregl: typeof import("maplibre-gl");
4
+ // }
5
+ // }
6
+
7
+ // export default Window;
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module "mahal_map" {
2
+ export const MahalMap: any;
3
+ export default MahalMap;
4
+ }
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
+ }