Skip to content

Commit

Permalink
feat(google-maps): expose addPoint, addPoints & a mapLoaded event
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz authored and NathanWalker committed Sep 27, 2023
1 parent b1cedcf commit 30e5474
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 159 deletions.
108 changes: 53 additions & 55 deletions packages/google-maps/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,81 @@ import { ContentView, Property } from '@nativescript/core';
import { Coordinate } from '.';

export enum MapType {
None = 'none',
Normal = 'normal',
Satellite = 'satellite',
Terrain = 'terrain',
Hybrid = 'hybrid'
None = 'none',
Normal = 'normal',
Satellite = 'satellite',
Terrain = 'terrain',
Hybrid = 'hybrid',
}

export enum JointType {
Round = 'round',
Bevel = 'bevel',
Default = 'default'
Round = 'round',
Bevel = 'bevel',
Default = 'default',
}

export const latProperty = new Property<MapViewBase, number>({
name: "lat"
name: 'lat',
});

export const lngProperty = new Property<MapViewBase, number>({
name: "lng"
name: 'lng',
});

export const zoomProperty = new Property<MapViewBase, number>({
name: "zoom"
name: 'zoom',
});

export const bearingProperty = new Property<MapViewBase, number>({
name: 'bearing'
})
name: 'bearing',
});

export const tiltProperty = new Property<MapViewBase, number>({
name: 'tilt'
})
name: 'tilt',
});

export class MapViewBase extends ContentView {
static readyEvent = 'ready';
static mapTapEvent = 'mapTap';
static mapLongPressEvent = 'mapLongPress';
static markerTapEvent = 'markerTap';
static myLocationTapEvent = 'myLocationTap';
static myLocationButtonTapEvent = 'myLocationButtonTap';
static markerDragStartEvent = 'markerDragStart';
static markerDraggingEvent = 'markerDragging';
static markerDragEndEvent = 'markerDragEnd';

static tileRenderingStartEvent = 'tileRenderingStart';
static tileRenderingEndEvent = 'tileRenderingEnd';


static cameraPositionEvent = 'cameraPosition';

static circleTapEvent = 'circle';
static polygonTapEvent = 'polygon';
static polylineTapEvent = 'polyline';
static poiTapEvent = 'poi';
static groundOverlayTapEvent = 'groundOverlay';

static infoWindowTapEvent = 'infoWindowTap';
static infoWindowLongPressEvent = 'infoWindowLongPress';
static infoWindowCloseEvent = 'infoWindowClose';

static markerInfoContentsEvent = 'markerInfoContents';
static markerInfoWindowEvent = 'markerInfoWindow';


static activeBuildingEvent = 'activeBuilding';
static activeLevelEvent = 'activeLevel';

lat: number;
lng: number;
zoom: number;
bearing: number;
tilt: number;

static readyEvent = 'ready';
static mapTapEvent = 'mapTap';
static mapLoadedEvent = 'mapLoaded';
static mapLongPressEvent = 'mapLongPress';
static markerTapEvent = 'markerTap';
static myLocationTapEvent = 'myLocationTap';
static myLocationButtonTapEvent = 'myLocationButtonTap';
static markerDragStartEvent = 'markerDragStart';
static markerDraggingEvent = 'markerDragging';
static markerDragEndEvent = 'markerDragEnd';

static tileRenderingStartEvent = 'tileRenderingStart';
static tileRenderingEndEvent = 'tileRenderingEnd';

static cameraPositionEvent = 'cameraPosition';

static circleTapEvent = 'circle';
static polygonTapEvent = 'polygon';
static polylineTapEvent = 'polyline';
static poiTapEvent = 'poi';
static groundOverlayTapEvent = 'groundOverlay';

static infoWindowTapEvent = 'infoWindowTap';
static infoWindowLongPressEvent = 'infoWindowLongPress';
static infoWindowCloseEvent = 'infoWindowClose';

static markerInfoContentsEvent = 'markerInfoContents';
static markerInfoWindowEvent = 'markerInfoWindow';

static activeBuildingEvent = 'activeBuilding';
static activeLevelEvent = 'activeLevel';

lat: number;
lng: number;
zoom: number;
bearing: number;
tilt: number;
}

