UNPKG

@nativescript-community/ui-carto

Version:

NativeScript plugin for CARTO Mobile SDK

401 lines 17.3 kB
import { Layer, TileLayer } from '.'; import { BaseNative, nativeProperty } from '..'; import { fromNativeMapPos, fromNativeScreenPos } from '../core'; import { VectorElement } from '../vectorelements'; import { MBVectorTileDecoder } from '../vectortiles'; export var VectorTileRenderOrder; (function (VectorTileRenderOrder) { VectorTileRenderOrder[VectorTileRenderOrder["HIDDEN"] = -1] = "HIDDEN"; VectorTileRenderOrder[VectorTileRenderOrder["LAYER"] = 0] = "LAYER"; VectorTileRenderOrder[VectorTileRenderOrder["LAST"] = 1] = "LAST"; })(VectorTileRenderOrder || (VectorTileRenderOrder = {})); export var VectorElementDragResult; (function (VectorElementDragResult) { VectorElementDragResult[VectorElementDragResult["IGNORE"] = 0] = "IGNORE"; VectorElementDragResult[VectorElementDragResult["STOP"] = 1] = "STOP"; VectorElementDragResult[VectorElementDragResult["MODIFY"] = 2] = "MODIFY"; VectorElementDragResult[VectorElementDragResult["DELETE"] = 3] = "DELETE"; })(VectorElementDragResult || (VectorElementDragResult = {})); var NTVectorElementEventListenerImpl = /** @class */ (function (_super) { __extends(NTVectorElementEventListenerImpl, _super); function NTVectorElementEventListenerImpl() { return _super !== null && _super.apply(this, arguments) || this; } NTVectorElementEventListenerImpl.initWithOwner = function (owner, layer, projection) { var delegate = NTVectorElementEventListenerImpl.new(); delegate._owner = owner; delegate._layer = layer; delegate.projection = projection; return delegate; }; NTVectorElementEventListenerImpl.prototype.onVectorElementClickedThreaded = function (info) { var owner = this._owner.get(); if (owner && owner.onVectorElementClicked) { var nElement = info.getVectorElement(); var element = new VectorElement(undefined, nElement); var position = info.getClickPos(); var elementPos = info.getElementClickPos(); if (this.projection) { var layerProj = this._layer.get().getNative().getDataSource().getProjection(); var nProj = this.projection.getNative(); elementPos = nProj.fromWgs84(layerProj.toWgs84(elementPos)); position = nProj.fromWgs84(layerProj.toWgs84(position)); } return (owner.onVectorElementClicked({ clickType: info.getClickType(), layer: this._layer.get(), element: element, native: nElement, metaData: element.metaData, position: fromNativeMapPos(position), elementPos: fromNativeMapPos(elementPos) }) || false); } return false; }; return NTVectorElementEventListenerImpl; }(AKVectorElementEventListener)); export { NTVectorElementEventListenerImpl }; let geojsonWriter; function getGeojsonWriter() { if (!geojsonWriter) { geojsonWriter = NTGeoJSONGeometryWriter.alloc().init(); } return geojsonWriter; } var NTVectorTileEventListenerImpl = /** @class */ (function (_super) { __extends(NTVectorTileEventListenerImpl, _super); function NTVectorTileEventListenerImpl() { return _super !== null && _super.apply(this, arguments) || this; } NTVectorTileEventListenerImpl.initWithOwner = function (owner, layer, projection) { var delegate = NTVectorTileEventListenerImpl.new(); delegate._owner = owner; delegate._layer = layer; delegate.projection = projection; return delegate; }; NTVectorTileEventListenerImpl.prototype.onVectorTileClickedThreaded = function (info) { var _a; var owner = this._owner.get(); if (owner && owner.onVectorTileClicked) { var feature = info.getFeature(); var geometry = feature.getGeometry(); var position = info.getClickPos(); var geoPosIndex = info.getFeaturePosIndex(); var featurePos = void 0; if (geoPosIndex !== -1 && /MultiPoint/.test(geometry.constructor.name)) { featurePos = (_a = geometry.getGeometry(geoPosIndex)) === null || _a === void 0 ? void 0 : _a.getCenterPos(); } if (!featurePos) { featurePos = geometry.getCenterPos(); } var projection = void 0; var dataSourceProjection_1 = this._layer.get().getNative().getDataSource().getProjection(); if (this.projection) { projection = this.projection.getNative(); featurePos = projection.fromWgs84(dataSourceProjection_1.toWgs84(featurePos)); position = projection.fromWgs84(dataSourceProjection_1.toWgs84(position)); } var geoFeature = { feature: feature, id: info.getFeatureId(), layer: info.getFeatureLayerName(), _nativeGeometry: geometry, get geometry() { if (!this._parsedGeometry) { var writer = getGeojsonWriter(); writer.setSourceProjection(dataSourceProjection_1); this._geometry = getGeojsonWriter().writeGeometry(this._nativeGeometry); this._parsedGeometry = JSON.parse(this._geometry); } return this._parsedGeometry; }, get _properties() { return info.getFeature().getProperties().toString(); }, get properties() { if (!this._parsedProperties) { this._parsedProperties = JSON.parse(this._properties); } return this._parsedProperties; } }; return (owner.onVectorTileClicked({ clickType: info.getClickType(), layer: this._layer.get(), feature: geoFeature, featureId: geoFeature.id, featureData: geoFeature.properties, featureLayerName: geoFeature.layer, featureGeometry: geometry, featureGeometryPosIndex: geoPosIndex, featurePosition: fromNativeMapPos(featurePos), position: fromNativeMapPos(position) }) || false); } return false; }; return NTVectorTileEventListenerImpl; }(AKVectorTileEventListener)); export { NTVectorTileEventListenerImpl }; export class BaseVectorTileLayer extends TileLayer { constructor(options) { super(options); for (const property of ['listener', 'nListener']) { const descriptor = Object.getOwnPropertyDescriptor(BaseVectorTileLayer.prototype, property); if (descriptor) { descriptor.enumerable = false; } } } setVectorTileEventListener(listener, projection, nativeClass = NTVectorTileEventListenerImpl) { this.listener = listener; this.listenerProjection = projection; if (listener) { if (listener instanceof NTVectorTileEventListener) { this.getNative().setVectorTileEventListener(listener); this.nListener = listener; } else { this.nListener = nativeClass.initWithOwner(new WeakRef(listener), new WeakRef(this), projection); this.getNative().setVectorTileEventListener(this.nListener); } } else { this.nListener = null; this.getNative().setVectorTileEventListener(null); } } getTileDecoder() { if (this.options.decoder) { return this.options.decoder; } else { return new MBVectorTileDecoder(undefined, this.getNative().getTileDecoder()); } } } __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "layerBlendingSpeed", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "labelBlendingSpeed", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "tileCacheCapacity", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "clickRadius", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "labelRenderOrder", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "buildingRenderOrder", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "rendererLayerFilter", void 0); __decorate([ nativeProperty ], BaseVectorTileLayer.prototype, "clickHandlerLayerFilter", void 0); export class VectorTileLayer extends BaseVectorTileLayer { createNative(options) { if (!!options.dataSource && !!options.decoder) { const dataSource = options.dataSource.getNative(); const decoder = options.decoder.getNative(); if (dataSource && decoder) { return NTVectorTileLayer.alloc().initWithDataSourceDecoder(dataSource, decoder); } } return null; } } export class BaseVectorLayer extends Layer { constructor(options) { super(options); for (const property of ['elementListener', 'nElementListener']) { const descriptor = Object.getOwnPropertyDescriptor(BaseVectorLayer.prototype, property); if (descriptor) { descriptor.enumerable = false; } } } // setVectorElementEventListener(listener: IVectorElementEventListener) { // initVectorElementEventListener(); // this.getNative().setVectorElementEventListener(new VectorElementEventListener(new WeakRef(listener), new WeakRef(this))); // } setVectorElementEventListener(listener, projection, nativeClass = NTVectorElementEventListenerImpl) { this.elementListener = listener; this.projection = projection; if (listener) { this.nElementListener = nativeClass.initWithOwner(new WeakRef(listener), new WeakRef(this), projection); this.getNative().setVectorElementEventListener(this.nElementListener); } else { this.nElementListener = null; this.getNative().setVectorElementEventListener(null); } } } export class VectorLayer extends BaseVectorLayer { createNative(options) { if (!!options.dataSource) { const dataSource = options.dataSource.getNative(); if (dataSource) { return NTVectorLayer.alloc().initWithDataSource(dataSource); } } return null; } } var NTVectorEditEventListenerImpl = /** @class */ (function (_super) { __extends(NTVectorEditEventListenerImpl, _super); function NTVectorEditEventListenerImpl() { return _super !== null && _super.apply(this, arguments) || this; } NTVectorEditEventListenerImpl.initWithOwner = function (owner) { var delegate = NTVectorEditEventListenerImpl.new(); delegate._owner = owner; return delegate; }; NTVectorEditEventListenerImpl.prototype.onDragEndThreaded = function (dragInfo) { var owner = this._owner.get(); if (owner && owner.onDragEnd) { return owner.onDragEnd.call(owner, { layer: this, element: new VectorElement(undefined, dragInfo.getVectorElement()), position: fromNativeMapPos(dragInfo.getMapPos()), screenPosition: fromNativeScreenPos(dragInfo.getScreenPos()), dragMode: dragInfo.getDragMode() }); } return NTVectorElementDragResult.T_VECTOR_ELEMENT_DRAG_RESULT_IGNORE; }; NTVectorEditEventListenerImpl.prototype.onDragMoveThreaded = function (dragInfo) { var owner = this._owner.get(); if (owner && owner.onDragMove) { return owner.onDragMove.call(owner, { layer: this, element: new VectorElement(undefined, dragInfo.getVectorElement()), position: fromNativeMapPos(dragInfo.getMapPos()), screenPosition: fromNativeScreenPos(dragInfo.getScreenPos()), dragMode: dragInfo.getDragMode() }); } return NTVectorElementDragResult.T_VECTOR_ELEMENT_DRAG_RESULT_IGNORE; }; NTVectorEditEventListenerImpl.prototype.onDragStartThreaded = function (dragInfo) { var owner = this._owner.get(); if (owner && owner.onDragStart) { return owner.onDragStart.call(owner, { layer: this, element: new VectorElement(undefined, dragInfo.getVectorElement()), position: fromNativeMapPos(dragInfo.getMapPos()), screenPosition: fromNativeScreenPos(dragInfo.getScreenPos()), dragMode: dragInfo.getDragMode() }); } return NTVectorElementDragResult.T_VECTOR_ELEMENT_DRAG_RESULT_IGNORE; }; NTVectorEditEventListenerImpl.prototype.onElementDeleteThreaded = function (element) { var owner = this._owner.get(); if (owner && owner.onElementDelete) { var el = new VectorElement(undefined, element); owner.onElementDelete.call(owner, el); } }; NTVectorEditEventListenerImpl.prototype.onElementDeselectedThreaded = function (element) { var owner = this._owner.get(); if (owner && owner.onElementDelete) { var el = new VectorElement(undefined, element); owner.onElementDelete.call(owner, el); } }; NTVectorEditEventListenerImpl.prototype.onElementModifyThreadedGeometry = function (element, geometry) { var owner = this._owner.get(); if (owner && owner.onElementModify) { var el = new VectorElement(undefined, element); owner.onElementModify.call(owner, el, geometry); } }; NTVectorEditEventListenerImpl.prototype.onElementSelectThreaded = function (element) { var owner = this._owner.get(); if (owner && owner.onElementSelect) { var el = new VectorElement(undefined, element); return owner.onElementSelect.call(owner, el); } return true; }; NTVectorEditEventListenerImpl.prototype.onSelectDragPointStyleThreadedDragPointStyle = function (element, dragPointStyle) { var owner = this._owner.get(); if (owner && owner.onElementSelect) { var el = new VectorElement(undefined, element); var styleBuilder = owner.onSelectDragPointStyle.call(owner, el); return styleBuilder ? styleBuilder.buildStyle() : null; } return null; }; return NTVectorEditEventListenerImpl; }(AKVectorEditEventListener)); export class EditableVectorLayer extends BaseVectorLayer { constructor(options) { super(options); for (const property of ['editListener', 'nEditListener']) { const descriptor = Object.getOwnPropertyDescriptor(EditableVectorLayer.prototype, property); if (descriptor) { descriptor.enumerable = false; } } } createNative(options) { if (!!options.dataSource) { const dataSource = options.dataSource.getNative(); if (dataSource) { const result = NTEditableVectorLayer.alloc().initWithDataSource(options.dataSource.getNative()); // result.setVectorEditEventListener(NTVectorEditEventListenerImpl.initWithOwner(new WeakRef(this))); // result.setVectorElementEventListener(NTVectorElementEventListenerImpl.initWithOwner(new WeakRef(this))); return result; } } return null; } setSelectedVectorElement(element) { if (this.native) { this.native.setSelectedVectorElement(element instanceof BaseNative ? element.getNative() : element); } } setVectorEditEventListener(listener, projection) { this.editListener = listener; this.projection = projection; if (listener) { this.nEditListener = NTVectorEditEventListenerImpl.initWithOwner(new WeakRef(listener)); this.getNative().setVectorEditEventListener(this.nEditListener); } else { this.nEditListener = null; this.getNative().setVectorEditEventListener(null); } } } export class ClusteredVectorLayer extends BaseVectorLayer { createNative(options) { return NTClusteredVectorLayer.alloc().initWithDataSourceClusterElementBuilder(options.dataSource.getNative(), options.builder.getNative?.() || options.builder); } expandCluster(element, px) { this.getNative().expandClusterPx(element.getNative(), px); } } __decorate([ nativeProperty ], ClusteredVectorLayer.prototype, "minimumClusterDistance", void 0); __decorate([ nativeProperty ], ClusteredVectorLayer.prototype, "maximumClusterZoom", void 0); __decorate([ nativeProperty({ nativeGetterName: 'isAnimatedClusters' }) ], ClusteredVectorLayer.prototype, "animatedClusters", void 0); //# sourceMappingURL=vector.ios.js.map