proximiio-js-library 1.7.2 → 1.8.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 CHANGED
@@ -125,15 +125,27 @@ const map = new Proximiio.Map({
125
125
  animatedRoute: false // optional, default: false, EXPERIMENTAL, if enabled animated dot will be displayed along the route,
126
126
  useRasterTiles: false, // optional, default: false, this will add raster tile source and layer with defined options from rasterTilesOptions
127
127
  rasterTilesOptions: {
128
- tilesUrl: string[], mandatory
129
- tileSize: number, optional, default: 256,
130
- minZoom: number, optional, default: 15,
131
- maxZoom: number, optional, default: 22,
132
- beforeLayer: string, optional, default: 'proximiio-shop',
133
- attribution: string, optional
128
+ tilesUrl: string[], // mandatory
129
+ tileSize: number, // optional, default: 256,
130
+ minZoom: number, // optional, default: 15,
131
+ maxZoom: number, // optional, default: 22,
132
+ beforeLayer: string, // optional, default: 'proximiio-shop',
133
+ attribution: string, // optional
134
134
  },
135
+ handleUrlParams: false, // optional, default: false, if enabled you can define place, start and destination features for routing in url params and library will handle those, you can change param names via urlParams option listed below
136
+ urlParams: {
137
+ startFeature: string, // optional, default: 'startFeature', library will search for the start feature by it's id or title defined within provided param
138
+ destinationFeature: string, // optional, default: 'destinationFeature', library will search for the destination feature by it's id or title defined within provided param
139
+ defaultPlace: string, // optional, default: 'defaultPlace', library will search for the place by it's id or title defined within provided param
140
+ }
141
+ useGpsLocation: false, // optional, default: false, if enabled your location will be detected with geolocation API and used as a starting point for routing
135
142
  });
136
143
  ```
144
+ #### Initiating with url params
145
+ Library can handle some params from url in case you will enable `handleUrlParams` in map constructor. There's nothing else special required, just provide them in browser url like this as default:
146
+
147
+ `http://your-server/?startFeature=featureIdOrTitle&destinationFeature=featureIdOrTitle&defaultPlace=placeIdOrTitle`
148
+
137
149
  #### Required Data for 3D Polygons
138
150
  As first there must be a MultiPolygon feature created which will be a polygon itself, it's also nice to have a label-line property in properties set. Label-line is just imaginary line alongside which poi title will be drawn. At last, you have to connect poi to polygon via adding its id to poi metadata like polygon_id property.
139
151
 
@@ -57,6 +57,13 @@ interface Options {
57
57
  beforeLayer?: string;
58
58
  attribution?: string;
59
59
  };
60
+ handleUrlParams?: boolean;
61
+ urlParams?: {
62
+ startFeauture?: string;
63
+ destinationFeature?: string;
64
+ defaultPlace?: string;
65
+ };
66
+ useGpsLocation?: boolean;
60
67
  }