latProperty.register(MapViewBase);
lngProperty.register(MapViewBase);
zoomProperty.register(MapViewBase);
bearingProperty.register(MapViewBase);
tiltProperty.register(MapViewBase);
tiltProperty.register(MapViewBase);
36 changes: 35 additions & 1 deletion packages/google-maps/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ export class MapView extends MapViewBase {
(<any>org).nativescript.plugins.google_maps.GoogleMaps.registerMapListeners(
map,
new (<any>org).nativescript.plugins.google_maps.GoogleMaps.Callback({
onMapLoaded() {
ref?.get?.().notify({
eventName: MapView.mapLoadedEvent,
object: ref?.get?.(),
});
},
onCameraEvent(position: com.google.android.gms.maps.model.CameraPosition, event: string, isGesture: boolean) {
if (event === 'start') {
ref?.get?.().notify(<CameraPositionStartEvent>{
Expand Down Expand Up @@ -1356,6 +1362,20 @@ export class Polygon extends OverLayBase implements IPolygon {
}
}

addPoint(point: Coordinate) {
const points = this.native.getPoints();
points.add(new com.google.android.gms.maps.model.LatLng(point.lat, point.lng));
this.native.setPoints(points);
}

addPoints(points: Coordinate[]) {
const nativePoints = this.native.getPoints();
points.forEach((point) => {
nativePoints.add(new com.google.android.gms.maps.model.LatLng(point.lat, point.lng));
});
this.native.setPoints(nativePoints);
}

get holes(): Coordinate[][] {
const array: androidNative.Array<java.util.List<com.google.android.gms.maps.model.LatLng>> = this.native.getHoles().toArray();
const holes: Coordinate[][] = [];
Expand Down Expand Up @@ -1528,6 +1548,20 @@ export class Polyline extends OverLayBase implements IPolyline {
}
}

addPoint(point: Coordinate) {
const points = this.native.getPoints();
points.add(new com.google.android.gms.maps.model.LatLng(point.lat, point.lng));
this.native.setPoints(points);
}

addPoints(points: Coordinate[]) {
const nativePoints = this.native.getPoints();
points.forEach((point) => {
nativePoints.add(new com.google.android.gms.maps.model.LatLng(point.lat, point.lng));
});
this.native.setPoints(nativePoints);
}

get tappable(): boolean {
return this.native.isClickable();
}
Expand Down Expand Up @@ -1884,7 +1918,7 @@ export class UrlTileProvider extends TileProvider {
// @ts-ignore
_callback: (x: number, y: number, zoom: number) => string;

constructor(callback: (x: number, y: number, zoom: number) => string, size: number = 256) {
constructor(callback: (x: number, y: number, zoom: number) => string, size = 256) {
super(null);
this._callback = callback;
const ref = new WeakRef(this);
Expand Down
7 changes: 7 additions & 0 deletions packages/google-maps/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ export class Polygon implements IPolygon {
geodesic: boolean;
holes: Coordinate[][];
points: Coordinate[];
addPoint(point: Coordinate);
addPoints(points: Coordinate[]);
strokeColor: Color | string;
strokeJointType: JointType;
strokePattern: Array<PatternItem & Partial<NativeObject>>;
Expand Down Expand Up @@ -553,6 +555,11 @@ export class Polyline extends NativeObject implements IPolyline {
* not closed by default; to form a closed polyline, the start and end points must be the same.
*/
points: Coordinate[];

addPoint(point: Coordinate);

addPoints(points: Coordinate[]);

/**
* If you want to handle events fired when the user clicks the polyline, set this property to
* `true`. You can change this value at any time. The default is `false`.
Expand Down
30 changes: 29 additions & 1 deletion packages/google-maps/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,20 @@ export class Polygon extends OverLayBase implements IPolygon {
this.native.path = points;
}

addPoint(point: Coordinate) {
const path = GMSMutablePath.alloc().initWithPath(this.native.path);
path.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
this.native.path = path;
}

addPoints(points: Coordinate[]) {
const path = GMSMutablePath.alloc().initWithPath(this.native.path);
points.forEach((point) => {
path.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
});
this.native.path = path;
}

get holes(): Coordinate[][] {
const nativeHoles = this.native?.holes;
const count = nativeHoles?.count || 0;
Expand Down Expand Up @@ -1487,6 +1501,20 @@ export class Polyline extends OverLayBase implements IPolyline {
this.native.path = points;
}

addPoint(point: Coordinate) {
const path = GMSMutablePath.alloc().initWithPath(this.native.path);
path.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
this.native.path = path;
}

addPoints(points: Coordinate[]) {
const path = GMSMutablePath.alloc().initWithPath(this.native.path);
points.forEach((point) => {
path.addCoordinate(CLLocationCoordinate2DMake(point.lat, point.lng));
});
this.native.path = path;
}

get tappable(): boolean {
return this.native.tappable;
}
Expand Down Expand Up @@ -1789,7 +1817,7 @@ export class TileProvider implements ITileProvider {
export class UrlTileProvider extends TileProvider {
_native: GMSURLTileLayer;

constructor(callback: (x: number, y: number, zoom: number) => string, size: number = 256) {
constructor(callback: (x: number, y: number, zoom: number) => string, size = 256) {
super(null);
const ref = new WeakRef(this);
this._native = GMSURLTileLayer.tileLayerWithURLConstructor((x, y, zoom) => {
Expand Down
Loading

0 comments on commit 30e5474

Please sign in to comment.