@nativescript-community/ui-mapbox 6.2.31 → 7.0.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/common.d.ts +56 -26
  3. package/common.js +44 -28
  4. package/expression/expression-parser.android.d.ts +2 -2
  5. package/expression/expression-parser.android.js +4 -3
  6. package/expression/expression-parser.ios.d.ts +2 -2
  7. package/expression/expression-parser.ios.js +28 -13
  8. package/index.android.d.ts +59 -66
  9. package/index.android.js +1388 -1244
  10. package/index.d.ts +36 -5
  11. package/index.ios.d.ts +72 -243
  12. package/index.ios.js +1161 -1999
  13. package/layers/layer-factory.android.d.ts +7 -5
  14. package/layers/layer-factory.android.js +71 -41
  15. package/layers/layer-factory.d.ts +2 -1
  16. package/layers/layer-factory.ios.d.ts +8 -8
  17. package/layers/layer-factory.ios.js +46 -100
  18. package/layers/parser/property-parser.android.d.ts +3 -1
  19. package/layers/parser/property-parser.android.js +25 -24
  20. package/layers/parser/property-parser.d.ts +1 -1
  21. package/layers/parser/property-parser.ios.d.ts +0 -2
  22. package/layers/parser/property-parser.ios.js +0 -149
  23. package/markers/Marker.android.d.ts +28 -0
  24. package/markers/Marker.android.js +54 -0
  25. package/markers/Marker.common.d.ts +2 -0
  26. package/markers/Marker.common.js +31 -0
  27. package/markers/MarkerManager.android.d.ts +35 -0
  28. package/markers/MarkerManager.android.js +220 -0
  29. package/package.json +7 -6
  30. package/platforms/android/include.gradle +31 -27
  31. package/platforms/android/ui_mapbox.aar +0 -0
  32. package/platforms/ios/Podfile +3 -1
  33. package/platforms/ios/Resources/default_pin.png +0 -0
  34. package/platforms/ios/src/MapboxBridge.swift +1479 -0
  35. package/platforms/ios/src/NativeExpressionParser.swift +33 -0
  36. package/platforms/ios/src/NativeLayerFactory.swift +108 -0
  37. package/tsconfig.tsbuildinfo +1 -0
  38. package/typings/Mapbox.ios.d.ts +2 -3242
  39. package/typings/geojson.android.d.ts +689 -0
  40. package/typings/index.android.d.ts +46 -0
  41. package/typings/mapbox.android.d.ts +39968 -12560
  42. package/typings/mapbox.bridge.ios.d.ts +129 -0
