UNPKG

@nativescript-community/ui-carto

Version:

NativeScript plugin for CARTO Mobile SDK

125 lines 4.71 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(new com.carto.core.MapTile(x, y, z, 0)); // return (ArrayBuffer as any).from(java.nio.ByteBuffer.wrap(data.getData().getData())); } 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 new com.carto.datasources.OrderedTileDataSource(dataSources[0], dataSources[1]); } } export class CombinedTileDataSource extends TileDataSource { createNative(options) { const dataSources = options.dataSources.map((d) => d.getNative()); return new com.carto.datasources.CombinedTileDataSource(dataSources[0], dataSources[1], options.zoomLevel); } } export class MergedMBVTTileDataSource extends TileDataSource { createNative(options) { const dataSources = options.dataSources.map((d) => d.getNative()); return new com.carto.datasources.MergedMBVTTileDataSource(dataSources[0], dataSources[1]); } } export class GeoJSONVectorTileDataSource extends TileDataSource { createNative(options) { return new com.carto.datasources.GeoJSONVectorTileDataSource(options.minZoom, options.maxZoom); } createLayer(name) { return this.getNative().createLayer(name); } setLayerFeatureCollection(layerIndex, projection, featureCollection) { this.getNative().setLayerFeatureCollection(layerIndex, projection?.getNative(), featureCollectionFromArgs(featureCollection)); } setLayerGeoJSON(layerIndex, geoJSON) { this.getNative().setLayerGeoJSON(layerIndex, JSVariantToNative(geoJSON)); } setLayerGeoJSONString(layerIndex, geoJSON) { this.getNative().setLayerGeoJSONString(layerIndex, typeof geoJSON === 'string' ? geoJSON : JSON.stringify(geoJSON)); } addGeoJSONFeature(layerIndex, geoJSON) { this.getNative().addGeoJSONFeature(layerIndex, JSVariantToNative(geoJSON)); } addGeoJSONStringFeature(layerIndex, geoJSON) { this.getNative().addGeoJSONStringFeature(layerIndex, typeof geoJSON === 'string' ? geoJSON : JSON.stringify(geoJSON)); } updateGeoJSONFeature(layerIndex, geoJSON) { this.getNative().updateGeoJSONFeature(layerIndex, JSVariantToNative(geoJSON)); } updateGeoJSONStringFeature(layerIndex, geoJSON) { this.getNative().updateGeoJSONStringFeature(layerIndex, typeof geoJSON === 'string' ? geoJSON : JSON.stringify(geoJSON)); } deleteLayer(index) { this.getNative().deleteLayer(index); } removeGeoJSONFeature(layerIndex, id) { this.getNative().removeGeoJSONFeature(layerIndex, JSVariantToNative(id)); } } __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 new com.carto.datasources.MultiTileDataSource(options.maxOpenedPackages); } else { return new com.carto.datasources.MultiTileDataSource(); } } add(source, tileMask) { if (tileMask) { this.getNative().add(source.getNative(), tileMask); } else { this.getNative().add(source.getNative()); } } remove(source) { if (this.native) { this.getNative().remove(source.getNative()); } } } //# sourceMappingURL=index.android.js.map