radar-sdk-js 4.2.0-beta.3 → 4.2.0-beta.5
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 +121 -104
- package/dist/radar.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/ui/RadarMap.d.ts +1 -0
- package/dist/ui/RadarMarker.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/http.ts +4 -0
- package/src/types.ts +3 -2
- package/src/ui/RadarMap.ts +4 -39
- package/src/ui/RadarMarker.ts +63 -9
- 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.2.0-beta.
|
|
59
|
+
<script src="https://js.radar.com/v4.2.0-beta.5/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.2.0-beta.
|
|
77
|
-
<script src="https://js.radar.com/v4.2.0-beta.
|
|
76
|
+
<link href="https://js.radar.com/v4.2.0-beta.5/radar.css" rel="stylesheet">
|
|
77
|
+
<script src="https://js.radar.com/v4.2.0-beta.5/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.2.0-beta.
|
|
102
|
-
<script src="https://js.radar.com/v4.2.0-beta.
|
|
101
|
+
<link href="https://js.radar.com/v4.2.0-beta.5/radar.css" rel="stylesheet">
|
|
102
|
+
<script src="https://js.radar.com/v4.2.0-beta.5/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.2.0-beta.
|
|
134
|
-
<script src="https://js.radar.com/v4.2.0-beta.
|
|
133
|
+
<link href="https://js.radar.com/v4.2.0-beta.5/radar.css" rel="stylesheet">
|
|
134
|
+
<script src="https://js.radar.com/v4.2.0-beta.5/radar.min.js"></script>
|
|
135
135
|
</head>
|
|
136
136
|
|
|
137
137
|
<body>
|
package/dist/radar.js
CHANGED
|
@@ -409,7 +409,7 @@ class Navigator {
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
-
var SDK_VERSION = '4.2.0-beta.
|
|
412
|
+
var SDK_VERSION = '4.2.0-beta.5';
|
|
413
413
|
|
|
414
414
|
class Http {
|
|
415
415
|
static request({ method, path, data, host, versioned = true, headers = {}, }) {
|
|
@@ -465,6 +465,9 @@ class Http {
|
|
|
465
465
|
Object.entries(allHeaders).forEach(([key, val]) => {
|
|
466
466
|
xhr.setRequestHeader(key, val);
|
|
467
467
|
});
|
|
468
|
+
if (allHeaders['Content-Type'] === 'image/png') {
|
|
469
|
+
xhr.responseType = 'blob';
|
|
470
|
+
}
|
|
468
471
|
xhr.onload = () => {
|
|
469
472
|
var _a;
|
|
470
473
|
let response;
|
|
@@ -1406,73 +1409,6 @@ class VerifyAPI {
|
|
|
1406
1409
|
}
|
|
1407
1410
|
}
|
|
1408
1411
|
|
|
1409
|
-
const defaultMarkerOptions = {
|
|
1410
|
-
color: '#000257',
|
|
1411
|
-
};
|
|
1412
|
-
class RadarMarker extends maplibregl.Marker {
|
|
1413
|
-
constructor(markerOptions) {
|
|
1414
|
-
const maplibreOptions = Object.assign({}, defaultMarkerOptions);
|
|
1415
|
-
if (markerOptions.color) {
|
|
1416
|
-
maplibreOptions.color = markerOptions.color;
|
|
1417
|
-
}
|
|
1418
|
-
if (markerOptions.element) {
|
|
1419
|
-
maplibreOptions.element = markerOptions.element;
|
|
1420
|
-
}
|
|
1421
|
-
if (markerOptions.scale) {
|
|
1422
|
-
maplibreOptions.scale = markerOptions.scale;
|
|
1423
|
-
}
|
|
1424
|
-
if (markerOptions.image) {
|
|
1425
|
-
const element = document.createElement('div');
|
|
1426
|
-
element.style.backgroundImage = `url(${markerOptions.image.url})`;
|
|
1427
|
-
element.style.width = markerOptions.image.width;
|
|
1428
|
-
element.style.height = markerOptions.image.height;
|
|
1429
|
-
maplibreOptions.element = element;
|
|
1430
|
-
}
|
|
1431
|
-
super(maplibreOptions);
|
|
1432
|
-
if (markerOptions.image) {
|
|
1433
|
-
this._image = markerOptions.image;
|
|
1434
|
-
}
|
|
1435
|
-
// set popup text or HTML
|
|
1436
|
-
if (markerOptions.text) {
|
|
1437
|
-
const popup = new maplibregl.Popup({ offset: 35 }).setText(markerOptions.text);
|
|
1438
|
-
this.setPopup(popup);
|
|
1439
|
-
}
|
|
1440
|
-
else if (markerOptions.html) {
|
|
1441
|
-
const popup = new maplibregl.Popup({ offset: 35 }).setHTML(markerOptions.html);
|
|
1442
|
-
this.setPopup(popup);
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
addTo(map) {
|
|
1446
|
-
if (map._customMarkerRawSvg && !this._image) {
|
|
1447
|
-
this._element.innerHTML = map._customMarkerRawSvg;
|
|
1448
|
-
}
|
|
1449
|
-
map._markers.push(this);
|
|
1450
|
-
return super.addTo(map);
|
|
1451
|
-
}
|
|
1452
|
-
remove() {
|
|
1453
|
-
if (this._map) {
|
|
1454
|
-
this._map._markers = this._map._markers.filter((marker) => marker !== this);
|
|
1455
|
-
}
|
|
1456
|
-
return super.remove();
|
|
1457
|
-
}
|
|
1458
|
-
getOptions() {
|
|
1459
|
-
const markerOptions = {
|
|
1460
|
-
// TODO: element: marker.getElement(),
|
|
1461
|
-
image: this._image,
|
|
1462
|
-
color: this._color,
|
|
1463
|
-
scale: this._scale,
|
|
1464
|
-
offset: this.getOffset(),
|
|
1465
|
-
anchor: this._anchor,
|
|
1466
|
-
draggable: this.isDraggable(),
|
|
1467
|
-
clickTolerance: this._clickTolerance,
|
|
1468
|
-
rotation: this.getRotation(),
|
|
1469
|
-
rotationAlignment: this.getRotationAlignment(),
|
|
1470
|
-
pitchAlignment: this.getPitchAlignment()
|
|
1471
|
-
};
|
|
1472
|
-
return markerOptions;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
1412
|
const RADAR_LOGO_URL = 'https://api.radar.io/maps/static/images/logo.svg';
|
|
1477
1413
|
class RadarLogoControl {
|
|
1478
1414
|
onAdd() {
|
|
@@ -1574,43 +1510,124 @@ class RadarMap extends maplibregl.Map {
|
|
|
1574
1510
|
};
|
|
1575
1511
|
this.on('resize', onResize);
|
|
1576
1512
|
this.on('load', onResize);
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1513
|
+
}
|
|
1514
|
+
getMarkers() {
|
|
1515
|
+
return this._markers;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
const defaultMarkerOptions = {
|
|
1520
|
+
color: '#000257',
|
|
1521
|
+
};
|
|
1522
|
+
const fileExtensionToContentType = {
|
|
1523
|
+
svg: 'image/svg+xml',
|
|
1524
|
+
png: 'image/png',
|
|
1525
|
+
};
|
|
1526
|
+
const getFileExtension = (file) => {
|
|
1527
|
+
return file.split('.').pop() || '';
|
|
1528
|
+
};
|
|
1529
|
+
const createImageElement = (options) => {
|
|
1530
|
+
const element = document.createElement('img');
|
|
1531
|
+
element.src = options.url;
|
|
1532
|
+
if (options.width) {
|
|
1533
|
+
element.width = options.width;
|
|
1534
|
+
}
|
|
1535
|
+
if (options.height) {
|
|
1536
|
+
element.height = options.height;
|
|
1537
|
+
}
|
|
1538
|
+
element.style.maxWidth = '64px';
|
|
1539
|
+
element.style.maxHeight = '64px';
|
|
1540
|
+
return element;
|
|
1541
|
+
};
|
|
1542
|
+
class RadarMarker extends maplibregl.Marker {
|
|
1543
|
+
constructor(markerOptions) {
|
|
1544
|
+
const maplibreOptions = Object.assign({}, defaultMarkerOptions);
|
|
1545
|
+
if (markerOptions.color) {
|
|
1546
|
+
maplibreOptions.color = markerOptions.color;
|
|
1547
|
+
}
|
|
1548
|
+
if (markerOptions.element) {
|
|
1549
|
+
maplibreOptions.element = markerOptions.element;
|
|
1550
|
+
}
|
|
1551
|
+
if (markerOptions.scale) {
|
|
1552
|
+
maplibreOptions.scale = markerOptions.scale;
|
|
1553
|
+
}
|
|
1554
|
+
if (markerOptions.image) {
|
|
1555
|
+
maplibreOptions.element = createImageElement(markerOptions.image);
|
|
1556
|
+
}
|
|
1557
|
+
super(maplibreOptions);
|
|
1558
|
+
if (markerOptions.image) {
|
|
1559
|
+
this._image = markerOptions.image;
|
|
1560
|
+
}
|
|
1561
|
+
if (markerOptions.customMarkerId) {
|
|
1562
|
+
const ext = getFileExtension(markerOptions.customMarkerId);
|
|
1563
|
+
if (ext !== 'svg' && ext !== 'png') {
|
|
1564
|
+
Logger.error(`Invalid custom marker extension ${ext} - falling back to default marker`);
|
|
1598
1565
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1566
|
+
else {
|
|
1567
|
+
this._customMarkerId = markerOptions.customMarkerId;
|
|
1568
|
+
const originalElement = this._element.cloneNode(true);
|
|
1569
|
+
this._element.childNodes.forEach((child) => {
|
|
1570
|
+
child.remove();
|
|
1571
|
+
});
|
|
1572
|
+
const contentType = fileExtensionToContentType[ext];
|
|
1573
|
+
Http.request({
|
|
1574
|
+
method: 'GET',
|
|
1575
|
+
versioned: false,
|
|
1576
|
+
path: `maps/PlACEHOLDER/markers/${markerOptions.customMarkerId}`,
|
|
1577
|
+
headers: {
|
|
1578
|
+
'Content-Type': contentType,
|
|
1579
|
+
},
|
|
1580
|
+
}).then((res) => {
|
|
1581
|
+
if (res.data instanceof Blob) {
|
|
1582
|
+
// png returns a Blob
|
|
1583
|
+
const customMarkerUrl = URL.createObjectURL(res.data);
|
|
1584
|
+
this._element.replaceChildren(createImageElement({ url: customMarkerUrl }));
|
|
1585
|
+
}
|
|
1586
|
+
else {
|
|
1587
|
+
// svg returns an xml string
|
|
1588
|
+
this._element.innerHTML = res.data;
|
|
1589
|
+
}
|
|
1590
|
+
}).catch((err) => {
|
|
1591
|
+
Logger.error(`Could not get custom marker: ${err.message} - falling back to default marker`);
|
|
1592
|
+
this._element.replaceChildren(...originalElement.childNodes);
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
// set popup text or HTML
|
|
1597
|
+
if (markerOptions.text) {
|
|
1598
|
+
const popup = new maplibregl.Popup({ offset: 35 }).setText(markerOptions.text);
|
|
1599
|
+
this.setPopup(popup);
|
|
1600
|
+
}
|
|
1601
|
+
else if (markerOptions.html) {
|
|
1602
|
+
const popup = new maplibregl.Popup({ offset: 35 }).setHTML(markerOptions.html);
|
|
1603
|
+
this.setPopup(popup);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
addTo(map) {
|
|
1607
|
+
map._markers.push(this);
|
|
1608
|
+
return super.addTo(map);
|
|
1609
|
+
}
|
|
1610
|
+
remove() {
|
|
1611
|
+
if (this._map) {
|
|
1612
|
+
this._map._markers = this._map._markers.filter((marker) => marker !== this);
|
|
1613
|
+
}
|
|
1614
|
+
return super.remove();
|
|
1615
|
+
}
|
|
1616
|
+
getOptions() {
|
|
1617
|
+
const markerOptions = {
|
|
1618
|
+
// TODO: element: marker.getElement(),
|
|
1619
|
+
image: this._image,
|
|
1620
|
+
color: this._color,
|
|
1621
|
+
scale: this._scale,
|
|
1622
|
+
offset: this.getOffset(),
|
|
1623
|
+
anchor: this._anchor,
|
|
1624
|
+
draggable: this.isDraggable(),
|
|
1625
|
+
clickTolerance: this._clickTolerance,
|
|
1626
|
+
rotation: this.getRotation(),
|
|
1627
|
+
rotationAlignment: this.getRotationAlignment(),
|
|
1628
|
+
pitchAlignment: this.getPitchAlignment()
|
|
1629
|
+
};
|
|
1630
|
+
return markerOptions;
|
|
1614
1631
|
}
|
|
1615
1632
|
}
|
|
1616
1633
|
|
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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string;
|
|
348
|
-
width
|
|
349
|
-
height
|
|
348
|
+
width?: number;
|
|
349
|
+
height?: number;
|
|
350
350
|
}
|
|
351
351
|
export interface RadarMarkerOptions extends maplibregl.MarkerOptions {
|
|
352
352
|
text?: string;
|
|
353
353
|
html?: string;
|
|
354
354
|
image?: RadarMarkerImage;
|
|
355
|
+
customMarkerId?: string;
|
|
355
356
|
}
|
|
356
357
|
export interface RadarAutocompleteUIOptions {
|
|
357
358
|
container: string | HTMLElement;
|
package/dist/ui/RadarMap.d.ts
CHANGED
package/dist/ui/RadarMarker.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { RadarMarkerImage, RadarMarkerOptions } from '../types';
|
|
|
4
4
|
declare class RadarMarker extends maplibregl.Marker {
|
|
5
5
|
_map: RadarMap;
|
|
6
6
|
_image?: RadarMarkerImage;
|
|
7
|
+
_customMarkerId?: string;
|
|
7
8
|
constructor(markerOptions: RadarMarkerOptions);
|
|
8
9
|
addTo(map: RadarMap): this;
|
|
9
10
|
remove(): this;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.2.0-beta.
|
|
1
|
+
declare const _default: "4.2.0-beta.5";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
package/src/http.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -460,14 +460,15 @@ export interface RadarMapOptions extends maplibregl.MapOptions {
|
|
|
460
460
|
|
|
461
461
|
export interface RadarMarkerImage {
|
|
462
462
|
url: string;
|
|
463
|
-
width
|
|
464
|
-
height
|
|
463
|
+
width?: number;
|
|
464
|
+
height?: number;
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
export interface RadarMarkerOptions extends maplibregl.MarkerOptions {
|
|
468
468
|
text?: string;
|
|
469
469
|
html?: string;
|
|
470
470
|
image?: RadarMarkerImage;
|
|
471
|
+
customMarkerId?: string;
|
|
471
472
|
}
|
|
472
473
|
|
|
473
474
|
export interface RadarAutocompleteUIOptions {
|
package/src/ui/RadarMap.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import maplibregl from 'maplibre-gl';
|
|
2
2
|
|
|
3
3
|
import RadarMarker from './RadarMarker';
|
|
4
|
+
import RadarLogoControl from './RadarLogoControl';
|
|
4
5
|
|
|
5
6
|
import Config from '../config';
|
|
6
|
-
import Http from '../http';
|
|
7
7
|
import Logger from '../logger';
|
|
8
|
-
import RadarLogoControl from './RadarLogoControl';
|
|
9
8
|
|
|
10
9
|
import type { RadarOptions, RadarMapOptions } from '../types';
|
|
11
10
|
|
|
@@ -121,44 +120,10 @@ class RadarMap extends maplibregl.Map {
|
|
|
121
120
|
};
|
|
122
121
|
this.on('resize', onResize);
|
|
123
122
|
this.on('load', onResize);
|
|
123
|
+
}
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const style = this.getStyle();
|
|
128
|
-
|
|
129
|
-
const customMarkers = (style.metadata as any)?.['radar:customMarkers'];
|
|
130
|
-
if (Array.isArray(customMarkers) && customMarkers.length > 0) {
|
|
131
|
-
const customMarker = customMarkers[0]; // only support one custom marker for now
|
|
132
|
-
try {
|
|
133
|
-
const markerRawSvg = await Http.request({
|
|
134
|
-
method: 'GET',
|
|
135
|
-
versioned: false,
|
|
136
|
-
path: `maps/markers/${customMarker.id}`,
|
|
137
|
-
headers: {
|
|
138
|
-
'Content-Type': 'image/svg+xml',
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
this._customMarkerRawSvg = markerRawSvg.data;
|
|
142
|
-
} catch (err) {
|
|
143
|
-
Logger.warn(`Error getting custom marker: ${customMarker.id} - using default marker.`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// set markers if necessary
|
|
148
|
-
this._markers.forEach((marker) => {
|
|
149
|
-
if (this._customMarkerRawSvg && !marker._image) {
|
|
150
|
-
// set custom marker
|
|
151
|
-
marker._element.innerHTML = this._customMarkerRawSvg;
|
|
152
|
-
} else {
|
|
153
|
-
const markerOptions = marker.getOptions();
|
|
154
|
-
const newMarker = new RadarMarker(markerOptions); // get default element
|
|
155
|
-
|
|
156
|
-
// set default element
|
|
157
|
-
marker._element.innerHTML = newMarker._element.innerHTML;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
this.on('styledata', onStyleLoad);
|
|
125
|
+
getMarkers(): RadarMarker[] {
|
|
126
|
+
return this._markers;
|
|
162
127
|
}
|
|
163
128
|
};
|
|
164
129
|
|
package/src/ui/RadarMarker.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import maplibregl from 'maplibre-gl';
|
|
2
2
|
|
|
3
|
+
import Http from '../http';
|
|
4
|
+
import Logger from '../logger';
|
|
5
|
+
|
|
3
6
|
import type RadarMap from './RadarMap';
|
|
4
7
|
|
|
5
8
|
import type { RadarMarkerImage, RadarMarkerOptions } from '../types';
|
|
@@ -8,9 +11,32 @@ const defaultMarkerOptions: maplibregl.MarkerOptions = {
|
|
|
8
11
|
color: '#000257',
|
|
9
12
|
};
|
|
10
13
|
|
|
14
|
+
const fileExtensionToContentType: Record<string, string> = {
|
|
15
|
+
svg: 'image/svg+xml',
|
|
16
|
+
png: 'image/png',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getFileExtension = (file: string): string => {
|
|
20
|
+
return file.split('.').pop() || '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const createImageElement = (options: RadarMarkerImage) => {
|
|
24
|
+
const element = document.createElement('img');
|
|
25
|
+
element.src = options.url;
|
|
26
|
+
if (options.width) {
|
|
27
|
+
element.width = options.width;
|
|
28
|
+
}
|
|
29
|
+
if (options.height) {
|
|
30
|
+
element.height = options.height;
|
|
31
|
+
}
|
|
32
|
+
element.style.maxWidth = '64px';
|
|
33
|
+
element.style.maxHeight = '64px';
|
|
34
|
+
return element;
|
|
35
|
+
}
|
|
11
36
|
class RadarMarker extends maplibregl.Marker {
|
|
12
37
|
_map!: RadarMap;
|
|
13
38
|
_image?: RadarMarkerImage;
|
|
39
|
+
_customMarkerId?: string;
|
|
14
40
|
|
|
15
41
|
constructor(markerOptions: RadarMarkerOptions) {
|
|
16
42
|
const maplibreOptions: maplibregl.MarkerOptions = Object.assign({}, defaultMarkerOptions);
|
|
@@ -25,12 +51,7 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
25
51
|
maplibreOptions.scale = markerOptions.scale;
|
|
26
52
|
}
|
|
27
53
|
if (markerOptions.image) {
|
|
28
|
-
|
|
29
|
-
element.style.backgroundImage = `url(${markerOptions.image.url})`;
|
|
30
|
-
element.style.width = markerOptions.image.width;
|
|
31
|
-
element.style.height = markerOptions.image.height;
|
|
32
|
-
|
|
33
|
-
maplibreOptions.element = element;
|
|
54
|
+
maplibreOptions.element = createImageElement(markerOptions.image);
|
|
34
55
|
}
|
|
35
56
|
|
|
36
57
|
super(maplibreOptions);
|
|
@@ -39,6 +60,42 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
39
60
|
this._image = markerOptions.image;
|
|
40
61
|
}
|
|
41
62
|
|
|
63
|
+
if (markerOptions.customMarkerId) {
|
|
64
|
+
const ext = getFileExtension(markerOptions.customMarkerId);
|
|
65
|
+
if (ext !== 'svg' && ext !== 'png') {
|
|
66
|
+
Logger.error(`Invalid custom marker extension ${ext} - falling back to default marker`);
|
|
67
|
+
} else {
|
|
68
|
+
this._customMarkerId = markerOptions.customMarkerId;
|
|
69
|
+
|
|
70
|
+
const originalElement = this._element.cloneNode(true);
|
|
71
|
+
this._element.childNodes.forEach((child) => {
|
|
72
|
+
child.remove();
|
|
73
|
+
});
|
|
74
|
+
const contentType = fileExtensionToContentType[ext];
|
|
75
|
+
|
|
76
|
+
Http.request({
|
|
77
|
+
method: 'GET',
|
|
78
|
+
versioned: false,
|
|
79
|
+
path: `maps/PlACEHOLDER/markers/${markerOptions.customMarkerId}`,
|
|
80
|
+
headers: {
|
|
81
|
+
'Content-Type': contentType,
|
|
82
|
+
},
|
|
83
|
+
}).then((res) => {
|
|
84
|
+
if (res.data instanceof Blob) {
|
|
85
|
+
// png returns a Blob
|
|
86
|
+
const customMarkerUrl = URL.createObjectURL(res.data);
|
|
87
|
+
this._element.replaceChildren(createImageElement({ url: customMarkerUrl }));
|
|
88
|
+
} else {
|
|
89
|
+
// svg returns an xml string
|
|
90
|
+
this._element.innerHTML = res.data;
|
|
91
|
+
}
|
|
92
|
+
}).catch((err) => {
|
|
93
|
+
Logger.error(`Could not get custom marker: ${err.message} - falling back to default marker`);
|
|
94
|
+
this._element.replaceChildren(...originalElement.childNodes);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
42
99
|
// set popup text or HTML
|
|
43
100
|
if (markerOptions.text) {
|
|
44
101
|
const popup = new maplibregl.Popup({ offset: 35 }).setText(markerOptions.text);
|
|
@@ -50,9 +107,6 @@ class RadarMarker extends maplibregl.Marker {
|
|
|
50
107
|
}
|
|
51
108
|
|
|
52
109
|
addTo(map: RadarMap) {
|
|
53
|
-
if (map._customMarkerRawSvg && !this._image) {
|
|
54
|
-
this._element.innerHTML = map._customMarkerRawSvg;
|
|
55
|
-
}
|
|
56
110
|
map._markers.push(this);
|
|
57
111
|
return super.addTo(map);
|
|
58
112
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.2.0-beta.
|
|
1
|
+
export default '4.2.0-beta.5';
|