@@ -1,12 +1,13 @@
1
- import { LayerCommon, LayerType } from "../common";
1
+ import { LayerCommon, LayerType } from '../common';
2
+ type ILayer = com.mapbox.maps.extension.style.layers.generated.FillLayer | com.mapbox.maps.extension.style.layers.generated.LineLayer | com.mapbox.maps.extension.style.layers.generated.SymbolLayer | com.mapbox.maps.extension.style.layers.generated.CircleLayer | com.mapbox.maps.extension.style.layers.generated.HeatmapLayer | com.mapbox.maps.extension.style.layers.generated.FillExtrusionLayer | com.mapbox.maps.extension.style.layers.generated.RasterLayer | com.mapbox.maps.extension.style.layers.generated.HillshadeLayer;
2
3
  export declare class Layer implements LayerCommon {
3
4
  id: string;
4
5
  private instance;
5
- constructor(instance: any);
6
+ constructor(instance: ILayer);
6
7
  visibility(): boolean;
7
8
  show(): void;
8
9
  hide(): void;
9
- getNativeInstance(): any;
10
+ getNativeInstance(): ILayer;
10
11
  setFilter(filter: any[]): void;
11
12
  getFilter(): any[];
12
13
  setProperty(name: string, value: any): void;
@@ -14,6 +15,7 @@ export declare class Layer implements LayerCommon {
14
15
  type(): LayerType;
15
16
  }
16
17
  export declare class LayerFactory {
17
- static createLayer(style: any, source: any): Promise<LayerCommon>;
18
- private static parseProperties;
18
+ static applyLayerProperties(layer: com.mapbox.maps.extension.style.layers.Layer, properties: Record<string, any>): void;
19
+ static createLayer(style: any, source: com.mapbox.maps.extension.style.sources.Source): Promise<LayerCommon>;
19
20
  }
21
+ export {};
@@ -1,105 +1,135 @@
1
1
  import { ExpressionParser } from '../expression/expression-parser';
2
2
  import { PropertyParser } from './parser/property-parser';
3
+ import { toCamelCase, transformValue } from './parser/property-parser.android';
3
4
  export class Layer {
4
5
  constructor(instance) {
5
6
  this.instance = instance;
6
- this.id = instance.getId();
7
+ this.id = instance.getSourceId();
7
8
  }
8
9
  visibility() {
9
10
  return this.instance.getVisibility().getValue() === 'visible' ? true : false;
10
11
  }
11
12
  show() {
12
- this.instance.setProperties([new com.mapbox.mapboxsdk.style.layers.PropertyValue('visibility', 'visible')]);
13
+ LayerFactory.applyLayerProperties(this.instance, {
14
+ visibility: 'visible'
15
+ });
16
+ // this.instance.setProperties([new com.mapbox.maps.extension.style.layers.generated.PropertyValue('visibility', 'visible')]);
13
17
  }
14
18
  hide() {
15
- this.instance.setProperties([new com.mapbox.mapboxsdk.style.layers.PropertyValue('visibility', 'none')]);
19
+ LayerFactory.applyLayerProperties(this.instance, {
20
+ visibility: 'none'
21
+ });
22
+ // this.instance.setProperties([new com.mapbox.maps.extension.style.layers.generated.PropertyValue('visibility', 'none')]);
16
23
  }
17
24
  getNativeInstance() {
18
25
  return this.instance;
19
26
  }
20
27
  setFilter(filter) {
21
- this.instance.setFilter(ExpressionParser.parseJson(filter));
28
+ if (this.instance['setFilter']) {
29
+ this.instance['setFilter'](ExpressionParser.parseJson(filter));
30
+ }
22
31
  }
23
32
  getFilter() {
24
- return ExpressionParser.toJson(this.instance.getFilter());
33
+ if (this.instance['getFilter']) {
34
+ return ExpressionParser.toJson(this.instance['getFilter']());
35
+ }
36
+ return [];
25
37
  }
26
38
  setProperty(name, value) {
27
- const properties = PropertyParser.parsePropertiesForLayer({ [name]: value });
28
- this.instance.setProperties(properties);
39
+ LayerFactory.applyLayerProperties(this.instance, {
40
+ [name]: value
41
+ });
29
42
  }
30
43
  getProperty(name) {
31
44
  return PropertyParser.propertyValueFromLayer(this.instance, name);
32
45
  }
33
46
  type() {
34
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.FillLayer) {
35
- return "fill";
47
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.FillLayer) {
48
+ return 'fill';
36
49
  }
37
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.LineLayer) {
38
- return "line";
50
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.LineLayer) {
51
+ return 'line';
39
52
  }
40
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.SymbolLayer) {
41
- return "symbol";
53
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.SymbolLayer) {
54
+ return 'symbol';
42
55
  }
43
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.CircleLayer) {
44
- return "circle";
56
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.CircleLayer) {
57
+ return 'circle';
45
58
  }
46
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.HeatmapLayer) {
47
- return "heatmap";
59
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.HeatmapLayer) {
60
+ return 'heatmap';
48
61
  }
49
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer) {
50
- return "fill-extrusion";
62
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.FillExtrusionLayer) {
63
+ return 'fill-extrusion';
51
64
  }
52
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.RasterLayer) {
53
- return "raster";
65
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.RasterLayer) {
66
+ return 'raster';
54
67
  }
55
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.HillshadeLayer) {
56
- return "hillshade";
57
- }
58
- if (this.instance instanceof com.mapbox.mapboxsdk.style.layers.BackgroundLayer) {
59
- return "background";
68
+ if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.HillshadeLayer) {
69
+ return 'hillshade';
60
70
  }
