proximiio-js-library 1.9.39 → 1.9.41

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
@@ -187,6 +187,10 @@ const map = new Proximiio.Map({
187
187
  hiddenAmenities: string[], // you can define array of amenity id's to hide poi labels and icons while polygons remains functional
188
188
  useTimerangeData: false, // if set to true only features inside defined time range in metadata.dateStart and metadata.dateEnd will be shown, default: false
189
189
  sendAnalytics: true, // if enabled we automatically send analytics from routing to our API, default: true
190
+ defaultFilter?: {
191
+ key: string; // if defaultFilter is defined it will look for this key in feature object
192
+ value: string; // if the previous key exists in the feature object, it's value will be compared to this value and filtering will be processed in a way that only features with same value or features with missing property will be visible
193
+ };
190
194
  });
191
195
  ```
192
196
 
@@ -642,6 +646,20 @@ map.getMapReadyListener().subscribe(ready => {
642
646
 
643
647
  ##### Map Features Filtering
644
648
 
649
+ ###### Setting new global filter
650
+
651
+ With this method you can filter features with any of it's properties, if the property key doesn't exists in the feature properties or it's value is the same as defined in options they will pass the filtering and will be visible on map.
652
+
653
+ ```
654
+ // param options { key: string; value: string } | null, define property key and value to filter features, optional, if null filtering will be disabled.
655
+
656
+ const map = new Proximiio.Map();
657
+ map.getMapReadyListener().subscribe(ready => {
658
+ console.log('map ready', ready);
659
+ map.setFiltering({ key: 'properties.metadata.exhibition', value: 'food'});
660
+ });
661
+ ```
662
+
645
663
  ###### Setting new feature filter
646
664
 
647
665
  With this method you set only defined poi feature to be visible, calling this method multiple times will set another feature to be visible without hiding the previous one, with inverted set to true defined feature will hide instead.
package/lib/common.d.ts CHANGED
@@ -5,3 +5,4 @@ export declare const kebabize: (data: any) => any;
5
5
  export declare const getImageFromBase64: (encoded: string) => Promise<HTMLImageElement>;
6
6
  export declare const getBase64FromImage: (file: File) => Promise<string>;
7
7
  export declare const uuidv4: () => any;
8
+ export declare const getNestedObjectValue: (nestedObject: any, dynamicKey: any) => any;
package/lib/common.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuidv4 = exports.getBase64FromImage = exports.getImageFromBase64 = exports.kebabize = exports.kebabToCamel = exports.camelToKebab = exports.axios = void 0;
3
+ exports.getNestedObjectValue = exports.uuidv4 = exports.getBase64FromImage = exports.getImageFromBase64 = exports.kebabize = exports.kebabToCamel = exports.camelToKebab = exports.axios = void 0;
4
4
  var axios_1 = require("axios");
5
5
  exports.axios = axios_1.default.create({
6
6
  baseURL: 'https://api.proximi.fi',
@@ -47,3 +47,25 @@ var uuidv4 = function () {
47
47
  });
48
48
  };
49
49
  exports.uuidv4 = uuidv4;
50
+ var getNestedObjectValue = function (nestedObject, dynamicKey) {
51
+ // If the dynamic key is empty, return undefined.
52
+ if (dynamicKey === '') {
53
+ return undefined;
54
+ }
55
+ // Split the dynamic key into two parts: the first key and the remaining keys.
56
+ var firstKey = dynamicKey.split('.')[0];
57
+ var remainingKeys = dynamicKey.slice(firstKey.length + 1);
58
+ // Get the value of the first key in the nested object.
59
+ var value = nestedObject[firstKey];
60
+ // If the value is undefined, return undefined.
61
+ if (value === undefined) {
62
+ return undefined;
63
+ }
64
+ // If the remaining keys are empty, return the value.
65
+ if (remainingKeys === '') {
66
+ return value;
67
+ }
68
+ // Get the value of the remaining keys in the nested object.
69
+ return exports.getNestedObjectValue(value, remainingKeys);
70
+ };
71
+ exports.getNestedObjectValue = getNestedObjectValue;
@@ -7,7 +7,7 @@ import { AmenityModel } from '../../models/amenity';
7
7
  import { MapboxOptions } from '../../models/mapbox-options';
8
8
  import PersonModel from '../../models/person';
9
9
  import { WayfindingConfigModel } from '../../models/wayfinding';
10
- interface State {
10
+ export interface State {
11
11
  readonly initializing: boolean;
12
12
  readonly floor: FloorModel;
13
13
  readonly floors: FloorModel[];
@@ -28,7 +28,7 @@ interface State {
28
28
  readonly persons: PersonModel[];
29
29
  readonly user: any;
30
30
  }
31
- interface Options {
31
+ export interface Options {
32
32
  selector?: string;
33
33
  allowNewFeatureModal?: boolean;
34
34
  newFeatureModalEvent?: string;
@@ -99,8 +99,12 @@ interface Options {
99
99
  hiddenAmenities?: string[];
100
100
  useTimerangeData?: boolean;
101
101
  sendAnalytics?: boolean;
102
+ defaultFilter?: {
103
+ key: string;
104
+ value: string;
105
+ };
102
106
  }
103
- interface PaddingOptions {
107
+ export interface PaddingOptions {
104
108
  bottom: number;
105
109
  left: number;
106
110
  right: number;
@@ -222,6 +226,15 @@ export declare class Map {
222
226
  * map.getMapboxInstance();
223
227
  */
224
228
  getMapboxInstance(): maplibregl.Map;
229
+ /**
230
+ * @memberof Map
231
+ * @name getMapState
232
+ * @returns returns map state
233
+ * @example
234
+ * const map = new Proximiio.Map();
235
+ * map.getMapState();
236
+ */
237
+ getMapState(): any;
225
238
  /**
226
239
  * @memberof Map
227
240
  * @name getMapReadyListener
@@ -662,6 +675,22 @@ export declare class Map {
662
675
  * });
663
676
  */
664
677
  setBoundsPadding(padding: number | PaddingOptions): void;
678
+ /**
679
+ * With this method you can filter features with any of it's properties, if the property key doesn't exists in the feature properties or it's value is the same as defined in options they will pass the filtering and will be visible on map.
680
+ * @memberof Map
681
+ * @name setFiltering
682
+ * @param options { key: string; value: string } | null, define property key and value to filter features, optional, if null filtering will be disabled.
683
+ * @example
684
+ * const map = new Proximiio.Map();
685
+ * map.getMapReadyListener().subscribe(ready => {
686
+ * console.log('map ready', ready);
687
+ * map.setFiltering({ key: 'properties.metadata.exhibition', value: 'food'});
688
+ * });
689
+ */
690
+ setFiltering(options: {
691
+ key: string;
692
+ value: string;
693
+ } | null): void;
665
694
  /**
666
695
  * With this method you can show only defined features, you can send both id or title, with inverted set to true defined feature will hide instead.
667
696
  * @memberof Map
@@ -917,4 +946,3 @@ export declare class Map {
917
946
  */
918
947
  refetch(): void;
919
948
  }
920
- export {};
@@ -285,6 +285,7 @@ var Map = /** @class */ (function () {
285
285
  amenityIdProperty: this.defaultOptions.amenityIdProperty,
286
286
  hiddenAmenities: this.defaultOptions.hiddenAmenities,
287
287
  useTimerangeData: this.defaultOptions.useTimerangeData,
288
+ filter: this.defaultOptions.defaultFilter,
288
289
  })];
289
290
  case 1:
290
291
  _d = _e.sent(), places = _d.places, style = _d.style, styles = _d.styles, features = _d.features, amenities = _d.amenities;
@@ -499,6 +500,7 @@ var Map = /** @class */ (function () {
499
500
  amenityIdProperty: this.defaultOptions.amenityIdProperty,
500
501
  hiddenAmenities: this.defaultOptions.hiddenAmenities,
501
502
  useTimerangeData: this.defaultOptions.useTimerangeData,
503
+ filter: this.defaultOptions.defaultFilter,
502
504
  })];
503
505
  case 1:
504
506
  features = (_a.sent()).features;
@@ -2185,6 +2187,17 @@ var Map = /** @class */ (function () {
2185
2187
  Map.prototype.getMapboxInstance = function () {
2186
2188
  return this.map;
2187
2189
  };
2190
+ /**
2191
+ * @memberof Map
2192
+ * @name getMapState
2193
+ * @returns returns map state
2194
+ * @example
2195
+ * const map = new Proximiio.Map();
2196
+ * map.getMapState();
2197
+ */
2198
+ Map.prototype.getMapState = function () {
2199
+ return this.state;
2200
+ };
2188
2201
  /**
2189
2202
  * @memberof Map
2190
2203
  * @name getMapReadyListener
@@ -2821,6 +2834,27 @@ var Map = /** @class */ (function () {
2821
2834
  Map.prototype.setBoundsPadding = function (padding) {
2822
2835
  this.defaultOptions.fitBoundsPadding = padding;
2823
2836
  };
2837
+ /**
2838
+ * With this method you can filter features with any of it's properties, if the property key doesn't exists in the feature properties or it's value is the same as defined in options they will pass the filtering and will be visible on map.
2839
+ * @memberof Map
2840
+ * @name setFiltering
2841
+ * @param options { key: string; value: string } | null, define property key and value to filter features, optional, if null filtering will be disabled.
2842
+ * @example
2843
+ * const map = new Proximiio.Map();
2844
+ * map.getMapReadyListener().subscribe(ready => {
2845
+ * console.log('map ready', ready);
2846
+ * map.setFiltering({ key: 'properties.metadata.exhibition', value: 'food'});
2847
+ * });
2848
+ */
2849
+ Map.prototype.setFiltering = function (options) {
2850
+ if (options) {
2851
+ this.defaultOptions.defaultFilter = options;
2852
+ }
2853
+ else {
2854
+ delete this.defaultOptions.defaultFilter;
2855
+ }
2856
+ this.onRefetch();
2857
+ };
2824
2858
  /**
2825
2859
  * With this method you can show only defined features, you can send both id or title, with inverted set to true defined feature will hide instead.
2826
2860
  * @memberof Map
@@ -1,10 +1,14 @@
1
1
  import Feature, { FeatureCollection } from '../models/feature';
2
2
  import { FeatureCollection as FCModel, Feature as FModel } from '@turf/helpers';
3
- export declare const getFeatures: ({ initPolygons, autoLabelLines, hiddenAmenities, useTimerangeData, }: {
3
+ export declare const getFeatures: ({ initPolygons, autoLabelLines, hiddenAmenities, useTimerangeData, filter, }: {
4
4
  initPolygons?: boolean;
5
5
  autoLabelLines?: boolean;
6
6
  hiddenAmenities?: string[];
7
7
  useTimerangeData?: boolean;
8
+ filter?: {
9
+ key: string;
10
+ value: string;
11
+ };
8
12
  }) => Promise<FeatureCollection>;
9
13
  export declare const getAmenities: (amenityIdProperty?: string) => Promise<any>;
10
14
  export declare const getPois: () => Promise<Feature[]>;
@@ -12,11 +16,15 @@ export declare const addFeatures: (featureCollection: FCModel) => Promise<void>;
12
16
  export declare const updateFeature: (featureData: FModel, featureId: string) => Promise<void>;
13
17
  export declare const deleteFeatures: (featureCollection: FCModel) => Promise<void>;
14
18
  declare const _default: {
15
- getFeatures: ({ initPolygons, autoLabelLines, hiddenAmenities, useTimerangeData, }: {
19
+ getFeatures: ({ initPolygons, autoLabelLines, hiddenAmenities, useTimerangeData, filter, }: {
16
20
  initPolygons?: boolean;
17
21
  autoLabelLines?: boolean;
18
22
  hiddenAmenities?: string[];
19
23
  useTimerangeData?: boolean;
24
+ filter?: {
25
+ key: string;
26
+ value: string;
27
+ };
20
28
  }) => Promise<FeatureCollection>;
21
29
  addFeatures: (featureCollection: FCModel<import("@turf/helpers").Geometry | import("@turf/helpers").GeometryCollection, {
22
30
  [name: string]: any;
@@ -59,7 +59,7 @@ var amenity_1 = require("../models/amenity");
59
59
  var main_1 = require("../components/map/main");
60
60
  var turf_1 = require("@turf/turf");
61
61
  var getFeatures = function (_a) {
62
- var initPolygons = _a.initPolygons, autoLabelLines = _a.autoLabelLines, hiddenAmenities = _a.hiddenAmenities, useTimerangeData = _a.useTimerangeData;
62
+ var initPolygons = _a.initPolygons, autoLabelLines = _a.autoLabelLines, hiddenAmenities = _a.hiddenAmenities, useTimerangeData = _a.useTimerangeData, filter = _a.filter;
63
63
  return __awaiter(void 0, void 0, void 0, function () {
64
64
  var url, res, featuresToAdd_1, shopPolygons_1, labelLineFeatures_1;
65
65
  return __generator(this, function (_b) {
@@ -76,16 +76,42 @@ var getFeatures = function (_a) {
76
76
  if (useTimerangeData) {
77
77
  res.data.features = res.data.features
78
78
  .map(function (feature) {
79
- if (feature.properties && feature.properties.type === 'poi') {
80
- if (feature.properties.metadata &&
81
- feature.properties.metadata.dateStart &&
82
- feature.properties.metadata.dateEnd &&
83
- feature.properties.metadata.dateStart <= Date.now() &&
79
+ var _a, _b;
80
+ if (feature.properties && ((_a = feature.properties.metadata) === null || _a === void 0 ? void 0 : _a.dateStart) && ((_b = feature.properties.metadata) === null || _b === void 0 ? void 0 : _b.dateEnd)) {
81
+ // if feature have dateStart and dateEnd check the range and filter
82
+ if (feature.properties.metadata.dateStart <= Date.now() &&
84
83
  feature.properties.metadata.dateEnd >= Date.now()) {
84
+ // if feature is in range return feature
85
85
  return feature;
86
86
  }
87
+ else {
88
+ // if feature is outside of range return undefined
89
+ return undefined;
90
+ }
91
+ }
92
+ else {
93
+ // if feature dont have dateStart and dateEnd return feature
94
+ return feature;
95
+ }
96
+ })
97
+ .filter(function (feature) { return feature !== undefined; });
98
+ }
99
+ if (filter && filter.key && filter.value) {
100
+ res.data.features = res.data.features
101
+ .map(function (feature) {
102
+ if (common_1.getNestedObjectValue(feature, filter.key)) {
103
+ // if feature filter property exists
104
+ if (common_1.getNestedObjectValue(feature, filter.key) === filter.value) {
105
+ // if feature property value is same as filter value
106
+ return feature;
107
+ }
108
+ else {
109
+ // if they are not same
110
+ return undefined;
111
+ }
87
112
  }
88
113
  else {
114
+ // if feature filter property does not exists
89
115
  return feature;
90
116
  }
91
117
  })
@@ -3,12 +3,16 @@ import { FloorModel } from '../models/floor';
3
3
  import StyleModel from '../models/style';
4
4
  import { FeatureCollection } from '../models/feature';
5
5
  import { AmenityModel } from '../models/amenity';
6
- export declare const getPackage: ({ initPolygons, autoLabelLines, amenityIdProperty, hiddenAmenities, useTimerangeData, }: {
6
+ export declare const getPackage: ({ initPolygons, autoLabelLines, amenityIdProperty, hiddenAmenities, useTimerangeData, filter, }: {
7
7
  initPolygons?: boolean;
8
8
  autoLabelLines?: boolean;
9
9
  amenityIdProperty?: string;
10
10
  hiddenAmenities?: string[];
11
11
  useTimerangeData?: boolean;
12
+ filter?: {
13
+ key: string;
14
+ value: string;
15
+ };
12
16
  }) => Promise<{
13
17
  places: PlaceModel[];
14
18
  floors: FloorModel[];
@@ -18,12 +22,16 @@ export declare const getPackage: ({ initPolygons, autoLabelLines, amenityIdPrope
18
22
  amenities: AmenityModel[];
19
23
  }>;
20
24
  declare const _default: {
21
- getPackage: ({ initPolygons, autoLabelLines, amenityIdProperty, hiddenAmenities, useTimerangeData, }: {
25
+ getPackage: ({ initPolygons, autoLabelLines, amenityIdProperty, hiddenAmenities, useTimerangeData, filter, }: {
22
26
  initPolygons?: boolean;
23
27
  autoLabelLines?: boolean;
24
28
  amenityIdProperty?: string;
25
29
  hiddenAmenities?: string[];
26
30
  useTimerangeData?: boolean;
31
+ filter?: {
32
+ key: string;
33
+ value: string;
34
+ };
27
35
  }) => Promise<{
28
36
  places: PlaceModel[];
29
37
  floors: FloorModel[];
@@ -42,7 +42,7 @@ var floors_1 = require("./floors");
42
42
  var style_1 = require("./style");
43
43
  var geo_1 = require("./geo");
44
44
  var getPackage = function (_a) {
45
- var initPolygons = _a.initPolygons, autoLabelLines = _a.autoLabelLines, amenityIdProperty = _a.amenityIdProperty, hiddenAmenities = _a.hiddenAmenities, useTimerangeData = _a.useTimerangeData;
45
+ var initPolygons = _a.initPolygons, autoLabelLines = _a.autoLabelLines, amenityIdProperty = _a.amenityIdProperty, hiddenAmenities = _a.hiddenAmenities, useTimerangeData = _a.useTimerangeData, filter = _a.filter;
46
46
  return __awaiter(void 0, void 0, void 0, function () {
47
47
  var result, promises;
48
48
  return __generator(this, function (_b) {
@@ -54,7 +54,7 @@ var getPackage = function (_a) {
54
54
  floors_1.getFloors().then(function (floors) { return (result.floors = floors.data); }),
55
55
  style_1.getStyle().then(function (style) { return (result.style = style); }),
56
56
  style_1.getStyles().then(function (styles) { return (result.styles = styles); }),
57
- geo_1.getFeatures({ initPolygons: initPolygons, autoLabelLines: autoLabelLines, hiddenAmenities: hiddenAmenities, useTimerangeData: useTimerangeData }).then(function (features) { return (result.features = features); }),
57
+ geo_1.getFeatures({ initPolygons: initPolygons, autoLabelLines: autoLabelLines, hiddenAmenities: hiddenAmenities, useTimerangeData: useTimerangeData, filter: filter }).then(function (features) { return (result.features = features); }),
58
58
  geo_1.getAmenities(amenityIdProperty).then(function (amenities) { return (result.amenities = amenities); }),
59
59
  ];
60
60
  return [4 /*yield*/, Promise.all(promises)];
@@ -25,7 +25,9 @@ export declare class FloorModel extends BaseModel {
25
25
  editor?: FloorEditorModel;
26
26
  geopoint?: [number, number];
27
27
  remoteId?: string;
28
- metadata?: object;
28
+ metadata?: {
29
+ [key: string]: string | undefined;
30
+ };
29
31
  constructor(data: any);
30
32
  get hasFloorplan(): boolean;
31
33
  }
@@ -9,6 +9,9 @@ export declare class PlaceModel extends BaseModel {
9
9
  };
10
10
  tags?: string[];
11
11
  remoteId?: string;
12
+ metadata?: {
13
+ [key: string]: string | undefined;
14
+ };
12
15
  constructor(data: any);
13
16
  get hasLocation(): boolean;
14
17
  }