UNPKG

@nativescript-community/ui-carto

Version:

NativeScript plugin for CARTO Mobile SDK

187 lines 6.82 kB
import { BaseGeocodingService } from './service.common'; import { toNativeMapPos } from '../core'; import { FeatureCollection } from '../geometry/feature'; import { nativeProperty } from '..'; import { BaseNative } from '../BaseNative'; import { NativeVector } from '../core/index.ios'; export class GeocodingService extends BaseGeocodingService { createNative(options) { return null; } calculateAddresses(options, callback) { const nRequest = NTGeocodingRequest.alloc().initWithProjectionQuery(options.projection.getNative(), options.query); if (options.locationRadius !== undefined) { nRequest.setLocationRadius(options.locationRadius); } if (options.location) { nRequest.setLocation(toNativeMapPos(options.location)); } const vector = this.getNative().calculateAddresses(nRequest); const result = vector ? new GeocodingResultVector(vector) : null; callback(null, result); } } export class ReverseGeocodingService extends BaseGeocodingService { createNative(options) { return null; } calculateAddresses(options, callback) { const nRequest = NTReverseGeocodingRequest.alloc().initWithProjectionLocation(options.projection.getNative(), toNativeMapPos(options.location)); if (options.searchRadius !== undefined) { nRequest.setSearchRadius(options.searchRadius); } const vector = this.getNative().calculateAddresses(nRequest); const result = vector ? new GeocodingResultVector(vector) : null; callback(null, result); } } export class GeocodingResult extends BaseNative { constructor(native) { super(null, native); } getAddress() { return this.native.getAddress(); // return { // street: nResult.getStreet(), // country: nResult.getCountry(), // name: nResult.getName(), // neighbourhood: nResult.getNeighbourhood(), // postcode: nResult.getPostcode(), // houseNumber: nResult.getHouseNumber(), // region: nResult.getRegion(), // locality: nResult.getLocality(), // categories: nativeVectorToArray(nResult.getCategories()) // } as Address; } getRank() { return this.native.getRank(); } getFeatureCollection() { return new FeatureCollection(this.native.getFeatureCollection()); } } export class GeocodingResultVector extends NativeVector { get(index) { return new GeocodingResult(this.native.get(index)); } } export class PeliasOnlineGeocodingService extends GeocodingService { createNative(options) { return NTPeliasOnlineGeocodingService.alloc().initWithApiKey(options.apiKey); } } __decorate([ nativeProperty ], PeliasOnlineGeocodingService.prototype, "autocomplete", void 0); __decorate([ nativeProperty ], PeliasOnlineGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], PeliasOnlineGeocodingService.prototype, "customServiceURL", void 0); export class PeliasOnlineReverseGeocodingService extends ReverseGeocodingService { createNative(options) { return NTPeliasOnlineReverseGeocodingService.alloc().initWithApiKey(options.apiKey); } } __decorate([ nativeProperty ], PeliasOnlineReverseGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], PeliasOnlineReverseGeocodingService.prototype, "customServiceURL", void 0); export class TomTomOnlineGeocodingService extends GeocodingService { createNative(options) { return NTTomTomOnlineGeocodingService.alloc().initWithApiKey(options.apiKey); } } __decorate([ nativeProperty ], TomTomOnlineGeocodingService.prototype, "autocomplete", void 0); __decorate([ nativeProperty ], TomTomOnlineGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], TomTomOnlineGeocodingService.prototype, "customServiceURL", void 0); export class TomTomOnlineReverseGeocodingService extends ReverseGeocodingService { createNative(options) { return NTTomTomOnlineReverseGeocodingService.alloc().initWithApiKey(options.apiKey); } } __decorate([ nativeProperty ], TomTomOnlineReverseGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], TomTomOnlineReverseGeocodingService.prototype, "customServiceURL", void 0); export class MapBoxOnlineGeocodingService extends GeocodingService { createNative(options) { return NTMapBoxOnlineGeocodingService.alloc().initWithAccessToken(options.apiKey); } } __decorate([ nativeProperty ], MapBoxOnlineGeocodingService.prototype, "autocomplete", void 0); __decorate([ nativeProperty ], MapBoxOnlineGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], MapBoxOnlineGeocodingService.prototype, "customServiceURL", void 0); export class MapBoxOnlineReverseGeocodingService extends ReverseGeocodingService { createNative(options) { return NTMapBoxOnlineReverseGeocodingService.alloc().initWithAccessToken(options.apiKey); } } __decorate([ nativeProperty ], MapBoxOnlineReverseGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], MapBoxOnlineReverseGeocodingService.prototype, "customServiceURL", void 0); export class OSMOfflineGeocodingService extends GeocodingService { createNative(options) { return NTOSMOfflineGeocodingService.alloc().initWithPath(options.path); } } __decorate([ nativeProperty ], OSMOfflineGeocodingService.prototype, "autocomplete", void 0); __decorate([ nativeProperty ], OSMOfflineGeocodingService.prototype, "language", void 0); __decorate([ nativeProperty ], OSMOfflineGeocodingService.prototype, "maxResults", void 0); export class OSMOfflineReverseGeocodingService extends ReverseGeocodingService { createNative(options) { return NTOSMOfflineReverseGeocodingService.alloc().initWithPath(options.path); } } __decorate([ nativeProperty ], OSMOfflineReverseGeocodingService.prototype, "language", void 0); export class MultiOSMOfflineGeocodingService extends GeocodingService { createNative(options) { return NTMultiOSMOfflineGeocodingService.alloc().init(); } add(database) { this.getNative().add(database); } remove(database) { this.getNative().remove(database); } } export class MultiOSMOfflineReverseGeocodingService extends ReverseGeocodingService { createNative(options) { return NTMultiOSMOfflineReverseGeocodingService.alloc().init(); } add(database) { this.getNative().add(database); } remove(database) { this.getNative().remove(database); } } //# sourceMappingURL=service.ios.js.map