mahal_map 1.4.9 → 1.5.1
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/README.md +114 -21
- package/dist/index.d.mts +140 -113
- package/dist/index.d.ts +140 -113
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -3
- package/dist/index.mjs.map +1 -1
- package/dist/mahal_map.sdk.js +1 -1
- package/package.json +12 -13
package/README.md
CHANGED
|
@@ -1,43 +1,136 @@
|
|
|
1
1
|
# Mahal Map
|
|
2
2
|
|
|
3
|
-
Mahal Map
|
|
3
|
+
Mahal Map is a JavaScript/TypeScript SDK for working with Mahal map services on top of MapLibre GL JS.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install maplibre-gl
|
|
8
|
+
npm install mahal_map maplibre-gl
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
`maplibre-gl` is a peer dependency: the application that uses this SDK must install it or include it through a browser script.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import
|
|
13
|
+
## NPM Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import maplibregl from "maplibre-gl";
|
|
17
|
+
import "maplibre-gl/dist/maplibre-gl.css";
|
|
18
|
+
import { MahalMap, MahalMapDefaultMarker } from "mahal_map";
|
|
19
|
+
|
|
20
|
+
const mainMap = MahalMap.create(
|
|
21
|
+
{
|
|
22
|
+
container: "main-map",
|
|
23
|
+
center: [69.624024, 40.279687],
|
|
24
|
+
zoom: 12,
|
|
25
|
+
},
|
|
26
|
+
maplibregl,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const marker = new MahalMapDefaultMarker({
|
|
30
|
+
coordinates: [69.624024, 40.279687],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
mainMap.addMarker(marker);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Multiple Maps
|
|
37
|
+
|
|
38
|
+
`MahalMap.create()` always creates and returns a new map instance. The SDK also stores created instances by their `container` key.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const mainMap = MahalMap.create({ container: "main" }, maplibregl);
|
|
42
|
+
const miniMap = MahalMap.create({ container: "mini" }, maplibregl);
|
|
43
|
+
|
|
44
|
+
MahalMap.getInstance("main").setZoom(14);
|
|
45
|
+
MahalMap.addMarker(miniMap, marker);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Browser SDK Usage
|
|
49
|
+
|
|
50
|
+
For direct browser usage, include MapLibre first and then the Mahal Map SDK bundle:
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<link
|
|
54
|
+
rel="stylesheet"
|
|
55
|
+
href="https://unpkg.com/maplibre-gl@5.3.0/dist/maplibre-gl.css"
|
|
56
|
+
/>
|
|
57
|
+
<script src="https://unpkg.com/maplibre-gl@5.3.0/dist/maplibre-gl.js"></script>
|
|
58
|
+
<script src="/dist/mahal_map.sdk.js?apikey=YOUR_API_KEY"></script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The browser SDK reads `apikey` from its script URL and stores it as the default API key for search and routing requests.
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<script>
|
|
65
|
+
const map = MahalMap.create({
|
|
66
|
+
container: "map",
|
|
67
|
+
center: [69.624024, 40.279687],
|
|
68
|
+
zoom: 12,
|
|
69
|
+
});
|
|
70
|
+
</script>
|
|
71
|
+
```
|
|
17
72
|
|
|
18
|
-
|
|
19
|
-
|
|
73
|
+
## Search
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { Search, SearchByLocation } from "mahal_map";
|
|
77
|
+
|
|
78
|
+
const results = await Search("Dushanbe", "");
|
|
79
|
+
|
|
80
|
+
const nearby = await SearchByLocation({
|
|
81
|
+
lat: 38.5737,
|
|
82
|
+
lng: 68.7738,
|
|
83
|
+
});
|
|
20
84
|
```
|
|
21
85
|
|
|
22
|
-
##
|
|
86
|
+
## Routing
|
|
23
87
|
|
|
24
|
-
|
|
88
|
+
```ts
|
|
89
|
+
import { Router } from "mahal_map";
|
|
25
90
|
|
|
26
|
-
|
|
27
|
-
|
|
91
|
+
const routes = await Router(
|
|
92
|
+
[
|
|
93
|
+
[69.624024, 40.279687],
|
|
94
|
+
[68.7738, 38.5737],
|
|
95
|
+
],
|
|
96
|
+
"geojson",
|
|
97
|
+
"",
|
|
98
|
+
);
|
|
28
99
|
```
|
|
29
100
|
|
|
30
|
-
##
|
|
101
|
+
## Development
|
|
31
102
|
|
|
32
103
|
```sh
|
|
33
|
-
npm run
|
|
104
|
+
npm run build
|
|
105
|
+
npm run build:sdk
|
|
106
|
+
npm run build:all
|
|
107
|
+
npm test
|
|
34
108
|
```
|
|
35
109
|
|
|
36
|
-
|
|
110
|
+
`npm run build` creates the npm package output. `npm run build:sdk` creates the browser IIFE SDK bundle.
|
|
111
|
+
|
|
112
|
+
## Project Structure
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
src/
|
|
116
|
+
index.ts
|
|
117
|
+
sdk.ts
|
|
118
|
+
config/
|
|
119
|
+
core/
|
|
120
|
+
markers/
|
|
121
|
+
services/
|
|
122
|
+
types/
|
|
123
|
+
utils/
|
|
124
|
+
```
|
|
37
125
|
|
|
38
|
-
- `
|
|
39
|
-
- `
|
|
126
|
+
- `index.ts` is the clean npm entrypoint.
|
|
127
|
+
- `sdk.ts` is the browser SDK entrypoint that reads `apikey` from the script URL.
|
|
128
|
+
- `core/` contains map and camera classes.
|
|
129
|
+
- `markers/` contains marker components and adapters.
|
|
130
|
+
- `services/` contains HTTP, auth key, search, and routing logic.
|
|
131
|
+
- `types/` contains public TypeScript contracts.
|
|
132
|
+
- `utils/` contains shared helpers and polyline utilities.
|
|
40
133
|
|
|
41
|
-
##
|
|
134
|
+
## License
|
|
42
135
|
|
|
43
|
-
|
|
136
|
+
ISC
|
package/dist/index.d.mts
CHANGED
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
import { Map, FlyToOptions } from 'maplibre-gl';
|
|
1
|
+
import { Map, FlyToOptions, Marker } from 'maplibre-gl';
|
|
2
|
+
import * as axios from 'axios';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
lng: string | number;
|
|
14
|
-
token?: string;
|
|
15
|
-
type?: string;
|
|
16
|
-
}
|
|
17
|
-
interface ISearch {
|
|
18
|
-
fullAddress: string;
|
|
19
|
-
latitude: number;
|
|
20
|
-
longitude: number;
|
|
21
|
-
type: string;
|
|
22
|
-
distance: number | null;
|
|
23
|
-
detailInfo: {
|
|
24
|
-
categories: string;
|
|
25
|
-
name: string;
|
|
26
|
-
};
|
|
27
|
-
detailDetail: {
|
|
28
|
-
city: string | null;
|
|
29
|
-
city_type: string | null;
|
|
30
|
-
street_name: string | null;
|
|
31
|
-
street_type: string | null;
|
|
32
|
-
subject_name: string | null;
|
|
33
|
-
subject_type: string | null;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
interface ISearchResponse {
|
|
37
|
-
success: boolean;
|
|
38
|
-
data: ISearch[];
|
|
39
|
-
message?: string;
|
|
4
|
+
declare class CameraController {
|
|
5
|
+
private map;
|
|
6
|
+
constructor(map: Map);
|
|
7
|
+
setZoom(zoom: number, smooth?: boolean): void;
|
|
8
|
+
setBearing(bearing: number, smooth?: boolean): void;
|
|
9
|
+
setPitch(pitch: number, smooth?: boolean): void;
|
|
10
|
+
toggle3D(is3D: boolean): void;
|
|
11
|
+
resetNorth(): void;
|
|
12
|
+
flyTo(options: FlyToOptions): void;
|
|
13
|
+
getPitch(): number;
|
|
40
14
|
}
|
|
41
15
|
|
|
42
16
|
interface IAdditionalParamType {
|
|
@@ -46,6 +20,32 @@ interface IAdditionalParamType {
|
|
|
46
20
|
limit?: number;
|
|
47
21
|
}
|
|
48
22
|
|
|
23
|
+
interface IMahalMapOptions {
|
|
24
|
+
container?: string | HTMLElement;
|
|
25
|
+
style?: string;
|
|
26
|
+
theme?: Theme;
|
|
27
|
+
center?: [number, number];
|
|
28
|
+
zoom?: number;
|
|
29
|
+
autoAddVectorSource?: boolean;
|
|
30
|
+
}
|
|
31
|
+
type Theme = "dark" | "light";
|
|
32
|
+
|
|
33
|
+
interface MahalMapDefaultMarkerProps {
|
|
34
|
+
coordinates: [number, number];
|
|
35
|
+
draggable?: boolean;
|
|
36
|
+
anchor?: "center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
37
|
+
color?: string;
|
|
38
|
+
svg?: string;
|
|
39
|
+
innerSvg?: string;
|
|
40
|
+
innerUrl?: string;
|
|
41
|
+
}
|
|
42
|
+
interface IMapMarker {
|
|
43
|
+
getElement(): HTMLElement;
|
|
44
|
+
getCoordinates(): [number, number];
|
|
45
|
+
isDraggable?(): boolean;
|
|
46
|
+
getAnchor?(): "center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
49
|
interface IRoute {
|
|
50
50
|
id: number;
|
|
51
51
|
type: string;
|
|
@@ -78,71 +78,75 @@ interface IRoute {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
interface
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
attributionControl: boolean;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface MahalMapDefaultMarkerProps {
|
|
92
|
-
coordinates: [number, number];
|
|
93
|
-
draggable?: boolean;
|
|
94
|
-
anchor?: "center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
95
|
-
color?: string;
|
|
96
|
-
svg?: string;
|
|
97
|
-
innerSvg?: string;
|
|
98
|
-
innerUrl?: string;
|
|
81
|
+
interface ISearchParam {
|
|
82
|
+
text: string;
|
|
83
|
+
lat?: string;
|
|
84
|
+
lng?: string;
|
|
85
|
+
token: string;
|
|
86
|
+
type?: string;
|
|
87
|
+
limit?: number;
|
|
99
88
|
}
|
|
100
|
-
interface
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
interface ISearchByLocationParam {
|
|
90
|
+
lat: string | number;
|
|
91
|
+
lng: string | number;
|
|
92
|
+
token?: string;
|
|
93
|
+
type?: string;
|
|
105
94
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
interface ISearchResponse {
|
|
96
|
+
longitude: number;
|
|
97
|
+
latitude: number;
|
|
98
|
+
fullAddress: string;
|
|
99
|
+
type: string;
|
|
100
|
+
distance: number | null;
|
|
101
|
+
detailInfo: {
|
|
102
|
+
categories: string;
|
|
103
|
+
name: string;
|
|
104
|
+
};
|
|
105
|
+
detailDetail: {
|
|
106
|
+
city: string | null;
|
|
107
|
+
city_type: string | null;
|
|
108
|
+
street_name: string | null;
|
|
109
|
+
street_type: string | null;
|
|
110
|
+
subject_name: string | null;
|
|
111
|
+
subject_type: string | null;
|
|
112
|
+
};
|
|
117
113
|
}
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
private createElement;
|
|
124
|
-
private applyColorToCustomSvg;
|
|
125
|
-
getElement(): HTMLElement;
|
|
126
|
-
getCoordinates(): [number, number];
|
|
127
|
-
isDraggable(): boolean;
|
|
128
|
-
getAnchor(): "center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
115
|
+
interface IReponse<T> {
|
|
116
|
+
success: boolean;
|
|
117
|
+
data: T;
|
|
118
|
+
message: string;
|
|
129
119
|
}
|
|
130
120
|
|
|
121
|
+
type MapLibreApi = {
|
|
122
|
+
Map: new (...args: ConstructorParameters<typeof Map>) => Map;
|
|
123
|
+
Marker: new (...args: ConstructorParameters<typeof Marker>) => Marker;
|
|
124
|
+
};
|
|
131
125
|
declare class MahalMap {
|
|
132
|
-
private static
|
|
126
|
+
private static instances;
|
|
133
127
|
private isReady;
|
|
134
128
|
private readyCallbacks;
|
|
135
129
|
private map;
|
|
136
130
|
private maplibre;
|
|
137
131
|
private camera;
|
|
132
|
+
private logoElement?;
|
|
138
133
|
private options;
|
|
134
|
+
private instanceKey;
|
|
139
135
|
private constructor();
|
|
140
|
-
static
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
static
|
|
144
|
-
static
|
|
145
|
-
|
|
136
|
+
private static getInstanceKey;
|
|
137
|
+
static create(options: IMahalMapOptions, maplibreObject?: MapLibreApi): MahalMap;
|
|
138
|
+
static onReady(container: string, callback: (map: Map) => void): void;
|
|
139
|
+
static getInstance(container: string): MahalMap;
|
|
140
|
+
static hasInstance(container: string): boolean;
|
|
141
|
+
static removeInstance(container: string): boolean;
|
|
142
|
+
static addMarker(instance: MahalMap, marker: IMapMarker): Marker;
|
|
143
|
+
static getCamera(instance: MahalMap): CameraController;
|
|
144
|
+
static getMap(instance: MahalMap): Map;
|
|
145
|
+
static setStyle(instance: MahalMap, theme: "dark" | "light"): void;
|
|
146
|
+
static setCenter(instance: MahalMap, center: [number, number]): void;
|
|
147
|
+
static setZoom(instance: MahalMap, zoom: number): void;
|
|
148
|
+
static destroy(instance: MahalMap): void;
|
|
149
|
+
addMarker(marker: IMapMarker): Marker;
|
|
146
150
|
init(map: Map): void;
|
|
147
151
|
getCamera(): CameraController;
|
|
148
152
|
getMap(): Map;
|
|
@@ -150,42 +154,65 @@ declare class MahalMap {
|
|
|
150
154
|
setCenter(center: [number, number]): void;
|
|
151
155
|
setZoom(zoom: number): void;
|
|
152
156
|
destroy(): void;
|
|
157
|
+
private addLogo;
|
|
158
|
+
private updateLogoColor;
|
|
159
|
+
private getLogoSvg;
|
|
153
160
|
}
|
|
154
161
|
|
|
162
|
+
declare function saveKey(param: string): void;
|
|
163
|
+
declare function clearKey(): void;
|
|
164
|
+
declare const getApiKey: () => string;
|
|
165
|
+
|
|
166
|
+
declare const api: axios.AxiosInstance;
|
|
167
|
+
|
|
168
|
+
declare function Router(param: number[][], typeData: string, token: string): Promise<IRoute[]>;
|
|
169
|
+
|
|
155
170
|
declare function Search(param: string, token: string, additionalParam?: IAdditionalParamType): Promise<ISearchResponse>;
|
|
156
171
|
declare function SearchByLocation(params: ISearchByLocationParam): Promise<ISearchResponse>;
|
|
157
172
|
|
|
158
|
-
declare
|
|
173
|
+
declare const index$1_Router: typeof Router;
|
|
174
|
+
declare const index$1_Search: typeof Search;
|
|
175
|
+
declare const index$1_SearchByLocation: typeof SearchByLocation;
|
|
176
|
+
declare const index$1_api: typeof api;
|
|
177
|
+
declare const index$1_clearKey: typeof clearKey;
|
|
178
|
+
declare const index$1_getApiKey: typeof getApiKey;
|
|
179
|
+
declare const index$1_saveKey: typeof saveKey;
|
|
180
|
+
declare namespace index$1 {
|
|
181
|
+
export { index$1_Router as Router, index$1_Search as Search, index$1_SearchByLocation as SearchByLocation, index$1_api as api, index$1_clearKey as clearKey, index$1_getApiKey as getApiKey, index$1_saveKey as saveKey };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
declare class MahalMapDefaultMarker {
|
|
185
|
+
private props;
|
|
186
|
+
private element;
|
|
187
|
+
constructor(props: MahalMapDefaultMarkerProps);
|
|
188
|
+
private createElement;
|
|
189
|
+
private applyColorToCustomSvg;
|
|
190
|
+
getElement(): HTMLElement;
|
|
191
|
+
getCoordinates(): [number, number];
|
|
192
|
+
isDraggable(): boolean;
|
|
193
|
+
getAnchor(): "center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare function checkCoordinates(coordinates: string): {
|
|
197
|
+
lat: string | undefined;
|
|
198
|
+
lng: string | undefined;
|
|
199
|
+
} | null;
|
|
159
200
|
|
|
160
201
|
declare function debounce<F extends (...args: any[]) => Promise<any>>(fn: F, delay: number): (...args: Parameters<F>) => Promise<ReturnType<F>>;
|
|
161
202
|
|
|
203
|
+
declare function geojsonPolyline(encoded: string): number[][];
|
|
204
|
+
|
|
205
|
+
declare function geometryPolyline(coordinates: number[][]): string;
|
|
206
|
+
|
|
162
207
|
declare function trimValue(value: string, cut: number): string;
|
|
163
208
|
|
|
209
|
+
declare const index_checkCoordinates: typeof checkCoordinates;
|
|
164
210
|
declare const index_debounce: typeof debounce;
|
|
211
|
+
declare const index_geojsonPolyline: typeof geojsonPolyline;
|
|
212
|
+
declare const index_geometryPolyline: typeof geometryPolyline;
|
|
165
213
|
declare const index_trimValue: typeof trimValue;
|
|
166
214
|
declare namespace index {
|
|
167
|
-
export { index_debounce as debounce, index_trimValue as trimValue };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
declare function saveKey(param: string): void;
|
|
171
|
-
declare function clearKey(): void;
|
|
172
|
-
declare const getApiKey: () => string;
|
|
173
|
-
|
|
174
|
-
declare const keyUtils_clearKey: typeof clearKey;
|
|
175
|
-
declare const keyUtils_getApiKey: typeof getApiKey;
|
|
176
|
-
declare const keyUtils_saveKey: typeof saveKey;
|
|
177
|
-
declare namespace keyUtils {
|
|
178
|
-
export { keyUtils_clearKey as clearKey, keyUtils_getApiKey as getApiKey, keyUtils_saveKey as saveKey };
|
|
215
|
+
export { index_checkCoordinates as checkCoordinates, index_debounce as debounce, index_geojsonPolyline as geojsonPolyline, index_geometryPolyline as geometryPolyline, index_trimValue as trimValue };
|
|
179
216
|
}
|
|
180
217
|
|
|
181
|
-
|
|
182
|
-
MahalMap: typeof MahalMap;
|
|
183
|
-
MahalMapDefaultMarker: typeof MahalMapDefaultMarker;
|
|
184
|
-
Search: typeof Search;
|
|
185
|
-
SearchByLocation: typeof SearchByLocation;
|
|
186
|
-
Router: typeof Router;
|
|
187
|
-
keyUtils: typeof keyUtils;
|
|
188
|
-
loadKeyFromScriptUrl: () => string;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export { type IAdditionalParamType, type IMahalMapOptions, type IMapMarker, type IRoute, type ISearch, type ISearchByLocationParam, type ISearchParam, type ISearchResponse, MahalMap, MahalMapDefaultMarker, type MahalMapDefaultMarkerProps, Router, Search, SearchByLocation, MMap as default, keyUtils, index as utils };
|
|
218
|
+
export { type IAdditionalParamType, type IMahalMapOptions, type IMapMarker, type IReponse, type IRoute, type ISearchByLocationParam, type ISearchParam, type ISearchResponse, MahalMap, MahalMapDefaultMarker, type MahalMapDefaultMarkerProps, Router, Search, SearchByLocation, type Theme, index$1 as keyUtils, index as utils };
|