@nativescript-community/ui-mapbox
Version:
Interactive, thoroughly customizable maps powered by vector tiles and OpenGL.
66 lines • 2.44 kB
JavaScript
// src/ui-mapbox/layer-factory.ios.ts
// TypeScript shim that exports LayerFactory (TS API) while delegating to native NativeLayerFactory when available.
// This preserves the TS export name 'LayerFactory' as requested.
import { Trace } from '@nativescript/core';
import { CLog, CLogTypes } from '../common';
export class Layer {
constructor(mapboxView, id) {
this.mapboxView = mapboxView;
this.id = id;
}
visibility() {
return true;
}
show() {
NativeLayerFactory.setLayerVisibility(this.mapboxView, this.id, true);
}
hide() {
NativeLayerFactory.setLayerVisibility(this.mapboxView, this.id, false);
}
getNativeInstance() {
return null;
}
setFilter(filter) {
// Not implemented here - recommend using addLayer with JSON via Mapbox.addLayer
}
getFilter() {
return null;
}
setProperty(name, value) {
NativeLayerFactory.setLayerProperty(this.mapboxView, this.id, name, value);
}
getProperty(name) {
return NativeLayerFactory.getLayerProperty(this.mapboxView, this.id, name);
}
type() {
return NativeLayerFactory.getLayerType(this.mapboxView, this.id);
}
}
// Export a TS LayerFactory that matches the old TS API but delegates to NativeLayerFactory
export class LayerFactory {
static async createLayer(mapboxView, style, belowLayerId) {
const styleJson = typeof style === 'string' ? style : JSON.stringify(style);
if (Trace.isEnabled()) {
CLog(CLogTypes.info, 'createLayer:', belowLayerId, JSON.stringify(style));
}
const id = style.id || 'layer_' + Date.now();
if (NativeLayerFactory.createLayer(mapboxView, id, styleJson, belowLayerId)) {
return new Layer(mapboxView, id);
}
else {
throw new Error('failed to create layer');
}
}
static applyLayerProperties(mapboxView, layer, properties) {
try {
// NativeLayerFactory.applyLayerProperties(layer.id, properties);
// if ((global as any).NativeLayerFactory && (global as any).NativeLayerFactory.setLayerProperty) {
for (const k of Object.keys(properties)) {
NativeLayerFactory.setLayerProperty(mapboxView, layer.id, k, properties[k]);
}
// }
}
catch (e) { }
}
}
//# sourceMappingURL=layer-factory.ios.js.map