UNPKG

@nativescript-community/ui-carto

Version:

NativeScript plugin for CARTO Mobile SDK

122 lines 4.75 kB
import { featureCollectionFromArgs, nativeProperty } from '..'; import { BaseNative } from '../BaseNative'; import { Projection } from '../projections'; import { JSVariantToNative } from '../utils'; export class DataSource extends BaseNative { getProjection() { if (this['projection']) { return this['projection']; } return new Projection(undefined, this.getNative().getProjection()); } } export class TileDataSource extends DataSource { createNative(options) { return null; } loadTile(x, y, z) { return this.getNative().loadTile(NTMapTile.alloc().initWithXYZoomFrameNr(x, y, z, 0)); // return interop.bufferFromData(NSData.dataWithBytesLength(data.getData().getData() as any, data.getData().size())); } get minZoom() { if (this.options.minZoom) { return this.options.minZoom; } return this.getNative().getMinZoom(); } set minZoom(value) { this.options.minZoom = value; } get maxZoom() { if (this.options.maxZoom) { return this.options.maxZoom; } return this.getNative().getMaxZoom(); } set maxZoom(value) { this.options.maxZoom = value; } } __decorate([ nativeProperty ], TileDataSource.prototype, "maxOverzoomLevel", void 0); export class OrderedTileDataSource extends TileDataSource { createNative(options) { const dataSources = options.dataSources.map((d) => d.getNative()); return NTOrderedTileDataSource.alloc().initWithDataSource1DataSource2(dataSources[0], dataSources[1]); } } export class CombinedTileDataSource extends TileDataSource { createNative(options) { const dataSources = options.dataSources.map((d) => d.getNative()); return NTCombinedTileDataSource.alloc().initWithDataSource1DataSource2ZoomLevel(dataSources[0], dataSources[1], options.zoomLevel); } } export class MergedMBVTTileDataSource extends TileDataSource { createNative(options) { const dataSources = options.dataSources.map((d) => d.getNative()); return NTMergedMBVTTileDataSource.alloc().initWithDataSource1DataSource2(dataSources[0], dataSources[1]); } } export class GeoJSONVectorTileDataSource extends TileDataSource { createNative(options) { return NTGeoJSONVectorTileDataSource.alloc().initWithMinZoomMaxZoom(options.minZoom, options.maxZoom); } createLayer(name) { return this.getNative().createLayer(name); } deleteLayer(index) { this.getNative().deleteLayer(index); } setLayerFeatureCollection(layerIndex, projection, featureCollection) { this.getNative().setLayerFeatureCollectionProjectionFeatureCollection(layerIndex, projection?.getNative(), featureCollectionFromArgs(featureCollection)); } setLayerGeoJSON(layerIndex, geoJSON) { this.getNative().setLayerGeoJSONGeoJSON(layerIndex, JSVariantToNative(geoJSON)); } setLayerGeoJSONString(layerIndex, geoJSON) { this.getNative().setLayerGeoJSONStringGeoJSON(layerIndex, typeof geoJSON === 'string' ? geoJSON : JSON.stringify(geoJSON)); } addGeoJSONFeature(layerIndex, geoJSON) { this.getNative().addGeoJSONFeatureGeoJSON(layerIndex, JSVariantToNative(geoJSON)); } addGeoJSONStringFeature(layerIndex, geoJSON) { this.getNative().addGeoJSONStringFeatureGeoJSON(layerIndex, typeof geoJSON === 'string' ? geoJSON : JSON.stringify(geoJSON)); } updateGeoJSONFeature(layerIndex, geoJSON) { this.getNative().updateGeoJSONFeatureGeoJSON(layerIndex, JSVariantToNative(geoJSON)); } updateGeoJSONStringFeature(layerIndex, geoJSON) { this.getNative().updateGeoJSONStringFeatureGeoJSON(layerIndex, typeof geoJSON === 'string' ? geoJSON : JSON.stringify(geoJSON)); } } __decorate([ nativeProperty ], GeoJSONVectorTileDataSource.prototype, "simplifyTolerance", void 0); __decorate([ nativeProperty ], GeoJSONVectorTileDataSource.prototype, "defaultLayerBuffer", void 0); export class MultiTileDataSource extends TileDataSource { createNative(options) { if (options.maxOpenedPackages) { return NTMultiTileDataSource.alloc().initWithMaxOpenedPackages(options.maxOpenedPackages); } else { return NTMultiTileDataSource.alloc().init(); } } add(source, tileMask) { if (tileMask) { this.getNative().addTileMask(source.getNative(), tileMask); } else { this.getNative().add(source.getNative()); } } remove(source) { if (this.native) { this.getNative().remove(source.getNative()); } } } //# sourceMappingURL=index.ios.js.map