radar-sdk-js 4.3.0-beta.1 → 4.3.0-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 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.3.0-beta.1/radar.min.js"></script>
59
+ <script src="https://js.radar.com/v4.3.0-beta.2/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.3.0-beta.1/radar.css" rel="stylesheet">
77
- <script src="https://js.radar.com/v4.3.0-beta.1/radar.min.js"></script>
76
+ <link href="https://js.radar.com/v4.3.0-beta.2/radar.css" rel="stylesheet">
77
+ <script src="https://js.radar.com/v4.3.0-beta.2/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.3.0-beta.1/radar.css" rel="stylesheet">
102
- <script src="https://js.radar.com/v4.3.0-beta.1/radar.min.js"></script>
101
+ <link href="https://js.radar.com/v4.3.0-beta.2/radar.css" rel="stylesheet">
102
+ <script src="https://js.radar.com/v4.3.0-beta.2/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.3.0-beta.1/radar.css" rel="stylesheet">
134
- <script src="https://js.radar.com/v4.3.0-beta.1/radar.min.js"></script>
133
+ <link href="https://js.radar.com/v4.3.0-beta.2/radar.css" rel="stylesheet">
134
+ <script src="https://js.radar.com/v4.3.0-beta.2/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.3.0-beta.1';
408
+ var SDK_VERSION = '4.3.0-beta.2';
409
409
 
