radar-sdk-js 4.4.1 → 4.5.0-beta.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/README.md +7 -7
- package/dist/radar.js +92 -71
- package/dist/radar.js.map +1 -1
- package/dist/ui/RadarMap.d.ts +1 -0
- package/dist/ui/RadarMarker.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/ui/RadarMap.ts +11 -0
- package/src/ui/RadarMarker.ts +95 -75
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ });
|
|
|
56
56
|
|
|
57
57
|
Add the following script in your `html` file
|
|
58
58
|
```html
|
|
59
|
-
<script src="https://js.radar.com/v4.
|
|
59
|
+
<script src="https://js.radar.com/v4.5.0-beta.0/radar.min.js"></script>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
Then initialize the Radar SDK
|
|
@@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then
|
|
|
73
73
|
```html
|
|
74
74
|
<html>
|
|
75
75
|
<head>
|
|
76
|
-
<link href="https://js.radar.com/v4.
|
|
77
|
-
<script src="https://js.radar.com/v4.
|
|
76
|
+
<link href="https://js.radar.com/v4.5.0-beta.0/radar.css" rel="stylesheet">
|
|
77
|
+
<script src="https://js.radar.com/v4.5.0-beta.0/radar.min.js"></script>
|
|
78
78
|
</head>
|
|
79
79
|
|
|
80
80
|
<body>
|
|
@@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis
|
|
|
98
98
|
```html
|
|
99
99
|
<html>
|
|
100
100
|
<head>
|
|
101
|
-
<link href="https://js.radar.com/v4.
|
|
102
|
-
<script src="https://js.radar.com/v4.
|
|
101
|
+
<link href="https://js.radar.com/v4.5.0-beta.0/radar.css" rel="stylesheet">
|
|
102
|
+
<script src="https://js.radar.com/v4.5.0-beta.0/radar.min.js"></script>
|
|
103
103
|
</head>
|
|
104
104
|
|
|
105
105
|
<body>
|
|
@@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper
|
|
|
130
130
|
```html
|
|
131
131
|
<html>
|
|
132
132
|
<head>
|
|
133
|
-
<link href="https://js.radar.com/v4.
|
|
134
|
-
<script src="https://js.radar.com/v4.
|
|
133
|
+
<link href="https://js.radar.com/v4.5.0-beta.0/radar.css" rel="stylesheet">
|
|
134
|
+
<script src="https://js.radar.com/v4.5.0-beta.0/radar.min.js"></script>
|
|
135
135
|
</head>
|
|
136
136
|
|
|
137
137
|
<body>
|
package/dist/radar.js
CHANGED
|
@@ -405,7 +405,7 @@ class Navigator {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
var SDK_VERSION = '4.
|
|
408
|
+
var SDK_VERSION = '4.5.0-beta.0';
|
|
409
409
|
|
|
410
410
|
const inFlightRequests = new Map();
|
|
411
411
|
class Http {
|
|
@@ -2106,6 +2106,14 @@ class RadarMap extends maplibregl.Map {
|
|
|
2106
2106
|
};
|
|
2107
2107
|
this.on('resize', onResize);
|
|
2108
2108
|
this.on('load', onResize);
|
|
2109
|
+
// parse radar metadata from style
|
|
2110
|
+
this.on('style.load', () => {
|
|
2111
|
+
const style = this.getStyle();
|
|
2112
|
+
const metadata = style.metadata || {};
|
|
2113
|
+
if (metadata['radar:marker']) { // default marker associated with custom style
|
|
2114
|
+
this._defaultMarker = metadata['radar:marker'];
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2109
2117
|
}
|
|
2110
2118
|
addMarker(marker) {
|
|
2111
2119
|
this._markers.push(marker);
|
|
@@ -2249,78 +2257,10 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
2249
2257
|
maplibreOptions.scale = markerOptions.scale;
|
|
2250
2258
|
}
|
|
2251
2259
|
super(maplibreOptions);
|
|
2260
|
+
this._options = markerOptions;
|
|
2252
2261
|
// handle marker images (Radar marker, or custom URL)
|
|
2253
2262
|
if (markerOptions.marker || markerOptions.url) {
|
|
2254
|
-
|
|
2255
|
-
this._element.childNodes.forEach((child) => {
|
|
2256
|
-
child.remove();
|
|
2257
|
-
});
|
|
2258
|
-
const onSuccess = (blob) => {
|
|
2259
|
-
const markerObject = URL.createObjectURL(blob);
|
|
2260
|
-
this._element.replaceChildren(createImageElement({
|
|
2261
|
-
width: markerOptions.width,
|
|
2262
|
-
height: markerOptions.height,
|
|
2263
|
-
url: markerObject,
|
|
2264
|
-
}));
|
|
2265
|
-
};
|
|
2266
|
-
const onError = (err) => {
|
|
2267
|
-
Logger.error(`Could not load marker: ${err.message} - falling back to default marker`);
|
|
2268
|
-
IMAGE_CACHE.set(markerOptions.url, 'failed'); // mark as failed
|
|
2269
|
-
this._element.replaceChildren(...Array.from(originalElement.childNodes));
|
|
2270
|
-
};
|
|
2271
|
-
// custom URL image
|
|
2272
|
-
if (markerOptions.url) {
|
|
2273
|
-
const loadImage = () => {
|
|
2274
|
-
fetch(markerOptions.url)
|
|
2275
|
-
.then(res => {
|
|
2276
|
-
if (res.status === 200) {
|
|
2277
|
-
res.blob()
|
|
2278
|
-
.then((data) => {
|
|
2279
|
-
IMAGE_CACHE.set(markerOptions.url, data); // cache data
|
|
2280
|
-
onSuccess(data);
|
|
2281
|
-
})
|
|
2282
|
-
.catch(onError);
|
|
2283
|
-
}
|
|
2284
|
-
else {
|
|
2285
|
-
onError(new Error(res.statusText));
|
|
2286
|
-
}
|
|
2287
|
-
})
|
|
2288
|
-
.catch(onError);
|
|
2289
|
-
};
|
|
2290
|
-
// attempt to use cached data, otherwise fetch marker image data from URL
|
|
2291
|
-
useCachedImage(markerOptions.url)
|
|
2292
|
-
.then(onSuccess)
|
|
2293
|
-
.catch((reason) => {
|
|
2294
|
-
if (reason !== 'miss') {
|
|
2295
|
-
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.url}: ${reason}`);
|
|
2296
|
-
}
|
|
2297
|
-
loadImage();
|
|
2298
|
-
});
|
|
2299
|
-
}
|
|
2300
|
-
// Radar hosted image
|
|
2301
|
-
if (markerOptions.marker) {
|
|
2302
|
-
const loadMarker = () => {
|
|
2303
|
-
Http.request({
|
|
2304
|
-
method: 'GET',
|
|
2305
|
-
version: 'maps',
|
|
2306
|
-
path: `markers/${markerOptions.marker}`,
|
|
2307
|
-
responseType: 'blob',
|
|
2308
|
-
})
|
|
2309
|
-
.then(({ data }) => {
|
|
2310
|
-
IMAGE_CACHE.set(markerOptions.url, data); // cache data
|
|
2311
|
-
onSuccess(data);
|
|
2312
|
-
})
|
|
2313
|
-
.catch(onError);
|
|
2314
|
-
};
|
|
2315
|
-
useCachedImage(markerOptions.marker)
|
|
2316
|
-
.then(onSuccess)
|
|
2317
|
-
.catch((reason) => {
|
|
2318
|
-
if (reason !== 'miss') {
|
|
2319
|
-
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.marker} ${reason}`);
|
|
2320
|
-
}
|
|
2321
|
-
loadMarker();
|
|
2322
|
-
});
|
|
2323
|
-
}
|
|
2263
|
+
this.getCustomImage(markerOptions);
|
|
2324
2264
|
}
|
|
2325
2265
|
// handle deprecated popup options
|
|
2326
2266
|
if (markerOptions.text) {
|
|
@@ -2367,7 +2307,88 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
2367
2307
|
});
|
|
2368
2308
|
}
|
|
2369
2309
|
}
|
|
2310
|
+
// load marker image from a URL or as a Radar asset (custom styles)
|
|
2311
|
+
getCustomImage(markerOptions) {
|
|
2312
|
+
const originalElement = this._element.cloneNode(true);
|
|
2313
|
+
this._element.childNodes.forEach((child) => {
|
|
2314
|
+
child.remove();
|
|
2315
|
+
});
|
|
2316
|
+
const onSuccess = (blob) => {
|
|
2317
|
+
const markerObject = URL.createObjectURL(blob);
|
|
2318
|
+
this._element.replaceChildren(createImageElement({
|
|
2319
|
+
width: markerOptions.width,
|
|
2320
|
+
height: markerOptions.height,
|
|
2321
|
+
url: markerObject,
|
|
2322
|
+
}));
|
|
2323
|
+
};
|
|
2324
|
+
const onError = (err) => {
|
|
2325
|
+
Logger.error(`Could not load marker: ${err.message} - falling back to default marker`);
|
|
2326
|
+
IMAGE_CACHE.set(markerOptions.url, 'failed'); // mark as failed
|
|
2327
|
+
this._element.replaceChildren(...Array.from(originalElement.childNodes));
|
|
2328
|
+
};
|
|
2329
|
+
// custom URL image
|
|
2330
|
+
if (markerOptions.url) {
|
|
2331
|
+
const loadImage = () => {
|
|
2332
|
+
fetch(markerOptions.url)
|
|
2333
|
+
.then(res => {
|
|
2334
|
+
if (res.status === 200) {
|
|
2335
|
+
res.blob()
|
|
2336
|
+
.then((data) => {
|
|
2337
|
+
IMAGE_CACHE.set(markerOptions.url, data); // cache data
|
|
2338
|
+
onSuccess(data);
|
|
2339
|
+
})
|
|
2340
|
+
.catch(onError);
|
|
2341
|
+
}
|
|
2342
|
+
else {
|
|
2343
|
+
onError(new Error(res.statusText));
|
|
2344
|
+
}
|
|
2345
|
+
})
|
|
2346
|
+
.catch(onError);
|
|
2347
|
+
};
|
|
2348
|
+
// attempt to use cached data, otherwise fetch marker image data from URL
|
|
2349
|
+
useCachedImage(markerOptions.url)
|
|
2350
|
+
.then(onSuccess)
|
|
2351
|
+
.catch((reason) => {
|
|
2352
|
+
if (reason !== 'miss') {
|
|
2353
|
+
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.url}: ${reason}`);
|
|
2354
|
+
}
|
|
2355
|
+
loadImage();
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
// Radar hosted image
|
|
2359
|
+
if (markerOptions.marker) {
|
|
2360
|
+
const loadMarker = () => {
|
|
2361
|
+
Http.request({
|
|
2362
|
+
method: 'GET',
|
|
2363
|
+
version: 'maps',
|
|
2364
|
+
path: `markers/${markerOptions.marker}`,
|
|
2365
|
+
responseType: 'blob',
|
|
2366
|
+
})
|
|
2367
|
+
.then(({ data }) => {
|
|
2368
|
+
IMAGE_CACHE.set(markerOptions.url, data); // cache data
|
|
2369
|
+
onSuccess(data);
|
|
2370
|
+
})
|
|
2371
|
+
.catch(onError);
|
|
2372
|
+
};
|
|
2373
|
+
useCachedImage(markerOptions.marker)
|
|
2374
|
+
.then(onSuccess)
|
|
2375
|
+
.catch((reason) => {
|
|
2376
|
+
if (reason !== 'miss') {
|
|
2377
|
+
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.marker} ${reason}`);
|
|
2378
|
+
}
|
|
2379
|
+
loadMarker();
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2370
2383
|
addTo(map) {
|
|
2384
|
+
// use default marker associated with map style, if none is provided in options
|
|
2385
|
+
// (and custom style has an associated marker)
|
|
2386
|
+
const markerOptions = this._options;
|
|
2387
|
+
if (!markerOptions.url && !markerOptions.marker && !markerOptions.color) {
|
|
2388
|
+
if (map._defaultMarker) {
|
|
2389
|
+
this.getCustomImage(Object.assign(Object.assign({}, markerOptions), { marker: map._defaultMarker }));
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2371
2392
|
map.addMarker(this);
|
|
2372
2393
|
return super.addTo(map);
|
|
2373
2394
|
}
|
package/dist/radar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/ui/RadarMap.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { RadarMapOptions, RadarLineOptions, RadarPolylineOptions, RadarPoly
|
|
|
7
7
|
declare class RadarMap extends maplibregl.Map {
|
|
8
8
|
_markers: RadarMarker[];
|
|
9
9
|
_features: RadarMapFeature[];
|
|
10
|
+
_defaultMarker?: string;
|
|
10
11
|
constructor(radarMapOptions: RadarMapOptions);
|
|
11
12
|
addMarker(marker: RadarMarker): void;
|
|
12
13
|
removeMarker(marker: RadarMarker): void;
|
package/dist/ui/RadarMarker.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ import maplibregl from 'maplibre-gl';
|
|
|
2
2
|
import type RadarMap from './RadarMap';
|
|
3
3
|
import type { RadarMarkerOptions } from '../types';
|
|
4
4
|
declare class RadarMarker extends maplibregl.Marker {
|
|
5
|
+
_options: RadarMarkerOptions;
|
|
5
6
|
_map: RadarMap;
|
|
6
7
|
constructor(markerOptions: RadarMarkerOptions);
|
|
8
|
+
getCustomImage(markerOptions: RadarMarkerOptions): void;
|
|
7
9
|
addTo(map: RadarMap): this;
|
|
8
10
|
remove(): this;
|
|
9
11
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.5.0-beta.0";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
package/src/ui/RadarMap.ts
CHANGED
|
@@ -80,6 +80,7 @@ const getStyle = (options: RadarOptions, mapOptions: RadarMapOptions) => {
|
|
|
80
80
|
class RadarMap extends maplibregl.Map {
|
|
81
81
|
_markers: RadarMarker[] = [];
|
|
82
82
|
_features: RadarMapFeature[] = [];
|
|
83
|
+
_defaultMarker?: string;
|
|
83
84
|
|
|
84
85
|
constructor(radarMapOptions: RadarMapOptions) {
|
|
85
86
|
const config = Config.get();
|
|
@@ -152,6 +153,16 @@ class RadarMap extends maplibregl.Map {
|
|
|
152
153
|
};
|
|
153
154
|
this.on('resize', onResize);
|
|
154
155
|
this.on('load', onResize);
|
|
156
|
+
|
|
157
|
+
// parse radar metadata from style
|
|
158
|
+
this.on('style.load', () => {
|
|
159
|
+
const style = this.getStyle();
|
|
160
|
+
const metadata: any = style.metadata || {};
|
|
161
|
+
|
|
162
|
+
if (metadata['radar:marker']) { // default marker associated with custom style
|
|
163
|
+
this._defaultMarker = metadata['radar:marker'];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
addMarker(marker: RadarMarker) {
|
package/src/ui/RadarMarker.ts
CHANGED
|
@@ -89,6 +89,7 @@ const defaultMarkerOptions: RadarMarkerOptions = {
|
|
|
89
89
|
};
|
|
90
90
|
|
|
91
91
|
class RadarMarker extends maplibregl.Marker {
|
|
92
|
+
_options: RadarMarkerOptions;
|
|
92
93
|
_map!: RadarMap;
|
|
93
94
|
|
|
94
95
|
constructor(markerOptions: RadarMarkerOptions) {
|
|
@@ -107,83 +108,11 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
107
108
|
|
|
108
109
|
super(maplibreOptions);
|
|
109
110
|
|
|
111
|
+
this._options = markerOptions;
|
|
112
|
+
|
|
110
113
|
// handle marker images (Radar marker, or custom URL)
|
|
111
114
|
if (markerOptions.marker || markerOptions.url) {
|
|
112
|
-
|
|
113
|
-
this._element.childNodes.forEach((child) => {
|
|
114
|
-
child.remove();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const onSuccess = (blob: Blob) => {
|
|
118
|
-
const markerObject = URL.createObjectURL(blob);
|
|
119
|
-
this._element.replaceChildren(createImageElement({
|
|
120
|
-
width: markerOptions.width,
|
|
121
|
-
height: markerOptions.height,
|
|
122
|
-
url: markerObject,
|
|
123
|
-
}));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const onError = (err: any) => {
|
|
127
|
-
Logger.error(`Could not load marker: ${err.message} - falling back to default marker`);
|
|
128
|
-
IMAGE_CACHE.set(markerOptions.url as string, 'failed'); // mark as failed
|
|
129
|
-
this._element.replaceChildren(...Array.from(originalElement.childNodes));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// custom URL image
|
|
133
|
-
if (markerOptions.url) {
|
|
134
|
-
const loadImage = () => { // fetch marker data from URL
|
|
135
|
-
fetch(markerOptions.url as string)
|
|
136
|
-
.then(res => {
|
|
137
|
-
if (res.status === 200) {
|
|
138
|
-
res.blob()
|
|
139
|
-
.then((data) => {
|
|
140
|
-
IMAGE_CACHE.set(markerOptions.url as string, data); // cache data
|
|
141
|
-
onSuccess(data);
|
|
142
|
-
})
|
|
143
|
-
.catch(onError);
|
|
144
|
-
} else {
|
|
145
|
-
onError(new Error(res.statusText));
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
.catch(onError)
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
// attempt to use cached data, otherwise fetch marker image data from URL
|
|
152
|
-
useCachedImage(markerOptions.url)
|
|
153
|
-
.then(onSuccess)
|
|
154
|
-
.catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
|
|
155
|
-
if (reason !== 'miss') {
|
|
156
|
-
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.url}: ${reason}`);
|
|
157
|
-
}
|
|
158
|
-
loadImage();
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Radar hosted image
|
|
163
|
-
if (markerOptions.marker) {
|
|
164
|
-
const loadMarker = () => {
|
|
165
|
-
Http.request({
|
|
166
|
-
method: 'GET',
|
|
167
|
-
version: 'maps',
|
|
168
|
-
path: `markers/${markerOptions.marker}`,
|
|
169
|
-
responseType: 'blob',
|
|
170
|
-
})
|
|
171
|
-
.then(({ data }) => {
|
|
172
|
-
IMAGE_CACHE.set(markerOptions.url as string, data); // cache data
|
|
173
|
-
onSuccess(data)
|
|
174
|
-
})
|
|
175
|
-
.catch(onError);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
useCachedImage(markerOptions.marker as string)
|
|
179
|
-
.then(onSuccess)
|
|
180
|
-
.catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
|
|
181
|
-
if (reason !== 'miss') {
|
|
182
|
-
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.marker} ${reason}`);
|
|
183
|
-
}
|
|
184
|
-
loadMarker();
|
|
185
|
-
});
|
|
186
|
-
}
|
|
115
|
+
this.getCustomImage(markerOptions);
|
|
187
116
|
}
|
|
188
117
|
|
|
189
118
|
// handle deprecated popup options
|
|
@@ -238,7 +167,98 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
238
167
|
}
|
|
239
168
|
}
|
|
240
169
|
|
|
170
|
+
// load marker image from a URL or as a Radar asset (custom styles)
|
|
171
|
+
getCustomImage(markerOptions: RadarMarkerOptions) {
|
|
172
|
+
const originalElement = this._element.cloneNode(true);
|
|
173
|
+
this._element.childNodes.forEach((child) => {
|
|
174
|
+
child.remove();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const onSuccess = (blob: Blob) => {
|
|
178
|
+
const markerObject = URL.createObjectURL(blob);
|
|
179
|
+
this._element.replaceChildren(createImageElement({
|
|
180
|
+
width: markerOptions.width,
|
|
181
|
+
height: markerOptions.height,
|
|
182
|
+
url: markerObject,
|
|
183
|
+
}));
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const onError = (err: any) => {
|
|
187
|
+
Logger.error(`Could not load marker: ${err.message} - falling back to default marker`);
|
|
188
|
+
IMAGE_CACHE.set(markerOptions.url as string, 'failed'); // mark as failed
|
|
189
|
+
this._element.replaceChildren(...Array.from(originalElement.childNodes));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// custom URL image
|
|
193
|
+
if (markerOptions.url) {
|
|
194
|
+
const loadImage = () => { // fetch marker data from URL
|
|
195
|
+
fetch(markerOptions.url as string)
|
|
196
|
+
.then(res => {
|
|
197
|
+
if (res.status === 200) {
|
|
198
|
+
res.blob()
|
|
199
|
+
.then((data) => {
|
|
200
|
+
IMAGE_CACHE.set(markerOptions.url as string, data); // cache data
|
|
201
|
+
onSuccess(data);
|
|
202
|
+
})
|
|
203
|
+
.catch(onError);
|
|
204
|
+
} else {
|
|
205
|
+
onError(new Error(res.statusText));
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
.catch(onError)
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// attempt to use cached data, otherwise fetch marker image data from URL
|
|
212
|
+
useCachedImage(markerOptions.url)
|
|
213
|
+
.then(onSuccess)
|
|
214
|
+
.catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
|
|
215
|
+
if (reason !== 'miss') {
|
|
216
|
+
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.url}: ${reason}`);
|
|
217
|
+
}
|
|
218
|
+
loadImage();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Radar hosted image
|
|
223
|
+
if (markerOptions.marker) {
|
|
224
|
+
const loadMarker = () => {
|
|
225
|
+
Http.request({
|
|
226
|
+
method: 'GET',
|
|
227
|
+
version: 'maps',
|
|
228
|
+
path: `markers/${markerOptions.marker}`,
|
|
229
|
+
responseType: 'blob',
|
|
230
|
+
})
|
|
231
|
+
.then(({ data }) => {
|
|
232
|
+
IMAGE_CACHE.set(markerOptions.url as string, data); // cache data
|
|
233
|
+
onSuccess(data)
|
|
234
|
+
})
|
|
235
|
+
.catch(onError);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
useCachedImage(markerOptions.marker as string)
|
|
239
|
+
.then(onSuccess)
|
|
240
|
+
.catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
|
|
241
|
+
if (reason !== 'miss') {
|
|
242
|
+
Logger.debug(`RadarMarker: cache lookup for ${markerOptions.marker} ${reason}`);
|
|
243
|
+
}
|
|
244
|
+
loadMarker();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
241
249
|
addTo(map: RadarMap) {
|
|
250
|
+
// use default marker associated with map style, if none is provided in options
|
|
251
|
+
// (and custom style has an associated marker)
|
|
252
|
+
const markerOptions = this._options;
|
|
253
|
+
if (!markerOptions.url && !markerOptions.marker && !markerOptions.color) {
|
|
254
|
+
if (map._defaultMarker) {
|
|
255
|
+
this.getCustomImage({
|
|
256
|
+
...markerOptions,
|
|
257
|
+
marker: map._defaultMarker,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
242
262
|
map.addMarker(this);
|
|
243
263
|
return super.addTo(map);
|
|
244
264
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.5.0-beta.0';
|