@nativescript/google-maps
Version:
Google Maps SDK
1,291 lines • 61.1 kB
JavaScript
import { Color, GridLayout, ImageSource, Screen, Utils, View } from '@nativescript/core';
import { bearingProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common';
import { deserialize, intoNativeCircleOptions, intoNativeGroundOverlayOptions, intoNativeMarkerOptions, intoNativePolygonOptions, intoNativePolylineOptions, serialize } from './utils';
export { hueFromColor, intoNativeMarkerOptions } from './utils';
const native_ = Symbol('[[native]]');
export class CameraUpdate {
static fromNative(nativeUpdate) {
if (nativeUpdate instanceof GMSCameraUpdate) {
const update = new CameraUpdate();
update._native = nativeUpdate;
return update;
}
return null;
}
static fromCoordinate(coordinate, zoom) {
if (typeof zoom === 'number') {
return CameraUpdate.fromNative(GMSCameraUpdate.setTargetZoom(CLLocationCoordinate2DMake(coordinate.lat, coordinate.lng), zoom));
}
else {
return CameraUpdate.fromNative(GMSCameraUpdate.setTarget(CLLocationCoordinate2DMake(coordinate.lat, coordinate.lng)));
}
}
static fromCoordinates(coordinates, width, height, padding) {
if (!Array.isArray(coordinates)) {
return null;
}
let bounds = GMSCoordinateBounds.new();
coordinates.forEach((coord) => {
bounds = bounds.includingCoordinate(CLLocationCoordinate2DMake(coord.lat, coord.lng));
});
if (arguments.length == 2) {
return CameraUpdate.fromNative(GMSCameraUpdate.fitBoundsWithPadding(bounds, width));
}
else {
/// top, left, bottom, right
const insets = UIEdgeInsetsFromString(`${padding},${padding},${height - padding},${width - padding}`);
return CameraUpdate.fromNative(GMSCameraUpdate.fitBoundsWithEdgeInsets(bounds, insets));
}
}
static fromCameraPosition(position) {
return CameraUpdate.fromNative(GMSCameraUpdate.setCamera(position.native));
}
static zoomIn() {
return CameraUpdate.fromNative(GMSCameraUpdate.zoomIn());
}
static zoomOut() {
return CameraUpdate.fromNative(GMSCameraUpdate.zoomOut());
}
static zoomTo(value) {
return CameraUpdate.fromNative(GMSCameraUpdate.zoomTo(value));
}
static zoomBy(amount, point) {
if (typeof point?.x === 'number' && typeof point.y === 'number') {
return CameraUpdate.fromNative(GMSCameraUpdate.zoomByAtPoint(amount, CGPointMake(point.x, point.y)));
}
else {
return CameraUpdate.fromNative(GMSCameraUpdate.zoomBy(amount));
}
}
static scrollBy(x, y) {
return CameraUpdate.fromNative(GMSCameraUpdate.scrollByXY(x, y));
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
}
export class CameraPosition {
constructor(target, zoom, bearing, tilt) {
if (target && typeof zoom === 'number') {
if (arguments.length === 2) {
this._native = GMSCameraPosition.cameraWithLatitudeLongitudeZoom(target.lat, target.lng, zoom);
}
else {
if (typeof bearing === 'number' && typeof tilt === 'number') {
this._native = GMSCameraPosition.cameraWithLatitudeLongitudeZoomBearingViewingAngle(target.lat, target.lng, zoom, bearing, tilt);
}
else {
const native = GMSCameraPosition.cameraWithLatitudeLongitudeZoom(target.lat, target.lng, zoom);
this._native = GMSCameraPosition.cameraWithTargetZoomBearingViewingAngle(native.target, native.zoom, bearing ?? native.bearing, tilt ?? native.viewingAngle);
}
}
}
}
static fromNative(nativePosition) {
if (nativePosition instanceof GMSCameraPosition) {
const position = new CameraPosition(null, null);
position._native = nativePosition;
return position;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get bearing() {
return this.native.bearing;
}
set bearing(value) {
this._native = GMSCameraPosition.cameraWithTargetZoomBearingViewingAngle(this.native.target, this.native.zoom, value, this.native.viewingAngle);
}
get target() {
return {
lat: this.native.target.latitude,
lng: this.native.target.longitude,
};
}
set target(value) {
this._native = GMSCameraPosition.cameraWithTargetZoomBearingViewingAngle(CLLocationCoordinate2DMake(value.lat, value.lng), this.native.zoom, this.native.bearing, this.native.viewingAngle);
}
get tilt() {
return this.native.viewingAngle;
}
set tilt(value) {
this._native = GMSCameraPosition.cameraWithTargetZoomBearingViewingAngle(this.native.target, this.native.zoom, this.native.bearing, value);
}
get zoom() {
return this.native.zoom;
}
set zoom(value) {
this._native = GMSCameraPosition.cameraWithTargetZoomBearingViewingAngle(this.native.target, value, this.native.bearing, this.native.viewingAngle);
}
toJSON() {
return {
target: this.target,
tilt: this.tilt,
bearing: this.bearing,
zoom: this.zoom,
};
}
}
export class Location {
static fromNative(location) {
if (location instanceof CLLocation) {
const ret = new Location();
ret._native = location;
return ret;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this._native;
}
get altitudeAccuracy() {
return this.native.verticalAccuracy;
}
get accuracy() {
return this.native.horizontalAccuracy;
}
get coordinate() {
return {
lat: this.native.coordinate.latitude,
lng: this.native.coordinate.longitude,
};
}
get timestamp() {
return this.native.timestamp;
}
get altitude() {
return this.native.altitude;
}
get speed() {
return this.native.speed;
}
get heading() {
return this.native.course;
}
}
var GMSMapViewDelegateImpl = /** @class */ (function (_super) {
__extends(GMSMapViewDelegateImpl, _super);
function GMSMapViewDelegateImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
GMSMapViewDelegateImpl_1 = GMSMapViewDelegateImpl;
GMSMapViewDelegateImpl.initWithOwner = function (owner) {
var delegate = GMSMapViewDelegateImpl_1.new();
delegate._owner = owner;
delegate._pendingSnapshotResolveQueue = [];
delegate._pendingSnapshotRejectQueue = [];
return delegate;
};
GMSMapViewDelegateImpl.prototype.didTapMyLocationButtonForMapView = function (mapView) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.myLocationButtonTapEvent,
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
});
return false;
};
GMSMapViewDelegateImpl.prototype.mapViewDidBeginDraggingMarker = function (mapView, marker) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.markerDragStartEvent,
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
marker: Marker.fromNative(marker),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidChangeCameraPosition = function (mapView, position) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.cameraPositionEvent,
state: 'move',
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
cameraPosition: CameraPosition.fromNative(position),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidCloseInfoWindowOfMarker = function (mapView, marker) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.infoWindowCloseEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
marker: Marker.fromNative(marker),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidDragMarker = function (mapView, marker) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.markerDraggingEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
marker: Marker.fromNative(marker),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidEndDraggingMarker = function (mapView, marker) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.markerDragEndEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
marker: Marker.fromNative(marker),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidFinishTileRendering = function (mapView) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.tileRenderingEndEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidLongPressAtCoordinate = function (mapView, coordinate) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.mapLongPressEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
coordinate: {
lat: coordinate.latitude,
lng: coordinate.longitude,
},
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidLongPressInfoWindowOfMarker = function (mapView, marker) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.infoWindowLongPressEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
marker: Marker.fromNative(marker),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidStartTileRendering = function (mapView) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.tileRenderingStartEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidTapAtCoordinate = function (mapView, coordinate) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.mapTapEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
coordinate: {
lat: coordinate.latitude,
lng: coordinate.longitude,
},
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidTapInfoWindowOfMarker = function (mapView, marker) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.infoWindowTapEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
marker: Marker.fromNative(marker),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidTapMarker = function (mapView, marker) {
var _a, _b;
var owner = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a);
if (owner) {
owner.notify({
eventName: MapView.markerTapEvent,
object: owner,
marker: Marker.fromNative(marker),
});
return owner.preventDefaultMarkerTapBehavior;
}
return false;
};
GMSMapViewDelegateImpl.prototype.mapViewDidTapMyLocation = function (mapView, location) {
var _a, _b, _c, _d;
(_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a).notify({
eventName: MapView.myLocationTapEvent,
object: (_d = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c),
location: Location.fromNative(mapView.myLocation),
});
};
GMSMapViewDelegateImpl.prototype.mapViewDidTapOverlay = function (mapView, overlay) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
if (overlay instanceof GMSCircle) {
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.circleTapEvent,
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
circle: Circle.fromNative(overlay),
});
}
else if (overlay instanceof GMSPolygon) {
(_k = (_h = (_g = this._owner) === null || _g === void 0 ? void 0 : _g.get) === null || _h === void 0 ? void 0 : (_j = _h.call(_g)).notify) === null || _k === void 0 ? void 0 : _k.call(_j, {
eventName: MapView.polygonTapEvent,
object: (_m = (_l = this._owner) === null || _l === void 0 ? void 0 : _l.get) === null || _m === void 0 ? void 0 : _m.call(_l),
polygon: Polygon.fromNative(overlay),
});
}
else if (overlay instanceof GMSPolyline) {
(_r = (_p = (_o = this._owner) === null || _o === void 0 ? void 0 : _o.get) === null || _p === void 0 ? void 0 : (_q = _p.call(_o)).notify) === null || _r === void 0 ? void 0 : _r.call(_q, {
eventName: MapView.polylineTapEvent,
object: (_t = (_s = this._owner) === null || _s === void 0 ? void 0 : _s.get) === null || _t === void 0 ? void 0 : _t.call(_s),
polyline: Polyline.fromNative(overlay),
});
}
else if (overlay instanceof GMSGroundOverlay) {
(_x = (_v = (_u = this._owner) === null || _u === void 0 ? void 0 : _u.get) === null || _v === void 0 ? void 0 : (_w = _v.call(_u)).notify) === null || _x === void 0 ? void 0 : _x.call(_w, {
eventName: MapView.groundOverlayTapEvent,
object: (_z = (_y = this._owner) === null || _y === void 0 ? void 0 : _y.get) === null || _z === void 0 ? void 0 : _z.call(_y),
groundOverlay: GroundOverlay.fromNative(overlay),
});
}
};
GMSMapViewDelegateImpl.prototype.mapViewDidTapPOIWithPlaceIDNameLocation = function (mapView, placeID, name, location) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.poiTapEvent,
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
poi: Poi.fromNative(placeID, name, location),
});
};
GMSMapViewDelegateImpl.prototype.mapViewIdleAtCameraPosition = function (mapView, position) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.cameraPositionEvent,
state: 'idle',
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
cameraPosition: CameraPosition.fromNative(position),
});
};
GMSMapViewDelegateImpl.prototype.mapViewMarkerInfoContents = function (mapView, marker) {
var _a, _b, _c, _d, _e;
var owner = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a);
if (owner) {
var event = {
eventName: MapView.markerInfoContentsEvent,
object: owner,
marker: Marker.fromNative(marker),
view: null,
};
owner.notify(event);
if (event.view instanceof View) {
var parent = marker[native_];
var container = marker._view;
if (!parent) {
parent = NSCCustomInfoView.new();
container = new GridLayout();
parent.backgroundColor = UIColor.clearColor;
marker._view = container;
marker[native_] = parent;
container._setupAsRootView({});
container._setupUI({});
container.callLoaded();
parent.addSubview(container.nativeView);
}
else {
if (event.view.parent !== container) {
container.removeChildren();
}
}
if (!event.view.parent) {
container.addChild(event.view);
}
else if (event.view.parent !== container) {
(_e = (_d = (_c = event === null || event === void 0 ? void 0 : event.view) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.removeChild) === null || _e === void 0 ? void 0 : _e.call(_d, event.view);
container.addChild(event.view);
}
var w = Utils.layout.makeMeasureSpec(500 * Screen.mainScreen.scale, Utils.layout.AT_MOST);
var h = Utils.layout.makeMeasureSpec(500 * Screen.mainScreen.scale, Utils.layout.AT_MOST);
var size = View.measureChild(container, event.view, w, h);
View.layoutChild(container, event.view, 0, 0, size.measuredWidth, size.measuredHeight);
parent.frame = CGRectMake(0, 0, size.measuredWidth / Screen.mainScreen.scale, size.measuredHeight / Screen.mainScreen.scale);
return parent;
}
else if (event.view instanceof UIView) {
return event.view;
}
}
return null;
};
GMSMapViewDelegateImpl.prototype.mapViewMarkerInfoWindow = function (mapView, marker) {
var _a, _b, _c, _d, _e;
var owner = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a);
if (owner) {
var event = {
eventName: MapView.markerInfoWindowEvent,
object: owner,
marker: Marker.fromNative(marker),
view: null,
};
owner.notify(event);
if (event.view instanceof View) {
var parent = marker[native_];
var container = marker._view;
if (!parent) {
parent = NSCCustomInfoView.new();
container = new GridLayout();
parent.backgroundColor = UIColor.clearColor;
marker._view = container;
marker[native_] = parent;
container._setupAsRootView({});
container._setupUI({});
container.callLoaded();
parent.addSubview(container.nativeView);
}
else {
if (event.view.parent !== container) {
container.removeChildren();
}
}
if (!event.view.parent) {
container.addChild(event.view);
}
else if (event.view.parent !== container) {
(_e = (_d = (_c = event === null || event === void 0 ? void 0 : event.view) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.removeChild) === null || _e === void 0 ? void 0 : _e.call(_d, event.view);
container.addChild(event.view);
}
var w = Utils.layout.makeMeasureSpec(500 * Screen.mainScreen.scale, Utils.layout.AT_MOST);
var h = Utils.layout.makeMeasureSpec(500 * Screen.mainScreen.scale, Utils.layout.AT_MOST);
var size = View.measureChild(container, event.view, w, h);
View.layoutChild(container, event.view, 0, 0, size.measuredWidth, size.measuredHeight);
parent.frame = CGRectMake(0, 0, size.measuredWidth / Screen.mainScreen.scale, size.measuredHeight / Screen.mainScreen.scale);
return parent;
}
else if (event.view instanceof UIView) {
return event.view;
}
}
return null;
};
GMSMapViewDelegateImpl.prototype.mapViewSnapshotReady = function (mapView) {
if (this._pendingSnapshotResolveQueue.length) {
try {
var format = UIGraphicsImageRendererFormat.defaultFormat();
format.scale = UIScreen.mainScreen.scale;
var renderer = UIGraphicsImageRenderer.alloc().initWithSizeFormat(mapView.frame.size, format);
var image = renderer.imageWithActions(function (ctx) {
mapView.layer.renderInContext(ctx.CGContext);
});
var next = this._pendingSnapshotResolveQueue.shift();
next(new ImageSource(image));
this._pendingSnapshotRejectQueue.shift();
}
catch (e) {
var next = this._pendingSnapshotResolveQueue.shift();
next(e);
this._pendingSnapshotResolveQueue.shift();
}
}
};
GMSMapViewDelegateImpl.prototype.mapViewWillMove = function (mapView, gesture) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.cameraPositionEvent,
state: 'start',
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
cameraPosition: CameraPosition.fromNative(mapView.camera),
isGesture: gesture,
});
};
var GMSMapViewDelegateImpl_1;
GMSMapViewDelegateImpl = GMSMapViewDelegateImpl_1 = __decorate([
ObjCClass(GMSMapViewDelegate)
], GMSMapViewDelegateImpl);
return GMSMapViewDelegateImpl;
}(NSObject));
var GMSIndoorDisplayDelegateImpl = /** @class */ (function (_super) {
__extends(GMSIndoorDisplayDelegateImpl, _super);
function GMSIndoorDisplayDelegateImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
GMSIndoorDisplayDelegateImpl_1 = GMSIndoorDisplayDelegateImpl;
GMSIndoorDisplayDelegateImpl.initWithOwner = function (owner) {
var delegate = GMSIndoorDisplayDelegateImpl_1.new();
delegate._owner = owner;
return delegate;
};
GMSIndoorDisplayDelegateImpl.prototype.didChangeActiveBuilding = function (building) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.activeBuildingEvent,
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
building: IndoorBuilding.fromNative(building),
});
};
GMSIndoorDisplayDelegateImpl.prototype.didChangeActiveLevel = function (level) {
var _a, _b, _c, _d, _e, _f;
(_d = (_b = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : (_c = _b.call(_a)).notify) === null || _d === void 0 ? void 0 : _d.call(_c, {
eventName: MapView.activeLevelEvent,
object: (_f = (_e = this._owner) === null || _e === void 0 ? void 0 : _e.get) === null || _f === void 0 ? void 0 : _f.call(_e),
level: IndoorLevel.fromNative(level),
});
};
var GMSIndoorDisplayDelegateImpl_1;
GMSIndoorDisplayDelegateImpl = GMSIndoorDisplayDelegateImpl_1 = __decorate([
ObjCClass(GMSIndoorDisplayDelegate)
], GMSIndoorDisplayDelegateImpl);
return GMSIndoorDisplayDelegateImpl;
}(NSObject));
var GMSSyncTileLayerImpl = /** @class */ (function (_super) {
__extends(GMSSyncTileLayerImpl, _super);
function GMSSyncTileLayerImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
GMSSyncTileLayerImpl.initWithCallback = function (callback) {
var delegate = GMSSyncTileLayerImpl.new();
delegate._callback = callback;
return delegate;
};
GMSSyncTileLayerImpl.prototype.tileForXYZoom = function (x, y, zoom) {
return this._callback(x, y, zoom).native;
};
return GMSSyncTileLayerImpl;
}(GMSSyncTileLayer));
export class MapView extends MapViewBase {
constructor() {
super(...arguments);
this._isReady = false;
}
static _init() {
if (this._didInit) {
return;
}
const info = NSBundle.mainBundle.pathForResourceOfType('Info', '.plist');
const dict = NSDictionary.dictionaryWithContentsOfFile(info);
const APIKey = dict.objectForKey('TNSGoogleMapsAPIKey');
if (APIKey) {
GMSServices.provideAPIKey(APIKey);
}
else {
console.error('Failed to load APIKey');
}
this._didInit = true;
}
createNativeView() {
MapView._init();
const nativeView = GMSMapView.mapWithFrameCamera(CGRectZero, null);
this._delegate = GMSMapViewDelegateImpl.initWithOwner(new WeakRef(this));
this._indoorDelegate = GMSIndoorDisplayDelegateImpl.initWithOwner(new WeakRef(this));
return nativeView;
}
initNativeView() {
super.initNativeView();
this.nativeView.delegate = this._delegate;
this.nativeView.indoorDisplay.delegate = this._indoorDelegate;
}
disposeNativeView() {
this.nativeView.delegate = null;
this.nativeView.indoorDisplay.delegate = null;
super.disposeNativeView();
}
onLoaded() {
super.onLoaded();
if (!this._isReady) {
this._updateCamera(this.nativeView, {
lat: this.lat,
lng: this.lng,
bearing: this.bearing,
tilt: this.tilt,
zoom: this.zoom,
});
this.notify({
eventName: 'ready',
object: this,
map: GoogleMap.fromNative(this.nativeView),
});
this._isReady = true;
}
}
[latProperty.setNative](value) {
if (this.nativeView) {
this._updateCamera(this.nativeView, {
lat: value,
});
}
}
[lngProperty.setNative](value) {
if (this.nativeView) {
this._updateCamera(this.nativeView, {
lng: value,
});
}
}
[zoomProperty.setNative](value) {
if (this.nativeView) {
this._updateCamera(this.nativeView, {
zoom: value,
});
}
}
[tiltProperty.setNative](value) {
if (this.nativeView) {
this._updateCamera(this.nativeView, {
tilt: value,
});
}
}
[bearingProperty.setNative](value) {
if (this.nativeView) {
this._updateCamera(this.nativeView, {
bearing: value,
});
}
}
_updateCamera(map, owner) {
const googleMap = GoogleMap.fromNative(map);
if (googleMap) {
const position = CameraPosition.fromNative(map.camera);
let changed = false;
if (!Utils.isNullOrUndefined(owner.lat)) {
position.target = {
lat: typeof owner.lat === 'string' ? parseFloat(owner.lat) : owner.lat,
lng: position.target.lng,
};
changed = true;
}
if (!Utils.isNullOrUndefined(owner.lng)) {
position.target = {
lat: position.target.lat,
lng: typeof owner.lng === 'string' ? parseFloat(owner.lng) : owner.lng,
};
changed = true;
}
if (!Utils.isNullOrUndefined(owner.zoom)) {
position.zoom = typeof owner.zoom === 'string' ? parseFloat(owner.zoom) : owner.zoom;
changed = true;
}
if (!Utils.isNullOrUndefined(owner.tilt)) {
position.tilt = typeof owner.tilt === 'string' ? parseFloat(owner.tilt) : owner.tilt;
changed = true;
}
if (!Utils.isNullOrUndefined(owner.bearing)) {
position.bearing = typeof owner.bearing === 'string' ? parseFloat(owner.bearing) : owner.bearing;
changed = true;
}
if (changed) {
googleMap.cameraPosition = position;
}
}
}
onMeasure(widthMeasureSpec, heightMeasureSpec) {
const nativeView = this.nativeView;
if (nativeView) {
const width = Utils.layout.getMeasureSpecSize(widthMeasureSpec);
const height = Utils.layout.getMeasureSpecSize(heightMeasureSpec);
this.setMeasuredDimension(width, height);
}
}
}
MapView._didInit = false;
export class IndoorLevel {
static fromNative(nativeIndoorLevel) {
if (nativeIndoorLevel instanceof GMSIndoorLevel) {
const indoorLevel = new IndoorLevel();
indoorLevel._native = nativeIndoorLevel;
return indoorLevel;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get name() {
return this.native.name;
}
get shortName() {
return this.native.shortName;
}
}
export class IndoorBuilding {
static fromNative(nativeIndoorBuilding) {
if (nativeIndoorBuilding instanceof GMSIndoorBuilding) {
const indoorBuilding = new IndoorBuilding();
indoorBuilding._native = nativeIndoorBuilding;
return indoorBuilding;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get defaultLevelIndex() {
return this.native.defaultLevelIndex;
}
get levels() {
const result = [];
const levels = this.native.levels;
const count = levels?.count || 0;
for (let i = 0; i < count; i++) {
result.push(IndoorLevel.fromNative(levels.objectAtIndex(i)));
}
return result;
}
get underground() {
return this.native.underground;
}
}
export class UISettings {
static fromNative(nativeUiSettings) {
if (nativeUiSettings instanceof GMSUISettings) {
const settings = new UISettings();
settings._native = nativeUiSettings;
return settings;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get zoomGesturesEnabled() {
return this.native.zoomGestures;
}
set zoomGesturesEnabled(value) {
this.native.zoomGestures = value;
}
get tiltGesturesEnabled() {
return this.native.tiltGestures;
}
set tiltGesturesEnabled(value) {
this.native.tiltGestures = value;
}
setAllGesturesEnabled(value) {
this.native.setAllGesturesEnabled(value);
}
get compassEnabled() {
return this.native.compassButton;
}
set compassEnabled(value) {
this.native.compassButton = value;
}
get scrollGesturesEnabledDuringRotateOrZoom() {
return this.native.allowScrollGesturesDuringRotateOrZoom;
}
set scrollGesturesEnabledDuringRotateOrZoom(value) {
this.native.allowScrollGesturesDuringRotateOrZoom = value;
}
get rotateGesturesEnabled() {
return this.native.rotateGestures;
}
set rotateGesturesEnabled(value) {
this.native.rotateGestures = value;
}
get myLocationButtonEnabled() {
return this.native.myLocationButton;
}
set myLocationButtonEnabled(value) {
this.native.myLocationButton = value;
}
get indoorLevelPickerEnabled() {
return this.native.indoorPicker;
}
set indoorLevelPickerEnabled(value) {
this.native.indoorPicker = value;
}
get scrollGesturesEnabled() {
return this.native.scrollGestures;
}
set scrollGesturesEnabled(value) {
this.native.scrollGestures = value;
}
}
export class GoogleMap {
static fromNative(nativeMap) {
if (nativeMap instanceof GMSMapView) {
const map = new GoogleMap();
map._native = nativeMap;
return map;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get buildingsEnabled() {
return this.native.buildingsEnabled;
}
set buildingsEnabled(value) {
this.native.buildingsEnabled = value;
}
get cameraPosition() {
return CameraPosition.fromNative(this.native.camera);
}
set cameraPosition(value) {
this.native.moveCamera(CameraUpdate.fromCameraPosition(value).native);
}
get maxZoomLevel() {
return this.native.maxZoom;
}
set maxZoomLevel(value) {
this.native.setMinZoomMaxZoom(this.native.minZoom, value);
}
get minZoomLevel() {
return this.native.minZoom;
}
set minZoomLevel(value) {
this.native.setMinZoomMaxZoom(value, this.native.maxZoom);
}
get myLocationEnabled() {
return this.native.myLocationEnabled;
}
set myLocationEnabled(value) {
this.native.myLocationEnabled = value;
}
get trafficEnabled() {
return this.native.trafficEnabled;
}
set trafficEnabled(value) {
this.native.trafficEnabled = value;
}
get uiSettings() {
return UISettings.fromNative(this.native.settings);
}
get mapType() {
switch (this.native.mapType) {
case 5 /* GMSMapViewType.kGMSTypeNone */:
return MapType.None;
case 1 /* GMSMapViewType.kGMSTypeNormal */:
return MapType.Normal;
case 2 /* GMSMapViewType.kGMSTypeSatellite */:
return MapType.Satellite;
case 3 /* GMSMapViewType.kGMSTypeTerrain */:
return MapType.Terrain;
case 4 /* GMSMapViewType.kGMSTypeHybrid */:
return MapType.Hybrid;
}
}
set mapType(value) {
switch (value) {
case MapType.None:
this.native.mapType = 5 /* GMSMapViewType.kGMSTypeNone */;
break;
case MapType.Normal:
this.native.mapType = 1 /* GMSMapViewType.kGMSTypeNormal */;
break;
case MapType.Satellite:
this.native.mapType = 2 /* GMSMapViewType.kGMSTypeSatellite */;
break;
case MapType.Terrain:
this.native.mapType = 3 /* GMSMapViewType.kGMSTypeTerrain */;
break;
case MapType.Hybrid:
this.native.mapType = 4 /* GMSMapViewType.kGMSTypeHybrid */;
break;
}
}
get mapStyle() {
return this._mapStyle;
}
set mapStyle(value) {
try {
this._mapStyle = value;
const style = JSON.stringify(value);
this.native.mapStyle = GMSMapStyle.styleWithJSONStringError(style);
}
catch (e) {
console.error(e);
}
}
clear() {
this.native.clear();
}
addMarker(options) {
const marker = Marker.fromNative(intoNativeMarkerOptions(options));
if (options?.userData) {
marker.userData = options.userData;
}
marker.native.map = this.native;
return marker;
}
removeMarker(marker) {
marker.native.map = null;
}
addCircle(options) {
const circle = Circle.fromNative(intoNativeCircleOptions(options));
circle.native.map = this.native;
return circle;
}
addGroundOverlay(options) {
const groundOverlay = GroundOverlay.fromNative(intoNativeGroundOverlayOptions(options));
groundOverlay.native.map = this.native;
return groundOverlay;
}
addPolygon(options) {
const polygon = Polygon.fromNative(intoNativePolygonOptions(options));
polygon.native.map = this.native;
return polygon;
}
addPolyline(options) {
const polyline = Polyline.fromNative(intoNativePolylineOptions(options));
polyline.native.map = this.native;
return polyline;
}
moveCamera(update) {
this.native.moveCamera(update.native);
}
animateCamera(update) {
this.native.animateWithCameraUpdate(update.native);
}
removeCircle(circle) {
circle.native.map = null;
}
removeGroundOverlay(groundOverlay) {
groundOverlay.native.map = null;
}
removePolygon(polygon) {
polygon.native.map = null;
}
removePolyline(polyline) {
polyline.native.map = null;
}
get projection() {
return Projection.fromNative(this.native.projection);
}
snapshot() {
return new Promise((resolve, reject) => {
const delegate = this.native.delegate;
delegate._pendingSnapshotRejectQueue.push(reject);
delegate._pendingSnapshotResolveQueue.push(resolve);
this.native.snapshotViewAfterScreenUpdates(true);
});
}
addTileOverlay(options) {
if (options?.tileProvider?.native) {
if (options?.tileProvider?.native instanceof GMSTileLayer) {
const overlay = TileOverlay.fromNative(options?.tileProvider?.native);
overlay.zIndex = options.zIndex;
overlay.fadeIn = options.fadeIn;
options.tileProvider.native.map = this.native;
overlay.transparency = options.transparency;
return overlay;
}
}
return null;
}
removeTileOverlay(overlay) {
overlay.native.map = null;
}
}
class OverLayBase {
get userData() {
if (this.native.userData instanceof NSDictionary) {
return deserialize(this.native.userData);
}
return {};
}
set userData(data) {
if (data && typeof data === 'object') {
this.native.userData = serialize(data);
}
else {
this.native.userData = null;
}
}
}
export class Marker extends OverLayBase {
constructor() {
super(...arguments);
this._color = new Color('red');
this._visible = true;
this._icon = null;
}
static fromNative(nativeMarker) {
if (nativeMarker instanceof GMSMarker) {
const marker = new Marker();
marker._native = nativeMarker;
marker._icon = new ImageSource();
return marker;
}
return null;
}
get color() {
return this._color;
}
set color(value) {
if (value instanceof Color) {
this._color = value;
this.native.icon = GMSMarker.markerImageWithColor(value.ios);
}
else if (typeof value === 'string') {
this._color = new Color(value);
this.native.icon = GMSMarker.markerImageWithColor(this._color.ios);
}
}
get opacity() {
return this.native.opacity;
}
set opacity(value) {
this.native.opacity = value;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get icon() {
if (this._icon?.ios === this.native.icon) {
return this._icon;
}
else if (this.native.icon) {
this._icon.setNativeSource(this.native.icon);
}
return this._icon;
}
set icon(value) {
if (value instanceof UIImage) {
this.native.icon = value;
this._icon.setNativeSource(value);
}
else if (value instanceof ImageSource) {
this._icon = value;
this.native.icon = value.ios;
}
}
get draggable() {
return this.native.draggable;
}
set draggable(value) {
this.native.draggable = value;
}
get position() {
return {
lat: this.native.position.latitude,
lng: this.native.position.longitude,
};
}
set position(latlng) {
this.native.position = CLLocationCoordinate2DMake(latlng.lat, latlng.lng);
}
get title() {
return this.native.title;
}
set title(value) {
this.native.title = value;
}
get snippet() {
return this.native.snippet;
}
set snippet(value) {
this.native.snippet = value;
}
get rotation() {
return this.native.rotation;
}
set rotation(value) {
this.native.rotation = value;
}
get visible() {
return this._visible;
}
set visible(value) {
this._visible = value;
this.native.opacity = this.visible ? 1 : 0;
}
get flat() {
return this.native.flat;
}
set flat(value) {
this.native.flat = value;
}
set zIndex(value) {
this.native.zIndex = value;
}
get zIndex() {
return this.native.zIndex;
}
hideInfoWindow() {
const map = this.native.map;
if (map?.selectedMarker === this.native) {
map.selectedMarker = null;
}
}
showInfoWindow() {
const map = this.native.map;
if (map) {
map.selectedMarker = this.native;
}
}
}
export class Circle extends OverLayBase {
static fromNative(nativeCircle) {
if (nativeCircle instanceof GMSCircle) {
const circle = new Circle();
circle._native = nativeCircle;
return circle;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get radius() {
return this.native.radius;
}
set radius(value) {
this.native.radius = value;
}
get strokeColor() {
return Color.fromIosColor(this.native.strokeColor);
}
set strokeColor(value) {
if (value instanceof Color) {
this.native.strokeColor = value.ios;
}
else if (typeof value === 'string') {
this.native.strokeColor = new Color(value).ios;
}
}
get center() {
const center = this.native.position;
return {
lat: center.latitude,
lng: center.longitude,
};
}
set center(value) {
this.native.position = CLLocationCoordinate2DMake(value.lat, value.lng);
}
get fillColor() {
return Color.fromIosColor(this.native.fillColor);
}
set fillColor(value) {
if (value instanceof Color) {
this.native.fillColor = value.ios;
}
else if (typeof value === 'string') {
this.native.fillColor = new Color(value).ios;
}
}
get tappable() {
return this.native.tappable;
}
set tappable(value) {
this.native.tappable = value;
}
get strokeWidth() {
return this.native.strokeWidth;
}
set strokeWidth(value) {
this.native.strokeWidth = value;
}
get zIndex() {
return this.native.zIndex;
}
set zIndex(value) {
this.native.zIndex = value;
}
}
export class Polygon extends OverLayBase {
static fromNative(nativePolygon) {
if (nativePolygon instanceof GMSPolygon) {
const polygon = new Polygon();
polygon._native = nativePolygon;
return polygon;
}
return null;
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get points() {
const path = this.native.path;
const count = path?.count?.() || 0;
const points = [];
for (let i = 0; i < count; i++) {
const point = path.coordinateAtIndex(i);
points.push({
lat: point.latitude,
lng: point.longitude,
});
}
return points;
}
set points(value) {
const points = GMSMutablePath.path();
if (Array.isArray(value)) {
value.forEach((point) => {
points.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
});
}
this.native.path = points;
}
addPoint(point) {
const path = GMSMutablePath.alloc().initWithPath(this.native.path);
path.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
this.native.path = path;
}
addPoints(points) {
const path = GMSMutablePath.alloc().initWithPath(this.native.path);
points.forEach((point) => {
path.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
});
this.native.path = path;
}
get holes() {
const nativeHoles = this.native?.holes;
const count = nativeHoles?.count || 0;
const holes = [];
for (let i = 0; i < count; i++) {
const nativeHole = nativeHoles.objectAtIndex(i);
const hole = [];
for (let j = 0; j < nativeHole.count(); j++) {
const coord = nativeHole.coordinateAtIndex(j);
hole.push({
lat: coord.latitude,
lng: coord.longitude,
});
}
holes.push(hole);
}
return holes;
}
set holes(value) {
const nativeHoles = [];
if (Array.isArray(value)) {
value.forEach((hole) => {
if (Array.isArray(hole) && hole.length) {
const path = GMSMutablePath.path();
hole.forEach((coordinate) => {
path.addCoordinate(CLLocationCoordinate2DMake(coordinate.lat, coordinate.lng));
});
nativeHoles.push(path);
}
});
}
this.native.holes = nativeHoles;
}
get tappable() {
return this.native.tappable;
}
set tappable(value) {
this.native.tappable = value;
}
get strokeWidth() {
return this.native.strokeWidth;
}
set strokeWidth(value) {
this.native.strokeWidth = value;
}
get strokeColor() {
return Color.fromIosColor(this.native.strokeColor);
}
set strokeColor(value) {
if (value