71
+ // if (this.instance instanceof com.mapbox.maps.extension.style.layers.generated.BackgroundLayer) {
72
+ // return 'background';
73
+ // }
61
74
  // there is no sky layer in the Android Mapbox SDK
62
75
  return null;
63
76
  }
64
77
  }
65
78
  export class LayerFactory {
79
+ static applyLayerProperties(layer, properties) {
80
+ for (const key in properties) {
81
+ if (!properties.hasOwnProperty(key))
82
+ continue;
83
+ const value = properties[key];
84
+ const actualKey = toCamelCase(key);
85
+ const nValue = transformValue(actualKey, value);
86
+ // Mapbox v11 setters are named after the property, e.g., circleColor(), circleRadius()
87
+ const setterName = actualKey;
88
+ // Call the setter dynamically
89
+ if (typeof layer[setterName] === 'function') {
90
+ layer[setterName](nValue);
91
+ }
92
+ else {
93
+ console.warn(`Layer has no setter for ${setterName}`);
94
+ }
95
+ }
96
+ }
66
97
  static async createLayer(style, source) {
67
- const layerProperties = this.parseProperties(style.type, Object.assign(style.paint || {}, style.layout || {})); // TODO: handle defaults
68
- const sourceId = source.getId();
98
+ // const layerProperties = this.parseProperties(style.type, Object.assign(style.paint || {}, style.layout || {})); // TODO: handle defaults
99
+ const layerProperties = Object.assign(style.paint || {}, style.layout || {}); // TODO: handle defaults
100
+ const sourceId = source.getSourceId();
69
101
  let nativeLayer;
70
102
  switch (style.type) {
71
103
  case 'line':
72
- nativeLayer = new com.mapbox.mapboxsdk.style.layers.LineLayer(style.id, sourceId).withProperties(layerProperties);
104
+ nativeLayer = new com.mapbox.maps.extension.style.layers.generated.LineLayer(style.id, sourceId);
73
105
  break;
74
106
  case 'circle':
75
- nativeLayer = new com.mapbox.mapboxsdk.style.layers.CircleLayer(style.id, sourceId).withProperties(layerProperties);
107
+ nativeLayer = new com.mapbox.maps.extension.style.layers.generated.CircleLayer(style.id, sourceId);
76
108
  break;
77
109
  case 'fill':
78
- nativeLayer = new com.mapbox.mapboxsdk.style.layers.FillLayer(style.id, sourceId).withProperties(layerProperties);
110
+ nativeLayer = new com.mapbox.maps.extension.style.layers.generated.FillLayer(style.id, sourceId);
79
111
  break;
80
112
  case 'symbol':
81
- nativeLayer = new com.mapbox.mapboxsdk.style.layers.SymbolLayer(style.id, sourceId).withProperties(layerProperties);
113
+ nativeLayer = new com.mapbox.maps.extension.style.layers.generated.SymbolLayer(style.id, sourceId);
82
114
  break;
83
115
  case 'raster':
84
- nativeLayer = new com.mapbox.mapboxsdk.style.layers.RasterLayer(style.id, sourceId).withProperties(layerProperties);
116
+ nativeLayer = new com.mapbox.maps.extension.style.layers.generated.RasterLayer(style.id, sourceId);
85
117
  break;
86
118
  default:
87
119
  throw new Error(`Unknown layer type: ${style.type}`);
88
120
  }
121
+ LayerFactory.applyLayerProperties(nativeLayer, layerProperties);
89
122
  const layer = new Layer(nativeLayer);
90
123
  if (style.minzoom !== undefined) {
91
- nativeLayer.setMinZoom(style.minzoom);
124
+ nativeLayer.minZoom(style.minzoom);
92
125
  }
93
126
  if (style.maxzoom !== undefined) {
94
- nativeLayer.setMaxZoom(style.maxzoom);
95
- }
96
- if (style['source-layer'] && nativeLayer.withSourceLayer) {
97
- nativeLayer.withSourceLayer(style['source-layer']);
127
+ nativeLayer.maxZoom(style.maxzoom);
98
128
  }
129
+ // if (style['source-layer'] && (nativeLayer as any).withSourceLayer) {
130
+ // (nativeLayer as any).withSourceLayer(style['source-layer']);
131
+ // }
99
132
  return layer;
100
133
  }
101
- static parseProperties(layerType, propertiesObject) {
102
- return PropertyParser.parsePropertiesForLayer(propertiesObject);
103
- }
104
134
  }
