UNPKG

nativescript-mapbox-enduco

Version:
415 lines (414 loc) 19.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MapboxViewBase = exports.delayProperty = exports.disableTiltProperty = exports.disableScrollProperty = exports.disableRotationProperty = exports.disableZoomProperty = exports.hideCompassProperty = exports.hideAttributionProperty = exports.hideLogoProperty = exports.showUserLocationProperty = exports.longitudeProperty = exports.latitudeProperty = exports.mapStyleProperty = exports.accessTokenProperty = exports.zoomLevelProperty = exports.mapReadyProperty = exports.MapboxViewCommonBase = exports.MapboxCommon = exports.MapStyle = void 0; var content_view_1 = require("tns-core-modules/ui/content-view"); var view_1 = require("tns-core-modules/ui/core/view"); var MapStyle; (function (MapStyle) { MapStyle[MapStyle["DARK"] = "dark"] = "DARK"; MapStyle[MapStyle["OUTDOORS"] = "outdoors"] = "OUTDOORS"; MapStyle[MapStyle["LIGHT"] = "light"] = "LIGHT"; MapStyle[MapStyle["SATELLITE"] = "satellite"] = "SATELLITE"; MapStyle[MapStyle["SATELLITE_STREETS"] = "satellite_streets"] = "SATELLITE_STREETS"; MapStyle[MapStyle["STREETS"] = "streets"] = "STREETS"; MapStyle[MapStyle["TRAFFIC_DAY"] = "traffic_day"] = "TRAFFIC_DAY"; MapStyle[MapStyle["TRAFFIC_NIGHT"] = "traffic_night"] = "TRAFFIC_NIGHT"; })(MapStyle = exports.MapStyle || (exports.MapStyle = {})); var MapboxCommon = (function () { function MapboxCommon() { } MapboxCommon.merge = function (obj1, obj2) { var result = {}; for (var i in obj1) { if ((i in obj2) && (typeof obj1[i] === "object") && (i !== null)) { result[i] = this.merge(obj1[i], obj2[i]); } else { result[i] = obj1[i]; } } for (var i in obj2) { if (i in result) { continue; } result[i] = obj2[i]; } return result; }; MapboxCommon.prototype.requestFineLocationPermission = function () { return new Promise(function (resolve) { resolve(); }); }; MapboxCommon.prototype.hasFineLocationPermission = function () { return new Promise(function (resolve) { resolve(true); }); }; MapboxCommon.defaults = { style: MapStyle.STREETS.toString(), mapStyle: MapStyle.STREETS.toString(), margins: { left: 0, right: 0, top: 0, bottom: 0 }, zoomLevel: 0, showUserLocation: false, hideLogo: false, hideAttribution: true, hideCompass: false, disableRotation: false, disableScroll: false, disableZoom: false, disableTilt: false, delay: 0 }; return MapboxCommon; }()); exports.MapboxCommon = MapboxCommon; var MapboxViewCommonBase = (function (_super) { __extends(MapboxViewCommonBase, _super); function MapboxViewCommonBase() { return _super !== null && _super.apply(this, arguments) || this; } MapboxViewCommonBase.prototype.onMapEvent = function (eventName, id, callback) { console.log("MapboxViewCommonBase:on(): top"); return this.mapbox.onMapEvent(eventName, id, callback, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.offMapEvent = function (eventName, id) { return this.mapbox.offMapEvent(eventName, id, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.addMarkers = function (markers) { return this.mapbox.addMarkers(markers, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.removeMarkers = function (options) { return this.mapbox.removeMarkers(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnMapClickListener = function (listener) { return this.mapbox.setOnMapClickListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnMapLongClickListener = function (listener) { return this.mapbox.setOnMapLongClickListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnScrollListener = function (listener, nativeMap) { return this.mapbox.setOnScrollListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnMoveBeginListener = function (listener, nativeMap) { return this.mapbox.setOnMoveBeginListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnFlingListener = function (listener, nativeMap) { return this.mapbox.setOnFlingListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnCameraMoveListener = function (listener, nativeMap) { return this.mapbox.setOnCameraMoveListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnCameraMoveCancelListener = function (listener, nativeMap) { return this.mapbox.setOnCameraMoveCancelListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setOnCameraIdleListener = function (listener, nativeMap) { return this.mapbox.setOnCameraIdleListener(listener, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getViewport = function () { return this.mapbox.getViewport(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setViewport = function (options) { return this.mapbox.setViewport(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setMapStyle = function (style) { return this.mapbox.setMapStyle(style, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getCenter = function () { return this.mapbox.getCenter(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setCenter = function (options) { return this.mapbox.setCenter(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getZoomLevel = function () { return this.mapbox.getZoomLevel(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setZoomLevel = function (options) { return this.mapbox.setZoomLevel(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getTilt = function () { return this.mapbox.getTilt(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setTilt = function (options) { return this.mapbox.setTilt(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getUserLocation = function () { return this.mapbox.getUserLocation(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.showUserLocationMarker = function (options) { this.mapbox.showUserLocationMarker(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.hideUserLocationMarker = function () { this.mapbox.hideUserLocationMarker(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.changeUserLocationMarkerMode = function (renderModeString, cameraModeString) { this.mapbox.changeUserLocationMarkerMode(renderModeString, cameraModeString, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.forceUserLocationUpdate = function (location) { this.mapbox.forceUserLocationUpdate(location, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.trackUser = function (options) { return this.mapbox.trackUser(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getTrackingMode = function () { return this.mapbox.getTrackingMode(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.addSource = function (id, options) { return this.mapbox.addSource(id, options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.removeSource = function (id) { return this.mapbox.removeSource(id, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.addLayer = function (style) { return this.mapbox.addLayer(style, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.removeLayer = function (id) { return this.mapbox.removeLayer(id, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.addLinePoint = function (id, point) { return this.mapbox.addLinePoint(id, point, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.queryRenderedFeatures = function (options) { return this.mapbox.queryRenderedFeatures(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.addPolygon = function (options) { return this.mapbox.addPolygon(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.removePolygons = function (ids) { return this.mapbox.removePolygons(ids, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.addPolyline = function (options) { return this.mapbox.addPolyline(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.removePolylines = function (ids) { this.mapbox.removePolylines(ids, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.updatePolyline = function (id, newPoints) { this.mapbox.updatePolyline(id, newPoints, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.animateCamera = function (options) { return this.mapbox.animateCamera(options, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.destroy = function () { return this.mapbox.destroy(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.onStart = function () { return this.mapbox.onStart(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.onResume = function (nativeMap) { console.log("MapboxViewCommonBase:onResume(): with nativeView:", this.getNativeMapView()); return this.mapbox.onResume(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.onPause = function (nativeMap) { console.log("MapboxViewCommonBase:onPause(): with nativeView:", this.getNativeMapView()); return this.mapbox.onPause(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.onStop = function (nativeMap) { return this.mapbox.onStop(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.onLowMemory = function (nativeMap) { return this.mapbox.onLowMemory(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.onDestroy = function (nativeMap) { return this.mapbox.onDestroy(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.convertToMapCoordinate = function (point) { return this.mapbox.convertToMapCoordinate(point, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.isScrollingEnabled = function () { return this.mapbox.isScrollingEnabled(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.setScrollingEnabled = function (enabled) { return this.mapbox.setScrollingEnabled(enabled, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.convertToOnScreenCoordinate = function (coordinate) { return this.mapbox.convertToOnScreenCoordinate(coordinate, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getDistanceBetween = function (from, to) { return this.mapbox.getDistanceBetween(from, to, this.getNativeMapView()); }; MapboxViewCommonBase.prototype.takeSnapshot = function () { return this.mapbox.takeSnapshot(this.getNativeMapView()); }; MapboxViewCommonBase.prototype.getPixelDistanceBetween = function (from, to) { var _this = this; return new Promise(function (resolve, reject) { try { _this.convertToOnScreenCoordinate(from) .then(function (a) { _this.convertToOnScreenCoordinate(to) .then(function (b) { var dx = a.x - b.x; var dy = a.y - b.y; resolve(Math.sqrt(dx * dx + dy * dy)); }); }); } catch (ex) { console.log("Error in mapbox.getPixelDistanceBetween: " + ex); reject(ex); } }); }; MapboxViewCommonBase.prototype.getCoordinateRegionAroundPoint = function (around, pixelDistance) { var _this = this; return new Promise(function (resolve, reject) { try { var min = { x: around.x - pixelDistance, y: around.y - pixelDistance }; var max_1 = { x: around.x + pixelDistance, y: around.y + pixelDistance }; _this.convertToMapCoordinate(min).then(function (minCoord) { _this.convertToMapCoordinate(max_1).then(function (maxCoord) { resolve({ minLat: Math.min(minCoord.lat, maxCoord.lat), maxLat: Math.max(minCoord.lat, maxCoord.lat), minLng: Math.min(minCoord.lng, maxCoord.lng), maxLng: Math.max(minCoord.lng, maxCoord.lng), }); }); }); } catch (ex) { console.log("Error in mapbox.getCoordinateRegionAroundPoint: " + ex); reject(ex); } }); }; return MapboxViewCommonBase; }(content_view_1.ContentView)); exports.MapboxViewCommonBase = MapboxViewCommonBase; exports.mapReadyProperty = new view_1.Property({ name: "mapReady" }); exports.mapReadyProperty.register(MapboxViewCommonBase); exports.zoomLevelProperty = new view_1.Property({ name: "zoomLevel" }); exports.zoomLevelProperty.register(MapboxViewCommonBase); exports.accessTokenProperty = new view_1.Property({ name: "accessToken" }); exports.accessTokenProperty.register(MapboxViewCommonBase); exports.mapStyleProperty = new view_1.Property({ name: "mapStyle" }); exports.mapStyleProperty.register(MapboxViewCommonBase); exports.latitudeProperty = new view_1.Property({ name: "latitude" }); exports.latitudeProperty.register(MapboxViewCommonBase); exports.longitudeProperty = new view_1.Property({ name: "longitude" }); exports.longitudeProperty.register(MapboxViewCommonBase); exports.showUserLocationProperty = new view_1.Property({ name: "showUserLocation", defaultValue: MapboxCommon.defaults.showUserLocation, valueConverter: view_1.booleanConverter }); exports.showUserLocationProperty.register(MapboxViewCommonBase); exports.hideLogoProperty = new view_1.Property({ name: "hideLogo", defaultValue: MapboxCommon.defaults.hideLogo, valueConverter: view_1.booleanConverter }); exports.hideLogoProperty.register(MapboxViewCommonBase); exports.hideAttributionProperty = new view_1.Property({ name: "hideAttribution", defaultValue: MapboxCommon.defaults.hideAttribution, valueConverter: view_1.booleanConverter }); exports.hideAttributionProperty.register(MapboxViewCommonBase); exports.hideCompassProperty = new view_1.Property({ name: "hideCompass", defaultValue: MapboxCommon.defaults.hideCompass, valueConverter: view_1.booleanConverter }); exports.hideCompassProperty.register(MapboxViewCommonBase); exports.disableZoomProperty = new view_1.Property({ name: "disableZoom", defaultValue: MapboxCommon.defaults.disableZoom, valueConverter: view_1.booleanConverter }); exports.disableZoomProperty.register(MapboxViewCommonBase); exports.disableRotationProperty = new view_1.Property({ name: "disableRotation", defaultValue: MapboxCommon.defaults.disableRotation, valueConverter: view_1.booleanConverter }); exports.disableRotationProperty.register(MapboxViewCommonBase); exports.disableScrollProperty = new view_1.Property({ name: "disableScroll", defaultValue: MapboxCommon.defaults.disableScroll, valueConverter: view_1.booleanConverter }); exports.disableScrollProperty.register(MapboxViewCommonBase); exports.disableTiltProperty = new view_1.Property({ name: "disableTilt", defaultValue: MapboxCommon.defaults.disableTilt, valueConverter: view_1.booleanConverter }); exports.disableTiltProperty.register(MapboxViewCommonBase); exports.delayProperty = new view_1.Property({ name: "delay" }); exports.delayProperty.register(MapboxViewCommonBase); var MapboxViewBase = (function (_super) { __extends(MapboxViewBase, _super); function MapboxViewBase() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.config = {}; return _this; } MapboxViewBase.prototype[exports.zoomLevelProperty.setNative] = function (value) { this.config.zoomLevel = +value; }; MapboxViewBase.prototype[exports.mapStyleProperty.setNative] = function (value) { console.log("MapboxViewBase::mapStyle.setNative(): setting value '" + value + "'"); this.config.style = value; this.config.mapStyle = value; }; MapboxViewBase.prototype[exports.accessTokenProperty.setNative] = function (value) { console.log("MapboxViewBase::accessTokenProperty.setNative(): setting value '" + value + "'"); this.config.accessToken = value; }; MapboxViewBase.prototype[exports.delayProperty.setNative] = function (value) { this.config.delay = parseInt("" + value); }; MapboxViewBase.prototype[exports.latitudeProperty.setNative] = function (value) { this.config.center = this.config.center || {}; this.config.center.lat = +value; }; MapboxViewBase.prototype[exports.longitudeProperty.setNative] = function (value) { this.config.center = this.config.center || {}; this.config.center.lng = +value; }; MapboxViewBase.prototype[exports.showUserLocationProperty.setNative] = function (value) { this.config.showUserLocation = value; }; MapboxViewBase.prototype[exports.hideLogoProperty.setNative] = function (value) { this.config.hideLogo = value; }; MapboxViewBase.prototype[exports.hideAttributionProperty.setNative] = function (value) { this.config.hideAttribution = value; }; MapboxViewBase.prototype[exports.hideCompassProperty.setNative] = function (value) { this.config.hideCompass = value; }; MapboxViewBase.prototype[exports.disableZoomProperty.setNative] = function (value) { this.config.disableZoom = value; }; MapboxViewBase.prototype[exports.disableRotationProperty.setNative] = function (value) { this.config.disableRotation = value; }; MapboxViewBase.prototype[exports.disableScrollProperty.setNative] = function (value) { this.config.disableScroll = value; this.setScrollingEnabled(value); }; MapboxViewBase.prototype[exports.disableTiltProperty.setNative] = function (value) { this.config.disableTilt = value; }; MapboxViewBase.mapReadyEvent = "mapReady"; MapboxViewBase.scrollEvent = "scrollEvent"; MapboxViewBase.moveBeginEvent = "moveBeginEvent"; MapboxViewBase.locationPermissionGrantedEvent = "locationPermissionGranted"; MapboxViewBase.locationPermissionDeniedEvent = "locationPermissionDenied"; return MapboxViewBase; }(MapboxViewCommonBase)); exports.MapboxViewBase = MapboxViewBase;