410
410
  class Http {
411
411
  static request({ method, path, data, host, version, headers = {}, responseType, }) {
@@ -1445,109 +1445,26 @@ class RadarLogoControl {
1445
1445
  }
1446
1446
  }
1447
1447
 
1448
- //check if value is primitive
1449
- const isPrimitive = (obj) => {
1450
- return (obj !== Object(obj));
1451
- };
1452
- const deepEqual = (obj1, obj2) => {
1453
- if (obj1 === obj2) // it's just the same object. No need to compare.
1454
- return true;
1455
- if (isPrimitive(obj1) && isPrimitive(obj2)) // compare primitives
1456
- return obj1 === obj2;
1457
- if (Object.keys(obj1).length !== Object.keys(obj2).length)
1458
- return false;
1459
- // compare objects with same number of keys
1460
- for (let key in obj1) {
1461
- if (!(key in obj2))
1462
- return false; //other object doesn't have this prop
1463
- if (!deepEqual(obj1[key], obj2[key]))
1464
- return false;
1465
- }
1466
- return true;
1467
- };
1468
- const uniq = (arr) => {
1469
- const outputArray = arr.filter((v, i, self) => i === self.indexOf(v));
1470
- return outputArray;
1471
- };
1472
-
1473
- // NOTE(jasonl): ENSURE THIS STAYS IN SYNC WITH THE SERVER IMPLEMENTATION
1474
- const RADAR_LANGUAGE_EXPR = ['get', 'radar:name_client_language'];
1475
- /** get an array of languages set in the browser in RFC 5646 format */
1476
- const getBrowserLanguages = (options = { fallback: 'en', format: 'RFC-5646' }) => {
1477
- let languagesRFC5646 = [options.fallback];
1478
- if (navigator.languages.length > 0) {
1479
- languagesRFC5646 = [...navigator.languages];
1480
- }
1481
- else if (navigator.language) {
1482
- languagesRFC5646 = [navigator.language];
1483
- }
1484
- if (options.format === 'ISO-639-1') {
1485
- // RFC 5646 format is always prefixed by the ISO 639-1 language code so we need to strip that out
1486
- const languagesISO6391 = uniq(languagesRFC5646.map(l => l.split('-')[0]));
1487
- return languagesISO6391;
1488
- }
1489
- return languagesRFC5646;
1490
- };
1491
- const replaceAllValuesInExpression = (expr, target, value) => {
1492
- if (target.length !== value.length) {
1493
- Logger.warn('replaceAllValueInExpression: Target and value arrays must be the same length');
1494
- return expr;
1495
- }
1496
- const findIndex = target.findIndex((t) => deepEqual(t, expr));
1497
- if (findIndex !== -1) {
1498
- return value[findIndex];
1499
- }
1500
- if (Array.isArray(expr)) {
1501
- return expr.map((e) => replaceAllValuesInExpression(e, target, value));
1502
- }
1503
- return expr;
1504
- };
1505
- const transformMapStyle = (styleJSON, options) => {
1506
- var _a;
1507
- let languages = [];
1508
- // use browser language if style language is set to local
1509
- if (((_a = styleJSON === null || styleJSON === void 0 ? void 0 : styleJSON.metadata) === null || _a === void 0 ? void 0 : _a['radar:language']) === 'local') {
1510
- const fallbackLanguage = options.navigatorFallbackLanguage || 'en';
1511
- languages = getBrowserLanguages({ fallback: fallbackLanguage, format: 'ISO-639-1' });
1512
- }
1513
- // client set language takes precedence
1514
- if (options.languages) {
1515
- languages = options.languages;
1516
- }
1517
- if (languages.length > 0) {
1518
- // construct expression ordered by language preference
1519
- const localLanguageExpression = ['coalesce'];
1520
- languages.forEach((l) => {
1521
- localLanguageExpression.push(['get', `name_${l}`], ['get', `name:${l}`]);
1522
- });
1523
- const transformedLayers = styleJSON.layers.map((layer) => {
1524
- if (layer.type === 'symbol' && layer.layout['text-field']) {
1525
- layer.layout['text-field'] = replaceAllValuesInExpression(layer.layout['text-field'], [RADAR_LANGUAGE_EXPR], [localLanguageExpression]);
1526
- return layer;
1527
- }
1528
- return layer;
1529
- });
1530
- return Object.assign(Object.assign({}, styleJSON), { layers: transformedLayers });
1531
- }
1532
- return styleJSON;
1533
- };
1534
-
1535
- const DEFAULT_STYLE = 'radar-default-v1';
1536
1448
  const RADAR_STYLES = [
1537
1449
  'radar-default-v1',
1538
1450
  'radar-light-v1',
1539
1451
  'radar-dark-v1',
1540
1452
  ];
1541
- const defaultMapOptions = {
1453
+ const defaultMaplibreOptions = {
1542
1454
  minZoom: 1,
1543
1455
  maxZoom: 20,
1544
1456
  attributionControl: false,
1545
1457
  dragRotate: false,
1546
1458
  touchPitch: false,
1547
1459
  maplibreLogo: false,
1548
- navigatorFallbackLanguage: 'en',
1549
1460
  };
1550
- const createStyleURL = (options, style = DEFAULT_STYLE) => (`${options.host}/maps/styles/${style}?publishableKey=${options.publishableKey}`);
1461
+ const createStyleURL = (options, mapOptions) => {
1462
+ let url = `${options.host}/maps/styles/${mapOptions.style}?publishableKey=${options.publishableKey}`;
1463
+ if (mapOptions.locale) {
1464
+ url += `&locale=${mapOptions.locale}`;
1465
+ }
1466
+ return url;
1467
+ };
1551
1468
  // check if style is a Radar style or a custom style
1552
1469
  const isRadarStyle = (style) => {
1553
1470
  if (RADAR_STYLES.includes(style)) { // Radar built-in style
@@ -1562,7 +1479,7 @@ const isRadarStyle = (style) => {
1562
1479
  const getStyle = (options, mapOptions) => {
1563
1480
  const style = mapOptions.style;
1564
1481
  if (!style || (typeof style === 'string' && isRadarStyle(style))) {
1565
- return createStyleURL(options, style);
1482
+ return createStyleURL(options, mapOptions);
1566
1483
  }
1567
1484
  return mapOptions.style; // style object or URL
1568
1485
  };
@@ -1574,12 +1491,9 @@ class RadarMap extends maplibregl.Map {
1574
1491
  }
1575
1492
  // configure maplibre options
1576
1493
  const style = getStyle(config, mapOptions);
1577
- const maplibreOptions = Object.assign({}, defaultMapOptions, mapOptions, { style });
1494
+ const maplibreOptions = Object.assign({}, defaultMaplibreOptions, mapOptions, { style });
1578
1495
  Logger.debug(`initialize map with options: ${JSON.stringify(maplibreOptions)}`);
1579
- maplibreOptions.transformRequest = (url, resourceType) => {
1580
- if (resourceType === 'Style' && isRadarStyle(url)) {
1581
- url = createStyleURL(config, url);
1582
- }
1496
+ maplibreOptions.transformRequest = (url) => {
1583
1497
  let headers = {
1584
1498
  'Authorization': config.publishableKey,
1585
1499
  'X-Radar-Device-Type': 'Web',
@@ -1618,20 +1532,8 @@ class RadarMap extends maplibregl.Map {
1618
1532
  }
1619
1533
  }
1620
1534
  };
1621
- const onStyleLoad = (e) => {
1622
- var _a;
1623
- const styleJSON = (_a = e.style) === null || _a === void 0 ? void 0 : _a.stylesheet; // for some reason, style does not exist in the types
1624
- if (!styleJSON) {
1625
- Logger.warn('style data not available');
1626
- return;
1627
- }
1628
- // transform text-field expressions to use local language
1629
- const newStyleJSON = transformMapStyle(styleJSON, maplibreOptions);
1630
- this.setStyle(newStyleJSON);
1631
- };
1632
1535
  this.on('resize', onResize);
1633
1536
  this.on('load', onResize);
1634
- this.on('styledata', onStyleLoad);
1635
1537
  }
1636
1538
  addMarker(marker) {
1637
1539
  this._markers.push(marker);
package/dist/radar.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/types.d.ts CHANGED
@@ -345,8 +345,7 @@ export interface RadarSearchGeofencesResponse extends RadarResponse {
345
345
  geofences: RadarGeofence[];
346
346
  }
347
347
  export interface RadarMapOptions extends Omit<maplibregl.MapOptions, 'transformRequest'> {
348
- languages?: string[];
349
- navigatorFallbackLanguage?: string;
348
+ locale?: string;
350
349
  }
351
350
  export interface RadarMarkerImage {
352
351
  url?: string;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "4.3.0-beta.1";
1
+ declare const _default: "4.3.0-beta.2";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radar-sdk-js",
3
- "version": "4.3.0-beta.1",
3
+ "version": "4.3.0-beta.2",
4
4
  "description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.",
5
5
  "homepage": "https://radar.com",
6
6
  "type": "module",
package/src/types.ts CHANGED
@@ -460,8 +460,7 @@ export interface RadarSearchGeofencesResponse extends RadarResponse {
460
460
  }
461
461
 
462
462
  export interface RadarMapOptions extends Omit<maplibregl.MapOptions, 'transformRequest'> {
463
- languages?: string[];
464
- navigatorFallbackLanguage?: string;
463
+ locale?: string;
465
464
  }
466
465
 
467
466
  export interface RadarMarkerImage {
@@ -1,13 +1,11 @@
1
1
  import maplibregl from 'maplibre-gl';
2
2
 
3
+ import SDK_VERSION from '../version';
3
4
  import RadarMarker from './RadarMarker';
4
5
  import RadarLogoControl from './RadarLogoControl';
5
6
 
6
7
  import Config from '../config';
7
8
  import Logger from '../logger';
8
- import SDK_VERSION from '../version';
9
-
10
- import { transformMapStyle } from '../util/mapStyle';
11
9
 
12
10
  import type { RadarOptions, RadarMapOptions } from '../types';
13
11
 
@@ -19,19 +17,22 @@ const RADAR_STYLES = [
19
17
  'radar-dark-v1',
20
18
  ];
21
19
 
22
- const defaultMapOptions: Partial<RadarMapOptions> = {
20
+ const defaultMaplibreOptions: Partial<maplibregl.MapOptions> = {
23
21
  minZoom: 1,
24
22
  maxZoom: 20,
25
23
  attributionControl: false,
26
24
  dragRotate: false,
27
25
  touchPitch: false,
28
26
  maplibreLogo: false,
29
- navigatorFallbackLanguage: 'en',
30
27
  };
31
28
 
32
- const createStyleURL = (options: RadarOptions, style: string = DEFAULT_STYLE) => (
33
- `${options.host}/maps/styles/${style}?publishableKey=${options.publishableKey}`
34
- );
29
+ const createStyleURL = (options: RadarOptions, mapOptions: RadarMapOptions) => {
30
+ let url = `${options.host}/maps/styles/${mapOptions.style}?publishableKey=${options.publishableKey}`
31
+ if (mapOptions.locale) {
32
+ url += `&locale=${mapOptions.locale}`
33
+ }
34
+ return url
35
+ };
35
36
 
36
37
  // check if style is a Radar style or a custom style
37
38
  const isRadarStyle = (style: string) => {
@@ -49,7 +50,7 @@ const getStyle = (options: RadarOptions, mapOptions: RadarMapOptions) => {
49
50
  const style = mapOptions.style;
50
51
 
51
52
  if (!style || (typeof style === 'string' && isRadarStyle(style))) {
52
- return createStyleURL(options, style);
53
+ return createStyleURL(options, mapOptions);
53
54
  }
54
55
 
55
56
  return mapOptions.style; // style object or URL
@@ -68,16 +69,13 @@ class RadarMap extends maplibregl.Map {
68
69
  // configure maplibre options
69
70
  const style = getStyle(config, mapOptions);
70
71
  const maplibreOptions: RadarMapOptions = Object.assign({},
71
- defaultMapOptions,
72
+ defaultMaplibreOptions,
72
73
  mapOptions,
73
74
  { style },
74
75
  );
75
76
  Logger.debug(`initialize map with options: ${JSON.stringify(maplibreOptions)}`);
76
77
 
77
- (maplibreOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => {
78
- if (resourceType === 'Style' && isRadarStyle(url)) {
79
- url = createStyleURL(config, url);
80
- }
78
+ (maplibreOptions as maplibregl.MapOptions).transformRequest = (url) => {
81
79
 
82
80
  let headers = {
83
81
  'Authorization': config.publishableKey,
@@ -122,21 +120,8 @@ class RadarMap extends maplibregl.Map {
122
120
  }
123
121
  }
124
122
  };
125
-
126
- const onStyleLoad = (e: maplibregl.MapStyleDataEvent) => {
127
- const styleJSON = (e as any).style?.stylesheet; // for some reason, style does not exist in the types
128
- if (!styleJSON) {
129
- Logger.warn('style data not available');
130
- return;
131
- }
132
-
133
- // transform text-field expressions to use local language
134
- const newStyleJSON = transformMapStyle(styleJSON, maplibreOptions);
135
- this.setStyle(newStyleJSON);
136
- };
137
123
  this.on('resize', onResize);
138
124
  this.on('load', onResize);
139
- this.on('styledata', onStyleLoad);
140
125
  }
141
126
 
142
127
  addMarker(marker: RadarMarker) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '4.3.0-beta.1';
1
+ export default '4.3.0-beta.2';
package/dist/util/_.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const deepEqual: (obj1: any, obj2: any) => boolean;
2
- export declare const uniq: <T extends unknown>(arr: T[]) => T[];
@@ -1,2 +0,0 @@
1
- import { RadarMapOptions } from '../types';
2
- export declare const transformMapStyle: (styleJSON: any, options: Pick<RadarMapOptions, 'languages' | 'navigatorFallbackLanguage'>) => any;
package/src/util/_.ts DELETED
@@ -1,30 +0,0 @@
1
- //check if value is primitive
2
- const isPrimitive = (obj: any) => {
3
- return (obj !== Object(obj));
4
- }
5
-
6
- export const deepEqual = (obj1: any, obj2: any) => {
7
-
8
- if (obj1 === obj2) // it's just the same object. No need to compare.
9
- return true;
10
-
11
- if (isPrimitive(obj1) && isPrimitive(obj2)) // compare primitives
12
- return obj1 === obj2;
13
-
14
- if (Object.keys(obj1).length !== Object.keys(obj2).length)
15
- return false;
16
-
17
- // compare objects with same number of keys
18
- for (let key in obj1) {
19
- if (!(key in obj2)) return false; //other object doesn't have this prop
20
- if (!deepEqual(obj1[key], obj2[key])) return false;
21
- }
22
-
23
- return true;
24
- }
25
-
26
- export const uniq = <T extends any>(arr: T[]): T[] => {
27
- const outputArray: T[] = arr.filter((v, i, self) => i === self.indexOf(v));
28
-
29
- return outputArray;
30
- }
@@ -1,85 +0,0 @@
1
- import * as _ from './_';
2
-
3
- import Logger from '../logger';
4
-
5
- import { RadarMapOptions } from '../types';
6
-
7
- // NOTE(jasonl): ENSURE THIS STAYS IN SYNC WITH THE SERVER IMPLEMENTATION
8
- const RADAR_LANGUAGE_EXPR = ['get', 'radar:name_client_language'];
9
-
10
- /** get an array of languages set in the browser in RFC 5646 format */
11
- const getBrowserLanguages = (options = { fallback: 'en', format: 'RFC-5646' }) => {
12
- let languagesRFC5646 = [options.fallback];
13
- if (navigator.languages.length > 0) {
14
- languagesRFC5646 = [...navigator.languages];
15
- } else if (navigator.language) {
16
- languagesRFC5646 = [navigator.language];
17
- }
18
-
19
- if (options.format === 'ISO-639-1') {
20
- // RFC 5646 format is always prefixed by the ISO 639-1 language code so we need to strip that out
21
- const languagesISO6391 = _.uniq(languagesRFC5646.map(l => l.split('-')[0]));
22
- return languagesISO6391;
23
- }
24
-
25
- return languagesRFC5646;
26
- };
27
-
28
- const replaceAllValuesInExpression = (expr: any, target: any[], value: any[]): any => {
29
- if (target.length !== value.length) {
30
- Logger.warn('replaceAllValueInExpression: Target and value arrays must be the same length');
31
- return expr;
32
- }
33
-
34
- const findIndex = target.findIndex((t) => _.deepEqual(t, expr));
35
- if (findIndex !== -1) {
36
- return value[findIndex];
37
- }
38
-
39
- if (Array.isArray(expr)) {
40
- return expr.map((e) => replaceAllValuesInExpression(e, target, value));
41
- }
42
-
43
- return expr;
44
- };
45
-
46
- export const transformMapStyle = (styleJSON: any, options: Pick<RadarMapOptions, 'languages' | 'navigatorFallbackLanguage'>): any => {
47
- let languages: string[] = [];
48
-
49
- // use browser language if style language is set to local
50
- if (styleJSON?.metadata?.['radar:language'] === 'local') {
51
- const fallbackLanguage = options.navigatorFallbackLanguage || 'en';
52
- languages = getBrowserLanguages({ fallback: fallbackLanguage, format: 'ISO-639-1' });
53
- }
54
-
55
- // client set language takes precedence
56
- if (options.languages) {
57
- languages = options.languages;
58
- }
59
-
60
- if (languages.length > 0) {
61
- // construct expression ordered by language preference
62
- const localLanguageExpression: any[] = ['coalesce'];
63
- languages.forEach((l: any) => {
64
- localLanguageExpression.push(['get', `name_${l}`], ['get', `name:${l}`]);
65
- });
66
-
67
- const transformedLayers = styleJSON.layers.map((layer: any) => {
68
- if (layer.type === 'symbol' && layer.layout['text-field']) {
69
- layer.layout['text-field'] = replaceAllValuesInExpression(
70
- layer.layout['text-field'],
71
- [RADAR_LANGUAGE_EXPR],
72
- [localLanguageExpression]
73
- );
74
-
75
- return layer;
76
- }
77
-
78
- return layer;
79
- });
80
-
81
- return { ...styleJSON, layers: transformedLayers };
82
- }
83
-
84
- return styleJSON;
85
- };