105
135
  //# sourceMappingURL=layer-factory.android.js.map
@@ -1,7 +1,8 @@
1
- import { LayerCommon, LayerType } from "../common"
1
+ import { LayerCommon, LayerType } from '../common';
2
2
 
3
3
  declare class LayerFactory {
4
4
  static createLayer(style, source): Promise<LayerCommon>;
5
+ static applyLayerProperties(layer: any, properties: Record<string, any>);
5
6
  }
6
7
 
7
8
  export declare class Layer implements LayerCommon {
@@ -1,13 +1,8 @@
1
- import { LayerCommon, LayerType } from "../common";
2
- export declare class LayerFactory {
3
- static createLayer(style: any, source: any): Promise<LayerCommon>;
4
- private static parseProperties;
5
- }
1
+ import { LayerCommon, LayerType } from '../common';
6
2
  export declare class Layer implements LayerCommon {
3
+ mapboxView: MapView;
7
4
  id: string;
8
- private instance;
9
- constructor(instance: MGLStyleLayer);
10
- type(): LayerType;
5
+ constructor(mapboxView: MapView, id: string);
11
6
  visibility(): boolean;
12
7
  show(): void;
13
8
  hide(): void;
@@ -16,4 +11,9 @@ export declare class Layer implements LayerCommon {
16
11
  getFilter(): any[];
17
12
  setProperty(name: string, value: any): void;
18
13
  getProperty(name: string): any;
14
+ type(): LayerType;
15
+ }
16
+ export declare class LayerFactory {
17
+ static createLayer(mapboxView: MapView, style: any, belowLayerId: string): Promise<LayerCommon>;
18
+ static applyLayerProperties(mapboxView: MapView, layer: any, properties: Record<string, any>): void;
19
19
  }
@@ -1,120 +1,66 @@
1
- import { ExpressionParser } from '../expression/expression-parser';
2
- import { PropertyParser } from './parser/property-parser';
3
- export class LayerFactory {
4
- static async createLayer(style, source) {
5
- let nativeLayer;
6
- switch (style.type) {
7
- case 'line':
8
- nativeLayer = MGLLineStyleLayer.alloc().initWithIdentifierSource(style.id, source);
9
- break;
10
- case 'circle':
11
- nativeLayer = MGLCircleStyleLayer.alloc().initWithIdentifierSource(style.id, source);
12
- break;
13
- case 'fill':
14
- nativeLayer = MGLFillStyleLayer.alloc().initWithIdentifierSource(style.id, source);
15
- break;
16
- case 'symbol':
17
- nativeLayer = MGLSymbolStyleLayer.alloc().initWithIdentifierSource(style.id, source);
18
- break;
19
- case 'raster':
20
- nativeLayer = MGLRasterStyleLayer.alloc().initWithIdentifierSource(style.id, source);
21
- break;
22
- default:
23
- throw new Error(`Unknown layer type: ${style.type}`);
24
- }
25
- if (style.minzoom !== undefined) {
26
- nativeLayer.minimumZoomLevel = style.minzoom;
27
- }
28
- if (style.maxzoom !== undefined) {
29
- nativeLayer.maximumZoomLevel = style.maxzoom;
30
- }
31
- if (style['source-layer']) {
32
- nativeLayer.sourceLayerIdentifier = style['source-layer'];
33
- }
34
- const layerProperties = this.parseProperties(style.type, Object.assign(style.paint || {}, style.layout || {})); // TODO: handle defaults
35
- for (const propKey in layerProperties) {
36
- if (Object.prototype.hasOwnProperty.call(layerProperties, propKey)) {
37
- nativeLayer[propKey] = layerProperties[propKey];
38
- }
39
- }
40
- const layer = new Layer(nativeLayer);
41
- return layer;
42
- }
43
- static parseProperties(layerType, propertiesObject) {
44
- return PropertyParser.parsePropertiesForLayer(propertiesObject);
45
- }
46
- }
1
+ // src/ui-mapbox/layer-factory.ios.ts
2
+ // TypeScript shim that exports LayerFactory (TS API) while delegating to native NativeLayerFactory when available.
3
+ // This preserves the TS export name 'LayerFactory' as requested.
4
+ import { Trace } from '@nativescript/core';
5
+ import { CLog, CLogTypes } from '../common';
47
6
  export class Layer {
48
- constructor(instance) {
49
- this.instance = instance;
50
- this.id = instance.identifier;
51
- }
52
- type() {
53
- if (this.instance instanceof MGLFillStyleLayer) {
54
- return "fill";
55
- }
56
- if (this.instance instanceof MGLLineStyleLayer) {
57
- return "line";
58
- }
59
- if (this.instance instanceof MGLSymbolStyleLayer) {
60
- return "symbol";
61
- }
62
- if (this.instance instanceof MGLCircleStyleLayer) {
63
- return "circle";
64
- }
65
- if (this.instance instanceof MGLHeatmapStyleLayer) {
66
- return "heatmap";
67
- }
68
- if (this.instance instanceof MGLFillExtrusionStyleLayer) {
69
- return "fill-extrusion";
70
- }
71
- if (this.instance instanceof MGLRasterStyleLayer) {
72
- return "raster";
73
- }
74
- if (this.instance instanceof MGLHillshadeStyleLayer) {
75
- return "hillshade";
76
- }
77
- if (this.instance instanceof MGLBackgroundStyleLayer) {
78
- return "background";
79
- }
80
- // there is no sky layer in the Mapbox iOS SDK
81
- return null;
7
+ constructor(mapboxView, id) {
8
+ this.mapboxView = mapboxView;
9
+ this.id = id;
82
10
  }
83
11
  visibility() {
84
- return this.instance.visible;
12
+ return true;
85
13
  }
86
14
  show() {
87
- this.instance.visible = true;
15
+ NativeLayerFactory.setLayerVisibility(this.mapboxView, this.id, true);
88
16
  }
89
17
  hide() {
90
- this.instance.visible = false;
18
+ NativeLayerFactory.setLayerVisibility(this.mapboxView, this.id, false);
91
19
  }
92
20
  getNativeInstance() {
93
- return this.instance;
21
+ return null;
94
22
  }
95
23
  setFilter(filter) {
96
- if (this.instance instanceof MGLVectorStyleLayer) {
97
- // MGLVectorStyleLayer is the base type of many layer types. Predicates only supported on vector style layers.
98
- // See https://docs.mapbox.com/ios/maps/api/6.3.0/Classes/MGLVectorStyleLayer.html
99
- this.instance.predicate = ExpressionParser.parseJson(filter);
100
- }
101
- else {
102
- throw new Error('Set filter only support for vector layer.');
103
- }
24
+ // Not implemented here - recommend using addLayer with JSON via Mapbox.addLayer
104
25
  }
105
26
  getFilter() {
106
- return ExpressionParser.toJson(this.instance.predicate);
27
+ return null;
107
28
  }
108
29
  setProperty(name, value) {
109
- const properties = PropertyParser.parsePropertiesForLayer({ [name]: value });
110
- for (const propKey in properties) {
111
- if (Object.prototype.hasOwnProperty.call(properties, propKey)) {
112
- this.instance[propKey] = properties[propKey];
113
- }
114
- }
30
+ NativeLayerFactory.setLayerProperty(this.mapboxView, this.id, name, value);
115
31
  }
116
32
  getProperty(name) {
117
- return PropertyParser.propertyValueFromLayer(this.instance, name);
33
+ return NativeLayerFactory.getLayerProperty(this.mapboxView, this.id, name);
34
+ }
35
+ type() {
36
+ return NativeLayerFactory.getLayerType(this.mapboxView, this.id);
37
+ }
38
+ }
39
+ // Export a TS LayerFactory that matches the old TS API but delegates to NativeLayerFactory
40
+ export class LayerFactory {
41
+ static async createLayer(mapboxView, style, belowLayerId) {
42
+ const styleJson = typeof style === 'string' ? style : JSON.stringify(style);
43
+ if (Trace.isEnabled()) {
44
+ CLog(CLogTypes.info, 'createLayer:', belowLayerId, JSON.stringify(style));
45
+ }
46
+ const id = style.id || 'layer_' + Date.now();
47
+ if (NativeLayerFactory.createLayer(mapboxView, id, styleJson, belowLayerId)) {
48
+ return new Layer(mapboxView, id);
49
+ }
50
+ else {
51
+ throw new Error('failed to create layer');
52
+ }
53
+ }
54
+ static applyLayerProperties(mapboxView, layer, properties) {
55
+ try {
56
+ // NativeLayerFactory.applyLayerProperties(layer.id, properties);
57
+ // if ((global as any).NativeLayerFactory && (global as any).NativeLayerFactory.setLayerProperty) {
58
+ for (const k of Object.keys(properties)) {
59
+ NativeLayerFactory.setLayerProperty(mapboxView, layer.id, k, properties[k]);
60
+ }
61
+ // }
62
+ }
63
+ catch (e) { }
118
64
  }
119
65
  }
120
66
  //# sourceMappingURL=layer-factory.ios.js.map
@@ -1,4 +1,6 @@
1
+ export declare function toCamelCase(s: any): any;
2
+ export declare function toPascalCase(s: any): any;
3
+ export declare function transformValue(key: any, value: any): any;
1
4
  export declare class PropertyParser {
2
- static parsePropertiesForLayer(propertiesObject: any): any[];
3
5
  static propertyValueFromLayer(layer: any, key: string): any;
4
6
  }
@@ -1,42 +1,43 @@
1
1
  import { Color } from '@nativescript/core';
2
- function toCamelCase(s) {
2
+ export function toCamelCase(s) {
3
3
  return s.replace(/([-_][a-z])/gi, ($1) => $1.toUpperCase().replace('-', '').replace('_', ''));
4
4
  }
5
- function toPascalCase(s) {
5
+ export function toPascalCase(s) {
6
6
  return s.replace(/(^[a-z]|[-_][a-z])/gi, ($1) => $1.toUpperCase().replace('-', '').replace('_', ''));
7
7
  }
8
- const Expression = com.mapbox.mapboxsdk.style.expressions.Expression;
9
- function transformValue(key, value) {
8
+ const Expression = com.mapbox.maps.extension.style.expressions.generated.Expression;
9
+ export function transformValue(key, value) {
10
10
  let nValue = value;
11
11
  if (Array.isArray(value)) {
12
- nValue = Expression.Converter.convert(JSON.stringify(value));
12
+ nValue = Expression.fromRaw(JSON.stringify(value));
13
13
  }
14
14
  if (key.indexOf('-color') !== -1 && !Array.isArray(value)) {
15
15
  const color = value instanceof Color ? value : new Color(value);
16
16
  nValue = color.android;
17
17
  }
18
- else if (typeof value === 'number') {
19
- nValue = new java.lang.Float(value);
18
+ else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
19
+ nValue = Expression.literal(value);
20
20
  }
21
- else if (typeof value === 'boolean') {
22
- nValue = new java.lang.Boolean(value);
21
+ else if (Array.isArray(value)) {
22
+ // assume it's a JSON-style expression
23
+ nValue = Expression.fromRaw(JSON.stringify(value));
23
24
  }
24
25
  return nValue;
25
26
  }
26
27
  export class PropertyParser {
27
- static parsePropertiesForLayer(propertiesObject) {
28
- const nProperties = [];
29
- const PropertyFactory = com.mapbox.mapboxsdk.style.layers.PropertyFactory;
30
- if (propertiesObject) {
31
- Object.keys(propertiesObject).forEach((k) => {
32
- const actualKey = toCamelCase(k);
33
- const value = propertiesObject[k];
34
- const nValue = transformValue(k, value);
35
- nProperties.push(PropertyFactory[actualKey](nValue));
36
- });
37
- }
38
- return nProperties;
39
- }
28
+ // static parsePropertiesForLayer(propertiesObject) {
29
+ // const nProperties = [];
30
+ // const PropertyFactory = com.mapbox.maps.extension.style.layers.PropertyFactory;
31
+ // if (propertiesObject) {
32
+ // Object.keys(propertiesObject).forEach((k) => {
33
+ // const actualKey = toCamelCase(k);
34
+ // const value = propertiesObject[k];
35
+ // const nValue = transformValue(k, value);
36
+ // nProperties.push(PropertyFactory[actualKey](nValue));
37
+ // });
38
+ // }
39
+ // return nProperties;
40
+ // }
40
41
  static propertyValueFromLayer(layer, key) {
41
42
  const getterMethodName = `get${toPascalCase(key)}`;
42
43
  let nValue;
@@ -47,11 +48,11 @@ export class PropertyParser {
47
48
  // native method seems not exist
48
49
  return null;
49
50
  }
50
- if (!nValue || nValue.isNull()) {
51
+ if (nValue === null || nValue === undefined) {
51
52
  return null;
52
53
  }
53
54
  if (nValue.isExpression()) {
54
- return JSON.parse(nValue.getExpression().toString());
55
+ return JSON.parse(nValue.toString());
55
56
  }
56
57
  else if (!!nValue.getColorInt()) {
57
58
  return new Color(nValue.getColorInt().intValue());
@@ -1,4 +1,4 @@
1
1
  export declare class PropertyParser {
2
- static parsePropertiesForLayer(propertiesObject: any): any;
2
+ // static parsePropertiesForLayer(propertiesObject: any): any;
3
3
  static propertyValueFromLayer(layer, key: string): any;
4
4
  }
@@ -1,4 +1,2 @@
1
1
  export declare class PropertyParser {
2
- static parsePropertiesForLayer(propertiesObject: any): {};
3
- static propertyValueFromLayer(layer: any, key: string): any;
4
2
  }
@@ -1,152 +1,3 @@
1
- import { Color } from '@nativescript/core';
2
- function toCamelCase(s) {
3
- return s.replace(/([-_][a-z])/gi, ($1) => $1.toUpperCase().replace('-', '').replace('_', ''));
4
- }
5
- const styleExtras = {
6
- // padding
7
- iconTextFitPadding: {
8
- iosType: 'edgeinsets'
9
- },
10
- // offsets
11
- iconOffset: {
12
- iosType: 'vector'
13
- },
14
- textOffset: {
15
- iosType: 'vector'
16
- },
17
- lineOffset: {
18
- iosType: 'vector'
19
- },
20
- // translates
21
- fillTranslate: {
22
- iosType: 'vector'
23
- },
24
- lineTranslate: {
25
- iosType: 'vector'
26
- },
27
- iconTranslate: {
28
- iosType: 'vector'
29
- },
30
- textTranslate: {
31
- iosType: 'vector'
32
- },
33
- circleTranslate: {
34
- iosType: 'vector'
35
- },
36
- fillExtrusionTranslate: {
37
- iosType: 'vector'
38
- }
39
- };
40
- const keysMap = {
41
- 'circle-pitch-scale': 'circleScaleAlignment',
42
- 'circle-translate': 'circleTranslation',
43
- 'circle-translate-anchor': 'circleTranslationAnchor',
44
- 'fill-antialias': 'fillAntialiased',
45
- 'fill-translate': 'fillTranslation',
46
- 'fill-translate-anchor': 'fillTranslationAnchor',
47
- 'icon-allow-overlap': 'iconAllowsOverlap',
48
- 'icon-keep-upright': 'keepsIconUpright',
49
- 'icon-ignore-placement': 'iconIgnoresPlacement',
50
- 'icon-image': 'iconImageName',
51
- 'icon-rotate': 'iconRotation',
52
- 'icon-rotate-alignment': 'iconRotationAlignment',
53
- 'icon-translate': 'iconTranslation',
54
- 'icon-translate-anchor': 'iconTranslationAnchor',
55
- 'icon-size': 'iconScale',
56
- 'line-translate': 'lineTranslation',
57
- 'line-translate-anchor': 'lineTranslationAnchor',
58
- 'line-dasharray': 'lineDashPattern',
59
- 'text-allow-overlap': 'textAllowsOverlap',
60
- 'text-field': 'text',
61
- 'text-font': 'textFontNames',
62
- 'text-justify': 'textJustification',
63
- 'text-ignore-placement': 'textIgnoresPlacement',
64
- 'text-keep-upright': 'keepsTextUpright',
65
- 'text-max-angle': 'maximumTextAngle',
66
- 'text-max-width': 'maximumTextWidth',
67
- 'text-rotate': 'textRotation',
68
- 'text-rotate-alignment': 'textRotationAlignment',
69
- 'text-size': 'textFontSize',
70
- 'text-translate': 'textTranslation',
71
- 'text-translate-anchor': 'textTranslationAnchor',
72
- 'raster-hue-rotate': 'rasterHueRotation',
73
- 'raster-resampling': 'rasterResamplingMode',
74
- 'raster-brightness-min': 'maximumRasterBrightness',
75
- 'raster-brightness-max': 'minimumRasterBrightness'
76
- };
77
- function transformValue(key, value, _styleType) {
78
- if (_styleType === 'color') {
79
- const color = value instanceof Color ? value : new Color(value);
80
- return color.ios;
81
- }
82
- else if (_styleType === 'vector') {
83
- const vector = CGVectorMake(value[0], value[1]);
84
- return NSExpression.expressionWithMGLJSONObject(NSValue.valueWithCGVector(vector));
85
- }
86
- else if (_styleType === 'edgeinsets') {
87
- const edgeInsets = new UIEdgeInsets({
88
- top: value[0],
89
- left: value[1],
90
- bottom: value[2],
91
- right: value[3]
92
- });
93
- return NSExpression.expressionWithMGLJSONObject(NSValue.valueWithUIEdgeInsets(edgeInsets));
94
- }
95
- else {
96
- switch (key) {
97
- case 'raster-resampling':
98
- if (value === 'linear') {
99
- return 0 /* MGLRasterResamplingMode.Linear */;
100
- }
101
- else if (value === 'nearest') {
102
- return 1 /* MGLRasterResamplingMode.Nearest */;
103
- }
104
- else {
105
- return value;
106
- }
107
- default:
108
- return value;
109
- }
110
- }
111
- }
112
1
  export class PropertyParser {
113
- static parsePropertiesForLayer(propertiesObject) {
114
- const nProperties = {};
115
- if (propertiesObject) {
116
- Object.keys(propertiesObject).forEach((k) => {
117
- const actualKey = keysMap[k] || toCamelCase(k);
118
- const value = propertiesObject[k];
119
- const rValue = transformValue(k, value, styleExtras[k]?.iosType);
120
- if (Array.isArray(value)) {
121
- nProperties[actualKey] = NSExpression.expressionWithMGLJSONObject(rValue);
122
- }
123
- else {
124
- nProperties[actualKey] = NSExpression.expressionForConstantValue(rValue);
125
- }
126
- });
127
- }
128
- return nProperties;
129
- }
130
- static propertyValueFromLayer(layer, key) {
131
- const actualKey = keysMap[key] || toCamelCase(key);
132
- const nValue = layer[actualKey];
133
- if (!nValue) {
134
- return null;
135
- }
136
- if (nValue.expressionType === 0 /* NSExpressionType.ConstantValueExpressionType */) {
137
- if (nValue.constantValue instanceof UIColor) {
138
- return Color.fromIosColor(nValue.constantValue);
139
- }
140
- else {
141
- return nValue.constantValue;
142
- }
143
- }
144
- else {
145
- const expressionObj = nValue.mgl_jsonExpressionObject;
146
- const data = NSJSONSerialization.dataWithJSONObjectOptionsError(expressionObj, 0);
147
- const expression = NSString.alloc().initWithDataEncoding(data, NSUTF8StringEncoding);
148
- return JSON.parse(expression);
149
- }
150
- }
151
2
  }
152
3
  //# sourceMappingURL=property-parser.ios.js.map