radar-sdk-js 4.2.1-beta.1 → 4.2.1-beta.2
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/http.d.ts +1 -2
- package/dist/radar.js +1873 -1590
- package/dist/radar.js.map +1 -1
- package/dist/types.d.ts +4 -8
- package/dist/ui/map.d.ts +2 -4
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/track.ts +26 -26
- package/src/http.ts +20 -33
- package/src/types.ts +4 -9
- package/src/ui/map.ts +141 -9
- package/src/version.ts +1 -1
- package/dist/ui/RadarLogoControl.d.ts +0 -6
- package/dist/ui/RadarMap.d.ts +0 -10
- package/dist/ui/RadarMarker.d.ts +0 -13
- package/src/ui/RadarLogoControl.ts +0 -24
- package/src/ui/RadarMap.ts +0 -130
- package/src/ui/RadarMarker.ts +0 -140
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/types.d.ts
CHANGED
|
@@ -347,16 +347,12 @@ export interface RadarSearchGeofencesResponse extends RadarResponse {
|
|
|
347
347
|
export interface RadarMapOptions extends maplibregl.MapOptions {
|
|
348
348
|
container: string | HTMLElement;
|
|
349
349
|
}
|
|
350
|
-
export interface
|
|
351
|
-
|
|
352
|
-
width?: number;
|
|
353
|
-
height?: number;
|
|
354
|
-
}
|
|
355
|
-
export interface RadarMarkerOptions extends maplibregl.MarkerOptions {
|
|
350
|
+
export interface RadarMarkerOptions {
|
|
351
|
+
color?: string;
|
|
356
352
|
text?: string;
|
|
357
353
|
html?: string;
|
|
358
|
-
|
|
359
|
-
|
|
354
|
+
element?: HTMLElement;
|
|
355
|
+
scale?: number;
|
|
360
356
|
}
|
|
361
357
|
export interface RadarAutocompleteUIOptions {
|
|
362
358
|
container: string | HTMLElement;
|
package/dist/ui/map.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/// <reference types="mapbox__point-geometry" />
|
|
2
|
-
import RadarMap from './RadarMap';
|
|
3
|
-
import RadarMarker from './RadarMarker';
|
|
4
2
|
import type { RadarMapOptions, RadarMarkerOptions } from '../types';
|
|
5
3
|
declare class MapUI {
|
|
6
4
|
static getMapLibre(): {
|
|
@@ -47,7 +45,7 @@ declare class MapUI {
|
|
|
47
45
|
addProtocol(customProtocol: string, loadFn: (requestParameters: import("maplibre-gl").RequestParameters, callback: import("maplibre-gl").ResponseCallback<any>) => import("maplibre-gl").Cancelable): void;
|
|
48
46
|
removeProtocol(customProtocol: string): void;
|
|
49
47
|
};
|
|
50
|
-
static createMap(mapOptions: RadarMapOptions):
|
|
51
|
-
static createMarker(markerOptions?: RadarMarkerOptions):
|
|
48
|
+
static createMap(mapOptions: RadarMapOptions): maplibregl.Map;
|
|
49
|
+
static createMarker(markerOptions?: RadarMarkerOptions): maplibregl.Marker;
|
|
52
50
|
}
|
|
53
51
|
export default MapUI;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.2.1-beta.
|
|
1
|
+
declare const _default: "4.2.1-beta.2";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
package/src/api/track.ts
CHANGED
|
@@ -137,14 +137,14 @@ class TrackAPI {
|
|
|
137
137
|
}),
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
const
|
|
140
|
+
const reqToken = await signJWT(payload, dk);
|
|
141
141
|
|
|
142
142
|
response = await Http.request({
|
|
143
143
|
host,
|
|
144
144
|
method: 'POST',
|
|
145
145
|
path: 'track',
|
|
146
146
|
data: {
|
|
147
|
-
token,
|
|
147
|
+
token: reqToken,
|
|
148
148
|
},
|
|
149
149
|
headers: {
|
|
150
150
|
'X-Radar-Body-Is-Token': 'true',
|
|
@@ -160,33 +160,33 @@ class TrackAPI {
|
|
|
160
160
|
sclVal,
|
|
161
161
|
cslVal,
|
|
162
162
|
};
|
|
163
|
+
}
|
|
163
164
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const trackRes = {
|
|
175
|
-
user,
|
|
176
|
-
events,
|
|
177
|
-
location,
|
|
178
|
-
token,
|
|
179
|
-
expiresAt,
|
|
180
|
-
expiresIn,
|
|
181
|
-
passed,
|
|
182
|
-
} as RadarTrackVerifiedResponse;
|
|
183
|
-
|
|
184
|
-
if (options.debug) {
|
|
185
|
-
trackRes.response = response;
|
|
186
|
-
}
|
|
165
|
+
let { user, events, token, expiresAt } = response;
|
|
166
|
+
const location = { latitude, longitude, accuracy };
|
|
167
|
+
let passed;
|
|
168
|
+
let expiresIn;
|
|
169
|
+
if (expiresAt) {
|
|
170
|
+
expiresAt = new Date(expiresAt);
|
|
171
|
+
passed = user?.fraud?.passed && user?.country?.passed && user?.state?.passed;
|
|
172
|
+
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
|
|
173
|
+
}
|
|
187
174
|
|
|
188
|
-
|
|
175
|
+
const trackRes = {
|
|
176
|
+
user,
|
|
177
|
+
events,
|
|
178
|
+
location,
|
|
179
|
+
token,
|
|
180
|
+
expiresAt,
|
|
181
|
+
expiresIn,
|
|
182
|
+
passed,
|
|
183
|
+
} as RadarTrackVerifiedResponse;
|
|
184
|
+
|
|
185
|
+
if (options.debug) {
|
|
186
|
+
trackRes.response = response;
|
|
189
187
|
}
|
|
188
|
+
|
|
189
|
+
return trackRes;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
response = await Http.request({
|
package/src/http.ts
CHANGED
|
@@ -31,14 +31,12 @@ class Http {
|
|
|
31
31
|
path,
|
|
32
32
|
data,
|
|
33
33
|
host,
|
|
34
|
-
|
|
35
|
-
headers = {},
|
|
34
|
+
headers,
|
|
36
35
|
}: {
|
|
37
36
|
method: HttpMethod;
|
|
38
37
|
path: string;
|
|
39
38
|
data?: any;
|
|
40
39
|
host?: string;
|
|
41
|
-
versioned?: boolean;
|
|
42
40
|
headers?: Record<string, string>;
|
|
43
41
|
}) {
|
|
44
42
|
return new Promise<HttpResponse>((resolve, reject) => {
|
|
@@ -56,10 +54,6 @@ class Http {
|
|
|
56
54
|
const version = options.version;
|
|
57
55
|
let url = `${urlHost}/${version}/${path}`;
|
|
58
56
|
|
|
59
|
-
if (!versioned) {
|
|
60
|
-
url = `${urlHost}/${path}`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
57
|
// remove undefined values from request data
|
|
64
58
|
let body: any = {};
|
|
65
59
|
Object.keys(data || {}).forEach((key) => {
|
|
@@ -84,39 +78,32 @@ class Http {
|
|
|
84
78
|
const xhr = new XMLHttpRequest();
|
|
85
79
|
xhr.open(method, url, true);
|
|
86
80
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
// set standard headers
|
|
82
|
+
xhr.setRequestHeader('Authorization', publishableKey);
|
|
83
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
84
|
+
xhr.setRequestHeader('X-Radar-Device-Type', 'Web');
|
|
85
|
+
xhr.setRequestHeader('X-Radar-SDK-Version', SDK_VERSION);
|
|
86
|
+
|
|
87
|
+
// set passed custom headers if present
|
|
88
|
+
if (headers) {
|
|
89
|
+
Object.keys(headers).forEach(key => {
|
|
90
|
+
const val = headers[key];
|
|
91
|
+
xhr.setRequestHeader(key, val);
|
|
92
|
+
});
|
|
98
93
|
}
|
|
99
94
|
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (allHeaders['Content-Type'] === 'image/png') {
|
|
109
|
-
xhr.responseType = 'blob';
|
|
95
|
+
// set config custom headers if present
|
|
96
|
+
if (typeof options.getRequestHeaders === 'function') {
|
|
97
|
+
const headers: { [key: string]: string } = options.getRequestHeaders();
|
|
98
|
+
Object.keys(headers || {}).forEach((key) => {
|
|
99
|
+
xhr.setRequestHeader(key, headers[key]);
|
|
100
|
+
});
|
|
110
101
|
}
|
|
111
102
|
|
|
112
103
|
xhr.onload = () => {
|
|
113
104
|
let response: any;
|
|
114
105
|
try {
|
|
115
|
-
|
|
116
|
-
response = JSON.parse(xhr.response);
|
|
117
|
-
} else {
|
|
118
|
-
response = { code: xhr.status, data: xhr.response };
|
|
119
|
-
}
|
|
106
|
+
response = JSON.parse(xhr.response);
|
|
120
107
|
} catch (e) {
|
|
121
108
|
return reject(new RadarServerError(response));
|
|
122
109
|
}
|
package/src/types.ts
CHANGED
|
@@ -463,17 +463,12 @@ export interface RadarMapOptions extends maplibregl.MapOptions {
|
|
|
463
463
|
container: string | HTMLElement;
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
-
export interface
|
|
467
|
-
|
|
468
|
-
width?: number;
|
|
469
|
-
height?: number;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export interface RadarMarkerOptions extends maplibregl.MarkerOptions {
|
|
466
|
+
export interface RadarMarkerOptions {
|
|
467
|
+
color?: string;
|
|
473
468
|
text?: string;
|
|
474
469
|
html?: string;
|
|
475
|
-
|
|
476
|
-
|
|
470
|
+
element?: HTMLElement;
|
|
471
|
+
scale?: number;
|
|
477
472
|
}
|
|
478
473
|
|
|
479
474
|
export interface RadarAutocompleteUIOptions {
|
package/src/ui/map.ts
CHANGED
|
@@ -1,25 +1,157 @@
|
|
|
1
1
|
import maplibregl from 'maplibre-gl';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import Config from '../config';
|
|
4
|
+
import Logger from '../logger';
|
|
5
5
|
|
|
6
|
-
import type { RadarMapOptions, RadarMarkerOptions } from '../types';
|
|
6
|
+
import type { RadarOptions, RadarMapOptions, RadarMarkerOptions } from '../types';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_STYLE = 'radar-default-v1';
|
|
9
|
+
|
|
10
|
+
const RADAR_STYLES = [
|
|
11
|
+
'radar-default-v1',
|
|
12
|
+
'radar-light-v1',
|
|
13
|
+
'radar-dark-v1',
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const RADAR_LOGO_URL = 'https://api.radar.io/maps/static/images/logo.svg';
|
|
17
|
+
|
|
18
|
+
const defaultMaplibreOptions: Partial<maplibregl.MapOptions> = {
|
|
19
|
+
minZoom: 1,
|
|
20
|
+
maxZoom: 20,
|
|
21
|
+
attributionControl: false,
|
|
22
|
+
dragRotate: false,
|
|
23
|
+
touchPitch: false,
|
|
24
|
+
maplibreLogo: false,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const defaultMarkerOptions: Partial<maplibregl.MarkerOptions> = {
|
|
28
|
+
color: '#000257',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const createStyleURL = (options: RadarOptions, style: string = DEFAULT_STYLE) => (
|
|
32
|
+
`${options.host}/maps/styles/${style}?publishableKey=${options.publishableKey}`
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// use formatted style URL if using one of Radar's out-of-the-box styles
|
|
36
|
+
const getStyle = (options: RadarOptions, mapOptions: RadarMapOptions) => {
|
|
37
|
+
const style = mapOptions.style;
|
|
38
|
+
|
|
39
|
+
if (!style || (typeof style === 'string' && RADAR_STYLES.includes(style))) {
|
|
40
|
+
return createStyleURL(options, mapOptions.style as string);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return mapOptions.style;
|
|
44
|
+
};
|
|
7
45
|
|
|
8
46
|
class MapUI {
|
|
9
47
|
public static getMapLibre() {
|
|
10
48
|
return maplibregl;
|
|
11
49
|
}
|
|
12
50
|
|
|
13
|
-
public static createMap(mapOptions: RadarMapOptions):
|
|
14
|
-
const
|
|
51
|
+
public static createMap(mapOptions: RadarMapOptions): maplibregl.Map {
|
|
52
|
+
const options = Config.get();
|
|
53
|
+
|
|
54
|
+
if (!options.publishableKey) {
|
|
55
|
+
Logger.warn('publishableKey not set. Call Radar.initialize() with key before creating a new map.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// configure maplibre options
|
|
59
|
+
const style = getStyle(options, mapOptions);
|
|
60
|
+
const maplibreOptions: maplibregl.MapOptions = Object.assign({},
|
|
61
|
+
defaultMaplibreOptions,
|
|
62
|
+
mapOptions,
|
|
63
|
+
{ style },
|
|
64
|
+
);
|
|
65
|
+
Logger.debug(`initialize map with options: ${JSON.stringify(maplibreOptions)}`);
|
|
15
66
|
|
|
16
|
-
|
|
67
|
+
// set container
|
|
68
|
+
maplibreOptions.container = mapOptions.container;
|
|
69
|
+
|
|
70
|
+
// custom request handler for Radar styles
|
|
71
|
+
maplibreOptions.transformRequest = (url, resourceType) => {
|
|
72
|
+
if (resourceType === 'Style' && RADAR_STYLES.includes(url)) {
|
|
73
|
+
const radarStyleURL = createStyleURL(options, url);
|
|
74
|
+
return { url: radarStyleURL };
|
|
75
|
+
} else {
|
|
76
|
+
return { url };
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// create map
|
|
81
|
+
const map = new maplibregl.Map(maplibreOptions);
|
|
82
|
+
const container = map.getContainer();
|
|
83
|
+
|
|
84
|
+
if (!container.style.width && !container.style.height) {
|
|
85
|
+
Logger.warn('map container does not have a set "width" or "height"');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// add radar logo
|
|
89
|
+
const img = document.createElement('img');
|
|
90
|
+
img.src = RADAR_LOGO_URL;
|
|
91
|
+
|
|
92
|
+
const link = document.createElement('a');
|
|
93
|
+
link.id = 'radar-map-logo';
|
|
94
|
+
link.href = 'https://radar.com?ref=powered_by_radar';
|
|
95
|
+
link.target = '_blank';
|
|
96
|
+
link.style.position = 'absolute';
|
|
97
|
+
link.style.bottom = '0';
|
|
98
|
+
link.style.left = '5px';
|
|
99
|
+
link.style.width = '80px';
|
|
100
|
+
link.style.height = '38px';
|
|
101
|
+
link.appendChild(img)
|
|
102
|
+
map.getContainer().appendChild(link);
|
|
103
|
+
|
|
104
|
+
// add attribution
|
|
105
|
+
const attribution = new maplibregl.AttributionControl({ compact: false });
|
|
106
|
+
map.addControl(attribution, 'bottom-right');
|
|
107
|
+
|
|
108
|
+
// add zoom controls
|
|
109
|
+
const nav = new maplibregl.NavigationControl({ showCompass: false });
|
|
110
|
+
map.addControl(nav, 'bottom-right');
|
|
111
|
+
|
|
112
|
+
// handle map resize actions
|
|
113
|
+
const onResize = () => {
|
|
114
|
+
const attrib = document.querySelector('.maplibregl-ctrl-attrib');
|
|
115
|
+
if (attrib) {
|
|
116
|
+
const width = map.getContainer().clientWidth;
|
|
117
|
+
if (width < 380) {
|
|
118
|
+
attrib.classList.add('hidden');
|
|
119
|
+
} else {
|
|
120
|
+
attrib.classList.remove('hidden');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
map.on('resize', onResize);
|
|
125
|
+
map.on('load', onResize);
|
|
126
|
+
|
|
127
|
+
return map;
|
|
17
128
|
}
|
|
18
129
|
|
|
19
|
-
public static createMarker(markerOptions: RadarMarkerOptions = {}):
|
|
20
|
-
const
|
|
130
|
+
public static createMarker(markerOptions: RadarMarkerOptions = {}): maplibregl.Marker {
|
|
131
|
+
const maplibreOptions: maplibregl.MarkerOptions = Object.assign({}, defaultMarkerOptions);
|
|
132
|
+
|
|
133
|
+
if (markerOptions.color) {
|
|
134
|
+
maplibreOptions.color = markerOptions.color;
|
|
135
|
+
}
|
|
136
|
+
if (markerOptions.element) {
|
|
137
|
+
maplibreOptions.element = markerOptions.element;
|
|
138
|
+
}
|
|
139
|
+
if (markerOptions.scale) {
|
|
140
|
+
maplibreOptions.scale = markerOptions.scale;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const marker = new maplibregl.Marker(maplibreOptions);
|
|
144
|
+
|
|
145
|
+
// set popup text or HTML
|
|
146
|
+
if (markerOptions.text) {
|
|
147
|
+
const popup = new maplibregl.Popup({ offset: 35 }).setText(markerOptions.text);
|
|
148
|
+
marker.setPopup(popup);
|
|
149
|
+
} else if (markerOptions.html) {
|
|
150
|
+
const popup = new maplibregl.Popup({ offset: 35 }).setHTML(markerOptions.html);
|
|
151
|
+
marker.setPopup(popup);
|
|
152
|
+
}
|
|
21
153
|
|
|
22
|
-
return
|
|
154
|
+
return marker;
|
|
23
155
|
}
|
|
24
156
|
}
|
|
25
157
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.2.1-beta.
|
|
1
|
+
export default '4.2.1-beta.2';
|
package/dist/ui/RadarMap.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import maplibregl from 'maplibre-gl';
|
|
2
|
-
import RadarMarker from './RadarMarker';
|
|
3
|
-
import type { RadarMapOptions } from '../types';
|
|
4
|
-
declare class RadarMap extends maplibregl.Map {
|
|
5
|
-
_customMarkerRawSvg: string | undefined;
|
|
6
|
-
_markers: RadarMarker[];
|
|
7
|
-
constructor(mapOptions: RadarMapOptions);
|
|
8
|
-
getMarkers(): RadarMarker[];
|
|
9
|
-
}
|
|
10
|
-
export default RadarMap;
|
package/dist/ui/RadarMarker.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import maplibregl from 'maplibre-gl';
|
|
2
|
-
import type RadarMap from './RadarMap';
|
|
3
|
-
import type { RadarMarkerImage, RadarMarkerOptions } from '../types';
|
|
4
|
-
declare class RadarMarker extends maplibregl.Marker {
|
|
5
|
-
_map: RadarMap;
|
|
6
|
-
_image?: RadarMarkerImage;
|
|
7
|
-
_customMarkerId?: string;
|
|
8
|
-
constructor(markerOptions: RadarMarkerOptions);
|
|
9
|
-
addTo(map: RadarMap): this;
|
|
10
|
-
remove(): this;
|
|
11
|
-
getOptions(): RadarMarkerOptions;
|
|
12
|
-
}
|
|
13
|
-
export default RadarMarker;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const RADAR_LOGO_URL = 'https://api.radar.io/maps/static/images/logo.svg';
|
|
2
|
-
|
|
3
|
-
class RadarLogoControl {
|
|
4
|
-
link: HTMLAnchorElement | undefined;
|
|
5
|
-
|
|
6
|
-
onAdd() {
|
|
7
|
-
const img = document.createElement('img');
|
|
8
|
-
img.src = RADAR_LOGO_URL;
|
|
9
|
-
|
|
10
|
-
this.link = document.createElement('a');
|
|
11
|
-
this.link.id = 'radar-map-logo';
|
|
12
|
-
this.link.href = 'https://radar.com?ref=powered_by_radar';
|
|
13
|
-
this.link.target = '_blank';
|
|
14
|
-
this.link.appendChild(img);
|
|
15
|
-
|
|
16
|
-
return this.link;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
onRemove() {
|
|
20
|
-
this.link?.remove();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default RadarLogoControl;
|
package/src/ui/RadarMap.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import maplibregl from 'maplibre-gl';
|
|
2
|
-
|
|
3
|
-
import RadarMarker from './RadarMarker';
|
|
4
|
-
import RadarLogoControl from './RadarLogoControl';
|
|
5
|
-
|
|
6
|
-
import Config from '../config';
|
|
7
|
-
import Logger from '../logger';
|
|
8
|
-
|
|
9
|
-
import type { RadarOptions, RadarMapOptions } from '../types';
|
|
10
|
-
|
|
11
|
-
const DEFAULT_STYLE = 'radar-default-v1';
|
|
12
|
-
|
|
13
|
-
const RADAR_STYLES = [
|
|
14
|
-
'radar-default-v1',
|
|
15
|
-
'radar-light-v1',
|
|
16
|
-
'radar-dark-v1',
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const defaultMaplibreOptions: Partial<maplibregl.MapOptions> = {
|
|
20
|
-
minZoom: 1,
|
|
21
|
-
maxZoom: 20,
|
|
22
|
-
attributionControl: false,
|
|
23
|
-
dragRotate: false,
|
|
24
|
-
touchPitch: false,
|
|
25
|
-
maplibreLogo: false,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
|
29
|
-
|
|
30
|
-
const createStyleURL = (options: RadarOptions, style: string = DEFAULT_STYLE) => (
|
|
31
|
-
`${options.host}/maps/styles/${style}?publishableKey=${options.publishableKey}`
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
/** Check if style is a Radar style or a custom style */
|
|
35
|
-
const isRadarStyle = (style: string) => {
|
|
36
|
-
return RADAR_STYLES.includes(style) || uuidRegex.test(style)
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/** Use formatted style URL if using one of Radar's out-of-the-box styles or is a Radar custom style */
|
|
40
|
-
const getStyle = (options: RadarOptions, mapOptions: RadarMapOptions) => {
|
|
41
|
-
const style = mapOptions.style;
|
|
42
|
-
|
|
43
|
-
if (!style || (typeof style === 'string' && isRadarStyle(style))) {
|
|
44
|
-
return createStyleURL(options, style);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return mapOptions.style;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
class RadarMap extends maplibregl.Map {
|
|
51
|
-
_customMarkerRawSvg: string | undefined;
|
|
52
|
-
_markers: RadarMarker[] = [];
|
|
53
|
-
|
|
54
|
-
constructor(mapOptions: RadarMapOptions) {
|
|
55
|
-
const config = Config.get();
|
|
56
|
-
|
|
57
|
-
if (!config.publishableKey) {
|
|
58
|
-
Logger.warn('publishableKey not set. Call Radar.initialize() with key before creating a new map.');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// configure maplibre options
|
|
62
|
-
const style = getStyle(config, mapOptions);
|
|
63
|
-
const maplibreOptions: maplibregl.MapOptions = Object.assign({},
|
|
64
|
-
defaultMaplibreOptions,
|
|
65
|
-
mapOptions,
|
|
66
|
-
{ style },
|
|
67
|
-
);
|
|
68
|
-
Logger.debug(`initialize map with options: ${JSON.stringify(maplibreOptions)}`);
|
|
69
|
-
|
|
70
|
-
// custom request handler for Radar styles
|
|
71
|
-
maplibreOptions.transformRequest = (url, resourceType) => {
|
|
72
|
-
let radarStyleURL = url;
|
|
73
|
-
let headers = { 'Authorization': config.publishableKey };
|
|
74
|
-
if (resourceType === 'Style' && isRadarStyle(url)) {
|
|
75
|
-
radarStyleURL = createStyleURL(config, url);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (mapOptions.transformRequest) {
|
|
79
|
-
return mapOptions.transformRequest(radarStyleURL, resourceType);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (typeof config.getRequestHeaders === 'function') {
|
|
83
|
-
headers = Object.assign(headers, config.getRequestHeaders());
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return { url: radarStyleURL, headers };
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
super(maplibreOptions);
|
|
90
|
-
|
|
91
|
-
const container = this.getContainer();
|
|
92
|
-
|
|
93
|
-
if (!container.style.width && !container.style.height) {
|
|
94
|
-
Logger.warn('map container does not have a set "width" or "height"');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// add radar logo
|
|
98
|
-
const radarLogo = new RadarLogoControl();
|
|
99
|
-
this.addControl(radarLogo, 'bottom-left');
|
|
100
|
-
|
|
101
|
-
// add attribution
|
|
102
|
-
const attribution = new maplibregl.AttributionControl({ compact: false });
|
|
103
|
-
this.addControl(attribution, 'bottom-right');
|
|
104
|
-
|
|
105
|
-
// add zoom controls
|
|
106
|
-
const nav = new maplibregl.NavigationControl({ showCompass: false });
|
|
107
|
-
this.addControl(nav, 'bottom-right');
|
|
108
|
-
|
|
109
|
-
// handle map resize actions
|
|
110
|
-
const onResize = () => {
|
|
111
|
-
const attrib = document.querySelector('.maplibregl-ctrl-attrib');
|
|
112
|
-
if (attrib) {
|
|
113
|
-
const width = this.getContainer().clientWidth;
|
|
114
|
-
if (width < 380) {
|
|
115
|
-
attrib.classList.add('hidden');
|
|
116
|
-
} else {
|
|
117
|
-
attrib.classList.remove('hidden');
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
this.on('resize', onResize);
|
|
122
|
-
this.on('load', onResize);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getMarkers(): RadarMarker[] {
|
|
126
|
-
return this._markers;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export default RadarMap;
|