UNPKG

@nativescript-community/ui-carto

Version:
376 lines 15.8 kB
import { Layer, TileLayer } from '.'; import { BaseNative, nativeProperty } from '..'; import { fromNativeMapPos, fromNativeScreenPos } from '../core'; import { VectorElement } from '../vectorelements'; import { MBVectorTileDecoder, VectorTileDecoder } from '../vectortiles'; export { VectorTileDecoder }; export const VectorTileRenderOrder = { get HIDDEN() { return com.carto.layers.VectorTileRenderOrder.VECTOR_TILE_RENDER_ORDER_HIDDEN; }, get LAYER() { return com.carto.layers.VectorTileRenderOrder.VECTOR_TILE_RENDER_ORDER_LAYER; }, get LAST() { return com.carto.layers.VectorTileRenderOrder.VECTOR_TILE_RENDER_ORDER_LAST; } }; export const VectorElementDragResult = { get IGNORE() { return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_IGNORE; }, get DELETE() { return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_DELETE; }, get MODIFY() { return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_MODIFY; }, get STOP() { return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_STOP; } }; let geojsonWriter; function getGeojsonWriter() { if (!geojsonWriter) { geojsonWriter = new com.carto.geometry.GeoJSONGeometryWriter(); } return geojsonWriter; } 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 = com.akylas.carto.additions.AKVectorTileEventListener) { this.listener = listener; this.listenerProjection = projection; if (listener) { if (listener instanceof com.carto.layers.VectorTileEventListener) { this.nListener = listener; } else { if (!this.nListener) { this.nListener = new nativeClass(new com.akylas.carto.additions.AKVectorTileEventListener.Listener({ onVectorTileClicked: this.onTileClicked.bind(this) })); } } this.getNative().setVectorTileEventListener(this.nListener); } else { this.nListener = null; this.getNative().setVectorTileEventListener(null); } } onTileClicked(info) { if (this.listener && this.listener.onVectorTileClicked) { const feature = info.getFeature(); const geometry = feature.getGeometry(); let position = info.getClickPos(); const geoPosIndex = info.getFeaturePosIndex(); let featurePos; if (geoPosIndex !== -1 && /MultiPoint/.test(geometry.constructor.name)) { featurePos = geometry.getGeometry(geoPosIndex)?.getCenterPos(); } if (!featurePos) { featurePos = geometry.getCenterPos(); } let projection; const dataSourceProjection = this.getNative().getDataSource().getProjection(); if (this.listenerProjection) { projection = this.listenerProjection.getNative(); featurePos = projection.fromWgs84(dataSourceProjection.toWgs84(featurePos)); position = projection.fromWgs84(dataSourceProjection.toWgs84(position)); } const geoFeature = { feature, id: info.getFeatureId(), layer: info.getFeatureLayerName(), _nativeGeometry: geometry, geoPosIndex, get geometry() { if (!this._parsedGeometry) { const writer = getGeojsonWriter(); writer.setSourceProjection(dataSourceProjection); this._geometry = getGeojsonWriter().writeGeometry(this._nativeGeometry); this._parsedGeometry = JSON.parse(this._geometry); } return this._parsedGeometry; }, get _properties() { return feature.getProperties().toString(); }, get properties() { if (!this._parsedProperties) { this._parsedProperties = JSON.parse(this._properties); } return this._parsedProperties; } }; return (this.listener.onVectorTileClicked.call(this.listener, { clickType: info.getClickType().swigValue(), layer: this, feature: geoFeature, featureId: geoFeature.id, featureData: geoFeature.properties, featureLayerName: geoFeature.layer, featureGeometry: geometry, featureGeometryPosIndex: geoPosIndex, featurePosition: fromNativeMapPos(featurePos), position: fromNativeMapPos(position) }) || false); } return false; } 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 new com.carto.layers.VectorTileLayer(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, projection, nativeClass = com.akylas.carto.additions.AKVectorElementEventListener) { this.elementListener = listener; this.projection = projection; if (listener) { if (!this.nElementListener) { this.nElementListener = new nativeClass(new com.akylas.carto.additions.AKVectorElementEventListener.Listener({ onVectorElementClicked: this.onElementClicked.bind(this) })); } this.getNative().setVectorElementEventListener(this.nElementListener); } else { this.nElementListener = null; this.getNative().setVectorElementEventListener(null); } } onElementClicked(info) { if (this.elementListener && this.elementListener.onVectorElementClicked) { const nElement = info.getVectorElement(); const element = new VectorElement(undefined, nElement); let position = info.getClickPos(); let elementPos = info.getElementClickPos(); if (this.projection) { const layerProj = this.getNative().getDataSource().getProjection(); const nProj = this.projection.getNative(); elementPos = nProj.fromWgs84(layerProj.toWgs84(elementPos)); position = nProj.fromWgs84(layerProj.toWgs84(position)); } return (this.elementListener.onVectorElementClicked.call(this.elementListener, { clickType: info.getClickType().swigValue(), layer: this, element, native: nElement, metaData: element.metaData, position: fromNativeMapPos(position), elementPos: fromNativeMapPos(elementPos) }) || false); } return false; } } export class VectorLayer extends BaseVectorLayer { createNative(options) { if (!!options.dataSource) { const dataSource = options.dataSource.getNative(); if (dataSource) { return new com.carto.layers.VectorLayer(options.dataSource.getNative()); } } return null; } } 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 = new com.carto.layers.EditableVectorLayer(options.dataSource.getNative()); // result.setVectorEditEventListener(VectorEditEventListenerImpl.initWithOwner(new WeakRef(this))); // result.setVectorElementEventListener(VectorElementEventListenerImpl.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, nativeClass = com.akylas.carto.additions.AKVectorEditEventListener) { this.editListener = listener; this.projection = projection; if (listener) { if (!this.nEditListener) { this.nEditListener = new nativeClass(new com.akylas.carto.additions.AKVectorEditEventListener.Listener({ onDragEnd: this.onDragEnd.bind(this), onDragMove: this.onDragMove.bind(this), onDragStart: this.onDragStart.bind(this), onElementDelete: this.onElementDelete.bind(this), onElementDeselected: this.onElementDeselected.bind(this), onElementModify: this.onElementModify.bind(this), onElementSelect: this.onElementSelect.bind(this), onSelectDragPointStyle: this.onSelectDragPointStyle.bind(this) })); } this.getNative().setVectorEditEventListener(this.nEditListener); } else { this.nEditListener = null; this.getNative().setVectorEditEventListener(null); } } onDragEnd(dragInfo) { if (this.editListener && this.editListener.onDragEnd) { return this.editListener.onDragEnd.call(this.editListener, { layer: this, element: new VectorElement(undefined, dragInfo.getVectorElement()), position: fromNativeMapPos(dragInfo.getMapPos()), screenPosition: fromNativeScreenPos(dragInfo.getScreenPos()), dragMode: dragInfo.getDragMode() }); } return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_IGNORE; } onDragMove(dragInfo) { if (this.editListener && this.editListener.onDragMove) { return this.editListener.onDragMove.call(this.editListener, { layer: this, element: new VectorElement(undefined, dragInfo.getVectorElement()), position: fromNativeMapPos(dragInfo.getMapPos()), screenPosition: fromNativeScreenPos(dragInfo.getScreenPos()), dragMode: dragInfo.getDragMode() }); } return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_IGNORE; } onDragStart(dragInfo) { if (this.editListener && this.editListener.onDragStart) { return this.editListener.onDragStart.call(this.editListener, { layer: this, element: new VectorElement(undefined, dragInfo.getVectorElement()), position: fromNativeMapPos(dragInfo.getMapPos()), screenPosition: fromNativeScreenPos(dragInfo.getScreenPos()), dragMode: dragInfo.getDragMode() }); } return com.carto.layers.VectorElementDragResult.VECTOR_ELEMENT_DRAG_RESULT_IGNORE; } onElementDelete(element) { if (this.editListener && this.editListener.onElementDelete) { const el = new VectorElement(undefined, element); this.editListener.onElementDelete.call(this.editListener, el); } } onElementDeselected(element) { if (this.editListener && this.editListener.onElementDelete) { const el = new VectorElement(undefined, element); this.editListener.onElementDelete.call(this.editListener, el); } } onElementModify(element, geometry) { if (this.editListener && this.editListener.onElementModify) { const el = new VectorElement(undefined, element); this.editListener.onElementModify.call(this.editListener, el, geometry); } } onElementSelect(element) { if (this.editListener && this.editListener.onElementSelect) { const el = new VectorElement(undefined, element); return this.editListener.onElementSelect.call(this.editListener, el); } return true; } onSelectDragPointStyle(element, dragPointStyle) { if (this.editListener && this.editListener.onElementSelect) { const el = new VectorElement(undefined, element); const styleBuilder = this.editListener.onSelectDragPointStyle.call(this.editListener, el); return styleBuilder ? styleBuilder.buildStyle() : null; } return null; } } export class ClusteredVectorLayer extends BaseVectorLayer { createNative(options) { return new com.carto.layers.ClusteredVectorLayer(options.dataSource.getNative(), options.builder.getNative?.() || options.builder); } expandCluster(element, px) { this.getNative().expandCluster(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.android.js.map