@nativescript-community/ui-carto
Version:
NativeScript plugin for CARTO Mobile SDK
60 lines • 2.2 kB
JavaScript
import { BaseNative } from '../BaseNative';
import { LatitudeKey, LongitudeKey, MapBounds, fromNativeMapBounds } from '../core';
import { nativeVariantToJS } from '../utils';
export class FeatureCollection extends BaseNative {
constructor(native) {
super(null, native);
}
getFeature(index) {
const nResult = this.native.getFeature(index);
// const nGeo = nResult.getGeometry();
return {
properties: nativeVariantToJS(nResult.getProperties()),
geometry: nResult.getGeometry()
};
}
getGeometry(index) {
return this.native.getFeature(index).getGeometry();
}
getFeatureCount() {
return this.native.getFeatureCount();
}
get featureCount() {
return this.native.getFeatureCount();
}
getBounds() {
let minLat = Number.MAX_SAFE_INTEGER;
let minLon = Number.MAX_SAFE_INTEGER;
let maxLat = -Number.MAX_SAFE_INTEGER;
let maxLon = -Number.MAX_SAFE_INTEGER;
const featureCount = this.featureCount;
for (let index = 0; index < featureCount; index++) {
const geometry = this.getGeometry(index);
const bounds = fromNativeMapBounds(geometry.getBounds());
minLat = Math.min(minLat, bounds.northeast[LatitudeKey]);
minLon = Math.min(minLon, bounds.northeast[LongitudeKey]);
maxLat = Math.max(maxLat, bounds.southwest[LatitudeKey]);
maxLon = Math.max(maxLon, bounds.southwest[LongitudeKey]);
}
return new MapBounds({
[LatitudeKey]: minLat,
[LongitudeKey]: minLon
}, {
[LatitudeKey]: maxLat,
[LongitudeKey]: maxLon
});
}
}
export class VectorTileFeatureCollection extends FeatureCollection {
getFeature(index) {
const nResult = this.native.getFeature(index);
return {
properties: nativeVariantToJS(nResult.getProperties()),
geometry: nResult.getGeometry(),
id: nResult.getId(),
layerName: nResult.getLayerName(),
distance: nResult.getDistance()
};
}
}
//# sourceMappingURL=feature.ios.js.map