@benedictstrube/ui-mapbox
Version:
Interactive, thoroughly customizable maps powered by vector tiles and OpenGL.
382 lines • 14.2 kB
JavaScript
import { Color, ContentView, ImageSource, Property, Trace, booleanConverter } from '@nativescript/core';
export * from './geo.utils';
export * from './expression/expression-parser';
export * from './layers/layer-factory';
export * from './layers/parser/property-parser';
export const MapboxTraceCategory = 'NativescriptMapbox';
export var CLogTypes;
(function (CLogTypes) {
CLogTypes[CLogTypes["log"] = Trace.messageType.log] = "log";
CLogTypes[CLogTypes["info"] = Trace.messageType.info] = "info";
CLogTypes[CLogTypes["warning"] = Trace.messageType.warn] = "warning";
CLogTypes[CLogTypes["error"] = Trace.messageType.error] = "error";
})(CLogTypes || (CLogTypes = {}));
export const CLog = (type, ...args) => {
Trace.write(args.map((a) => (a && typeof a === 'object' ? JSON.stringify(a) : a)).join(' '), MapboxTraceCategory, type);
};
export var MapStyle;
(function (MapStyle) {
MapStyle["DARK"] = "dark";
MapStyle["OUTDOORS"] = "outdoors";
MapStyle["LIGHT"] = "light";
MapStyle["SATELLITE"] = "satellite";
MapStyle["SATELLITE_STREETS"] = "satellite_streets";
MapStyle["STREETS"] = "streets";
MapStyle["TRAFFIC_DAY"] = "traffic_day";
MapStyle["TRAFFIC_NIGHT"] = "traffic_night";
})(MapStyle || (MapStyle = {}));
export class MapboxCommon {
constructor(view) {
this.view = view;
}
static merge(obj1, obj2) {
const result = {};
for (const 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 (const i in obj2) {
if (i in result) {
continue;
}
result[i] = obj2[i];
}
return result;
}
async requestFineLocationPermission() { }
async hasFineLocationPermission() {
return true;
}
}
MapboxCommon.defaults = {
style: MapStyle.STREETS.toString(),
mapStyle: MapStyle.STREETS.toString(),
margins: {
left: 0,
right: 0,
top: 0,
bottom: 0
},
zoomLevel: 0,
showUserLocation: false,
locationComponentOptions: {},
hideLogo: false,
hideAttribution: true,
hideCompass: false,
disableRotation: false,
disableScroll: false,
disableZoom: false,
disableTilt: false,
delay: 0
};
export class MapboxViewCommonBase extends ContentView {
onMapEvent(eventName, id, callback) {
return this.mapbox.onMapEvent(eventName, id, callback, this.getNativeMapView());
}
offMapEvent(eventName, id) {
return this.mapbox.offMapEvent(eventName, id, this.getNativeMapView());
}
addMarkers(markers) {
return this.mapbox.addMarkers(markers, this.getNativeMapView());
}
removeMarkers(options) {
return this.mapbox.removeMarkers(options, this.getNativeMapView());
}
setOnMapClickListener(listener) {
return this.mapbox.setOnMapClickListener(listener, this.getNativeMapView());
}
setOnMapLongClickListener(listener) {
return this.mapbox.setOnMapLongClickListener(listener, this.getNativeMapView());
}
setOnScrollListener(listener, nativeMap) {
return this.mapbox.setOnScrollListener(listener, this.getNativeMapView());
}
setOnMoveBeginListener(listener, nativeMap) {
return this.mapbox.setOnMoveBeginListener(listener, this.getNativeMapView());
}
setOnMoveEndListener(listener, nativeMap) {
return this.mapbox.setOnMoveEndListener(listener, this.getNativeMapView());
}
setOnFlingListener(listener, nativeMap) {
return this.mapbox.setOnFlingListener(listener, this.getNativeMapView());
}
setOnCameraMoveListener(listener, nativeMap) {
return this.mapbox.setOnCameraMoveListener(listener, this.getNativeMapView());
}
setOnCameraMoveCancelListener(listener, nativeMap) {
return this.mapbox.setOnCameraMoveCancelListener(listener, this.getNativeMapView());
}
setOnCameraIdleListener(listener, nativeMap) {
return this.mapbox.setOnCameraIdleListener(listener, this.getNativeMapView());
}
getViewport() {
return this.mapbox.getViewport(this.getNativeMapView());
}
setViewport(options) {
return this.mapbox.setViewport(options, this.getNativeMapView());
}
setMapStyle(style) {
return this.mapbox.setMapStyle(style, this.getNativeMapView());
}
getCenter() {
return this.mapbox.getCenter(this.getNativeMapView());
}
setCenter(options) {
return this.mapbox.setCenter(options, this.getNativeMapView());
}
getZoomLevel() {
return this.mapbox.getZoomLevel(this.getNativeMapView());
}
setZoomLevel(options) {
return this.mapbox.setZoomLevel(options, this.getNativeMapView());
}
getTilt() {
return this.mapbox.getTilt(this.getNativeMapView());
}
setTilt(options) {
return this.mapbox.setTilt(options, this.getNativeMapView());
}
getUserLocation() {
return this.mapbox.getUserLocation(this.getNativeMapView());
}
showUserLocationMarker(options) {
this.mapbox.showUserLocationMarker(options, this.getNativeMapView());
}
hideUserLocationMarker() {
this.mapbox.hideUserLocationMarker(this.getNativeMapView());
}
changeUserLocationMarkerMode(renderModeString, cameraModeString) {
this.mapbox.changeUserLocationMarkerMode(renderModeString, cameraModeString, this.getNativeMapView());
}
forceUserLocationUpdate(location) {
this.mapbox.forceUserLocationUpdate(location, this.getNativeMapView());
}
trackUser(options) {
return this.mapbox.trackUser(options, this.getNativeMapView());
}
getUserLocationCameraMode() {
return this.mapbox.getUserLocationCameraMode(this.getNativeMapView());
}
addSource(id, options) {
return this.mapbox.addSource(id, options, this.getNativeMapView());
}
updateSource(id, options) {
return this.mapbox.updateSource(id, options, this.getNativeMapView());
}
removeSource(id) {
return this.mapbox.removeSource(id, this.getNativeMapView());
}
addLayer(style, belowLayerId) {
return this.mapbox.addLayer(style, belowLayerId, this.getNativeMapView());
}
removeLayer(id) {
return this.mapbox.removeLayer(id, this.getNativeMapView());
}
addLinePoint(id, point, sourceId) {
return this.mapbox.addLinePoint(id, point, sourceId, this.getNativeMapView());
}
queryRenderedFeatures(options) {
return this.mapbox.queryRenderedFeatures(options, this.getNativeMapView());
}
querySourceFeatures(sourceId, options) {
return this.mapbox.querySourceFeatures(sourceId, options, this.getNativeMapView());
}
addPolygon(options) {
return this.mapbox.addPolygon(options, this.getNativeMapView());
}
removePolygons(ids) {
return this.mapbox.removePolygons(ids, this.getNativeMapView());
}
addPolyline(options) {
return this.mapbox.addPolyline(options, this.getNativeMapView());
}
removePolylines(ids) {
return this.mapbox.removePolylines(ids, this.getNativeMapView());
}
animateCamera(options) {
return this.mapbox.animateCamera(options, this.getNativeMapView());
}
getLayer(name, nativeMap) {
return this.mapbox.getLayer(name, nativeMap);
}
getLayers(nativeMap) {
return this.mapbox.getLayers(nativeMap);
}
getImage(imageId) {
return this.mapbox.getImage(imageId, this.getNativeMapView());
}
addImage(imageId, image) {
return this.mapbox.addImage(imageId, image, this.getNativeMapView());
}
removeImage(imageId) {
return this.mapbox.removeImage(imageId, this.getNativeMapView());
}
destroy() {
return this.mapbox && this.mapbox.destroy(this.getNativeMapView());
}
onStart() {
return this.mapbox && this.mapbox.onStart(this.getNativeMapView());
}
onResume(nativeMap) {
return this.mapbox && this.mapbox.onResume(this.getNativeMapView());
}
onPause(nativeMap) {
return this.mapbox && this.mapbox.onPause(this.getNativeMapView());
}
onStop(nativeMap) {
return this.mapbox && this.mapbox.onStop(this.getNativeMapView());
}
onLowMemory(nativeMap) {
return this.mapbox.onLowMemory(this.getNativeMapView());
}
onDestroy(nativeMap) {
return this.mapbox && this.mapbox.onDestroy(this.getNativeMapView());
}
project(data) {
return this.mapbox && this.mapbox.project(data);
}
projectBack(screenCoordinate) {
return this.mapbox && this.mapbox.projectBack(screenCoordinate);
}
setScrollingEnabled(enabled, nativeMap) {
return this.mapbox && this.mapbox.setScrollingEnabled(enabled, this.getNativeMapView());
}
}
export const mapReadyProperty = new Property({ name: 'mapReady' });
mapReadyProperty.register(MapboxViewCommonBase);
export const zoomLevelProperty = new Property({ name: 'zoomLevel' });
zoomLevelProperty.register(MapboxViewCommonBase);
export const accessTokenProperty = new Property({ name: 'accessToken' });
accessTokenProperty.register(MapboxViewCommonBase);
export const mapStyleProperty = new Property({ name: 'mapStyle' });
mapStyleProperty.register(MapboxViewCommonBase);
export const latitudeProperty = new Property({ name: 'latitude' });
latitudeProperty.register(MapboxViewCommonBase);
export const longitudeProperty = new Property({ name: 'longitude' });
longitudeProperty.register(MapboxViewCommonBase);
export const showUserLocationProperty = new Property({
name: 'showUserLocation',
defaultValue: MapboxCommon.defaults.showUserLocation,
valueConverter: booleanConverter
});
showUserLocationProperty.register(MapboxViewCommonBase);
export const locationComponentOptionsProperty = new Property({
name: 'locationComponentOptions',
defaultValue: MapboxCommon.defaults.locationComponentOptions
});
locationComponentOptionsProperty.register(MapboxViewCommonBase);
export const hideLogoProperty = new Property({
name: 'hideLogo',
defaultValue: MapboxCommon.defaults.hideLogo,
valueConverter: booleanConverter
});
hideLogoProperty.register(MapboxViewCommonBase);
export const hideAttributionProperty = new Property({
name: 'hideAttribution',
defaultValue: MapboxCommon.defaults.hideAttribution,
valueConverter: booleanConverter
});
hideAttributionProperty.register(MapboxViewCommonBase);
export const telemetryProperty = new Property({
name: 'telemetry',
defaultValue: false,
valueConverter: booleanConverter
});
telemetryProperty.register(MapboxViewCommonBase);
export const hideCompassProperty = new Property({
name: 'hideCompass',
defaultValue: MapboxCommon.defaults.hideCompass,
valueConverter: booleanConverter
});
hideCompassProperty.register(MapboxViewCommonBase);
export const disableZoomProperty = new Property({
name: 'disableZoom',
defaultValue: MapboxCommon.defaults.disableZoom,
valueConverter: booleanConverter
});
disableZoomProperty.register(MapboxViewCommonBase);
export const disableRotationProperty = new Property({
name: 'disableRotation',
defaultValue: MapboxCommon.defaults.disableRotation,
valueConverter: booleanConverter
});
disableRotationProperty.register(MapboxViewCommonBase);
export const disableScrollProperty = new Property({
name: 'disableScroll',
defaultValue: MapboxCommon.defaults.disableScroll,
valueConverter: booleanConverter
});
disableScrollProperty.register(MapboxViewCommonBase);
export const disableTiltProperty = new Property({
name: 'disableTilt',
defaultValue: MapboxCommon.defaults.disableTilt,
valueConverter: booleanConverter
});
disableTiltProperty.register(MapboxViewCommonBase);
export const delayProperty = new Property({ name: 'delay', valueConverter: (v) => parseInt(v, 10) });
delayProperty.register(MapboxViewCommonBase);
export class MapboxViewBase extends MapboxViewCommonBase {
constructor() {
super(...arguments);
this.config = {};
}
[zoomLevelProperty.setNative](value) {
this.config.zoomLevel = +value;
}
[mapStyleProperty.setNative](value) {
this.config.style = value;
this.config.mapStyle = value;
}
[accessTokenProperty.setNative](value) {
this.config.accessToken = value;
}
[delayProperty.setNative](value) {
this.config.delay = value;
}
[latitudeProperty.setNative](value) {
this.config.center = this.config.center || {};
this.config.center.lat = +value;
}
[longitudeProperty.setNative](value) {
this.config.center = this.config.center || {};
this.config.center.lng = +value;
}
[showUserLocationProperty.setNative](value) {
this.config.showUserLocation = value;
}
[locationComponentOptionsProperty.setNative](value) {
this.config.locationComponentOptions = value || {};
}
[hideLogoProperty.setNative](value) {
this.config.hideLogo = value;
}
[hideAttributionProperty.setNative](value) {
this.config.hideAttribution = value;
}
[hideCompassProperty.setNative](value) {
this.config.hideCompass = value;
}
[disableZoomProperty.setNative](value) {
this.config.disableZoom = value;
}
[disableRotationProperty.setNative](value) {
this.config.disableRotation = value;
}
[disableScrollProperty.setNative](value) {
this.config.disableScroll = value;
}
[disableTiltProperty.setNative](value) {
this.config.disableTilt = value;
}
}
MapboxViewBase.mapReadyEvent = 'mapReady';
MapboxViewBase.scrollEvent = 'scrollEvent';
MapboxViewBase.moveBeginEvent = 'moveBeginEvent';
MapboxViewBase.moveEndEvent = 'moveEndEvent';
MapboxViewBase.locationPermissionGrantedEvent = 'locationPermissionGranted';
MapboxViewBase.locationPermissionDeniedEvent = 'locationPermissionDenied';
//# sourceMappingURL=common.js.map