61
68
  interface PaddingOptions {
62
69
  bottom: number;
@@ -105,6 +112,7 @@ export declare class Map {
105
112
  private onMapReady;
106
113
  private initKiosk;
107
114
  private onSetKiosk;
115
+ private initGeoLocation;
108
116
  private initDirectionIcon;
109
117
  private initAnimatedRoute;
110
118
  private initRasterTiles;
@@ -134,6 +134,13 @@ var Map = /** @class */ (function () {
134
134
  showRasterFloorplans: false,
135
135
  animatedRoute: false,
136
136
  useRasterTiles: false,
137
+ handleUrlParams: false,
138
+ urlParams: {
139
+ startFeauture: 'startFeature',
140
+ destinationFeature: 'destinationFeature',
141
+ defaultPlace: 'defaultPlace',
142
+ },
143
+ useGpsLocation: false,
137
144
  };
138
145
  this.showStartPoint = false;
139
146
  this.amenityIds = [];
@@ -155,8 +162,13 @@ var Map = /** @class */ (function () {
155
162
  if (options.isKiosk && options.mapboxOptions && options.kioskSettings && !options.mapboxOptions.center) {
156
163
  options.mapboxOptions.center = options.kioskSettings.coordinates;
157
164
  }
165
+ var urlParams = __assign(__assign({}, this.defaultOptions.urlParams), options.urlParams);
158
166
  this.defaultOptions = __assign(__assign({}, this.defaultOptions), options);
167
+ this.defaultOptions.urlParams = urlParams;
159
168
  this.state = exports.globalState;
169
+ if (this.defaultOptions.isKiosk && this.defaultOptions.useGpsLocation) {
170
+ throw new Error("It's not possible to use both isKiosk and useGpsLocation options as enabled!");
171
+ }
160
172
  this.onSourceChange = this.onSourceChange.bind(this);
161
173
  this.onSyntheticChange = this.onSyntheticChange.bind(this);
162
174
  this.onStyleChange = this.onStyleChange.bind(this);
@@ -195,23 +207,36 @@ var Map = /** @class */ (function () {
195
207
  Map.prototype.fetch = function () {
196
208
  var _a, _b, _c;
197
209
  return __awaiter(this, void 0, void 0, function () {
198
- var _d, places, style, styles, features, amenities, user, defaultPlace, place, center;
210
+ var placeParam, urlParams, _d, places, style, styles, features, amenities, user, defaultPlace, place, center;
199
211
  var _this = this;
200
212
  return __generator(this, function (_e) {
201
213
  switch (_e.label) {
202
- case 0: return [4 /*yield*/, repository_1.default.getPackage(this.defaultOptions.initPolygons)];
214
+ case 0:
215
+ placeParam = null;
216
+ if (this.defaultOptions.handleUrlParams) {
217
+ urlParams = new URLSearchParams(window.location.search);
218
+ placeParam = urlParams.get(this.defaultOptions.urlParams.defaultPlace);
219
+ }
220
+ return [4 /*yield*/, repository_1.default.getPackage(this.defaultOptions.initPolygons)];
203
221
  case 1:
204
222
  _d = _e.sent(), places = _d.places, style = _d.style, styles = _d.styles, features = _d.features, amenities = _d.amenities;
205
223
  return [4 /*yield*/, auth_1.default.getCurrentUser()];
206
224
  case 2:
207
225
  user = _e.sent();
208
- defaultPlace = places.find(function (p) { return p.id === _this.defaultOptions.defaultPlaceId; });
226
+ defaultPlace = placeParam
227
+ ? places.find(function (p) { return p.id === placeParam || p.name === placeParam; })
228
+ : places.find(function (p) { return p.id === _this.defaultOptions.defaultPlaceId; });
209
229
  place = places.length > 0 ? (defaultPlace ? defaultPlace : places[0]) : new place_1.PlaceModel({});
210
- center = ((_a = this.defaultOptions.mapboxOptions) === null || _a === void 0 ? void 0 : _a.center)
211
- ? this.defaultOptions.mapboxOptions.center
212
- : this.defaultOptions.isKiosk
213
- ? (_b = this.defaultOptions.kioskSettings) === null || _b === void 0 ? void 0 : _b.coordinates
214
- : [place.location.lng, place.location.lat];
230
+ center = [place.location.lng, place.location.lat];
231
+ if ((_a = this.defaultOptions.mapboxOptions) === null || _a === void 0 ? void 0 : _a.center) {
232
+ center = this.defaultOptions.mapboxOptions.center;
233
+ }
234
+ if (this.defaultOptions.isKiosk) {
235
+ center = (_b = this.defaultOptions.kioskSettings) === null || _b === void 0 ? void 0 : _b.coordinates;
236
+ }
237
+ if (placeParam) {
238
+ center = [place.location.lng, place.location.lat];
239
+ }
215
240
  style.center = center;
216
241
  this.defaultOptions.mapboxOptions.center = style.center;
217
242
  if (this.defaultOptions.zoomLevel) {
@@ -246,7 +271,7 @@ var Map = /** @class */ (function () {
246
271
  Map.prototype.onMapReady = function (e) {
247
272
  var _a, _b;
248
273
  return __awaiter(this, void 0, void 0, function () {
249
- var map, routingLayer, usePrefixed, shopsLayer, routingSymbolsLayer, decodedChevron, decodedPersonIcon, decodedFloorchangeUpImage, decodedFloorchangeDownImage;
274
+ var map, routingLayer, usePrefixed, shopsLayer, routingSymbolsLayer, decodedChevron, decodedPersonIcon, decodedFloorchangeUpImage, decodedFloorchangeDownImage, urlParams, startParam_1, destinationParam_1, startFeature, destinationFeature;
250
275
  var _this = this;
251
276
  return __generator(this, function (_c) {
252
277
  switch (_c.label) {
@@ -311,6 +336,9 @@ var Map = /** @class */ (function () {
311
336
  if (this.defaultOptions.isKiosk) {
312
337
  this.initKiosk();
313
338
  }
339
+ if (this.defaultOptions.useGpsLocation) {
340
+ this.initGeoLocation();
341
+ }
314
342
  if (this.defaultOptions.considerVisibilityParam) {
315
343
  this.handlePoiVisibility();
316
344
  }
@@ -323,6 +351,26 @@ var Map = /** @class */ (function () {
323
351
  if (this.defaultOptions.useRasterTiles) {
324
352
  this.initRasterTiles();
325
353
  }
354
+ if (this.defaultOptions.handleUrlParams) {
355
+ urlParams = new URLSearchParams(window.location.search);
356
+ startParam_1 = urlParams.get(this.defaultOptions.urlParams.startFeauture);
357
+ destinationParam_1 = urlParams.get(this.defaultOptions.urlParams.destinationFeature);
358
+ startFeature = startParam_1
359
+ ? this.state.allFeatures.features.find(function (f) {
360
+ return f.properties.title &&
361
+ (f.id === startParam_1 || f.properties.id === startParam_1 || f.properties.title === startParam_1);
362
+ })
363
+ : this.startPoint;
364
+ destinationFeature = this.state.allFeatures.features.find(function (f) {
365
+ return f.properties.title &&
366
+ (f.id === destinationParam_1 ||
367
+ f.properties.id === destinationParam_1 ||
368
+ f.properties.title === destinationParam_1);
369
+ });
370
+ if (startFeature && destinationFeature) {
371
+ this.onRouteUpdate(startFeature, destinationFeature);
372
+ }
373
+ }
326
374
  this.initPersonsMap();
327
375
  this.map.on('click', 'proximiio-pois-icons', function (ev) {
328
376
  _this.onShopClick(ev);
@@ -381,6 +429,27 @@ var Map = /** @class */ (function () {
381
429
  this.centerOnPoi(this.startPoint);
382
430
  }
383
431
  };
432
+ Map.prototype.initGeoLocation = function () {
433
+ var _this = this;
434
+ if (this.map && this.defaultOptions.useGpsLocation) {
435
+ var geolocate_1 = new mapboxgl.GeolocateControl({
436
+ positionOptions: {
437
+ enableHighAccuracy: true,
438
+ },
439
+ showAccuracyCircle: false,
440
+ trackUserLocation: true,
441
+ });
442
+ this.map.addControl(geolocate_1);
443
+ setTimeout(function () {
444
+ geolocate_1.trigger();
445
+ });
446
+ geolocate_1.on('geolocate', function (data) {
447
+ _this.startPoint = turf.point([data.coords.longitude, data.coords.latitude], {
448
+ level: _this.state.floor.level,
449
+ });
450
+ });
451
+ }
452
+ };
384
453
  Map.prototype.initDirectionIcon = function () {
385
454
  if (this.map) {
386
455
  this.state.style.addSource('direction-icon-source', {
@@ -1339,6 +1408,9 @@ var Map = /** @class */ (function () {
1339
1408
  map.setFilter('my-location-layer', filter);
1340
1409
  this.state.style.getLayer('my-location-layer').filter = filter;
1341
1410
  }
1411
+ if (this.defaultOptions.useGpsLocation && this.startPoint) {
1412
+ this.startPoint.properties = __assign(__assign({}, this.startPoint.properties), { level: floor.level });
1413
+ }
1342
1414
  if (map.getLayer('persons-layer')) {
1343
1415
  var filter = ['all', ['==', ['to-number', ['get', 'level']], floor.level]];
1344
1416
  map.setFilter('persons-layer', filter);
@@ -1735,7 +1807,7 @@ var Map = /** @class */ (function () {
1735
1807
  * });
1736
1808
  */
1737
1809
  Map.prototype.findRouteByIds = function (idTo, idFrom, accessibleRoute) {
1738
- var fromFeature = this.defaultOptions.isKiosk
1810
+ var fromFeature = this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1739
1811
  ? this.startPoint
1740
1812
  : this.state.allFeatures.features.find(function (f) { return f.id === idFrom || f.properties.id === idFrom; });
1741
1813
  var toFeature = this.state.allFeatures.features.find(function (f) { return f.id === idTo || f.properties.id === idTo; });
@@ -1757,12 +1829,14 @@ var Map = /** @class */ (function () {
1757
1829
  * });
1758
1830
  */
1759
1831
  Map.prototype.findRouteByTitle = function (titleTo, titleFrom, accessibleRoute) {
1760
- var fromFeature = this.defaultOptions.isKiosk
1832
+ var fromFeature = this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1761
1833
  ? this.startPoint
1762
1834
  : this.state.allFeatures.features.find(function (f) { return f.properties.title === titleFrom; });
1763
1835
  var toFeature = this.state.allFeatures.features.find(function (f) { return f.properties.title === titleTo; });
1764
1836
  this.routingSource.toggleAccessible(accessibleRoute);
1765
- this.onRouteUpdate(this.defaultOptions.isKiosk ? this.startPoint : fromFeature, toFeature);
1837
+ this.onRouteUpdate(this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1838
+ ? this.startPoint
1839
+ : fromFeature, toFeature);
1766
1840
  };
1767
1841
  /**
1768
1842
  * This method will generate route based on selected features by their titles
@@ -1783,12 +1857,14 @@ var Map = /** @class */ (function () {
1783
1857
  * });
1784
1858
  */
1785
1859
  Map.prototype.findRouteByCoords = function (latTo, lngTo, levelTo, latFrom, lngFrom, levelFrom, accessibleRoute) {
1786
- var fromFeature = this.defaultOptions.isKiosk
1860
+ var fromFeature = this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1787
1861
  ? this.startPoint
1788
1862
  : turf.feature({ type: 'Point', coordinates: [lngFrom, latFrom] }, { level: levelFrom });
1789
1863
  var toFeature = turf.feature({ type: 'Point', coordinates: [lngTo, latTo] }, { level: levelTo });
1790
1864
  this.routingSource.toggleAccessible(accessibleRoute);
1791
- this.onRouteUpdate(this.defaultOptions.isKiosk ? this.startPoint : fromFeature, toFeature);
1865
+ this.onRouteUpdate(this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1866
+ ? this.startPoint
1867
+ : fromFeature, toFeature);
1792
1868
  };
1793
1869
  /**
1794
1870
  * This method will generate route to nearest amenity feature
@@ -1805,13 +1881,15 @@ var Map = /** @class */ (function () {
1805
1881
  * });
1806
1882
  */
1807
1883
  Map.prototype.findRouteToNearestFeature = function (amenityId, idFrom, accessibleRoute) {
1808
- var fromFeature = this.defaultOptions.isKiosk
1884
+ var fromFeature = this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1809
1885
  ? this.startPoint
1810
1886
  : this.state.allFeatures.features.find(function (f) { return f.id === idFrom || f.properties.id === idFrom; });
1811
1887
  var toFeature = this.getClosestFeature(amenityId, fromFeature);
1812
1888
  if (toFeature) {
1813
1889
  this.routingSource.toggleAccessible(accessibleRoute);
1814
- this.onRouteUpdate(this.defaultOptions.isKiosk ? this.startPoint : fromFeature, toFeature);
1890
+ this.onRouteUpdate(this.startPoint && (this.defaultOptions.isKiosk || this.defaultOptions.useGpsLocation)
1891
+ ? this.startPoint
1892
+ : fromFeature, toFeature);
1815
1893
  }
1816
1894
  else {
1817
1895
  throw new Error("Feature not found");