Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-maps): toggle marker tap panning and info windows #376

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
114 changes: 59 additions & 55 deletions packages/google-maps/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,87 @@ 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'
})

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';
name: 'tilt',
});

lat: number;
lng: number;
zoom: number;
bearing: number;
tilt: number;
export const disableMarkerTapHandlerProperty = new Property<MapViewBase, boolean>({
name: 'disableMarkerTapHandler',
defaultValue: false,
});

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;
disableMarkerTapHandler: boolean;
}

latProperty.register(MapViewBase);
lngProperty.register(MapViewBase);
zoomProperty.register(MapViewBase);
bearingProperty.register(MapViewBase);
tiltProperty.register(MapViewBase);
tiltProperty.register(MapViewBase);
disableMarkerTapHandlerProperty.register(MapViewBase);
36 changes: 28 additions & 8 deletions packages/google-maps/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
Style,
TileOverlayOptions,
} from '.';
import { bearingProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common';
import { bearingProperty, disableMarkerTapHandlerProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common';

import { intoNativeMarkerOptions, intoNativeCircleOptions, intoNativePolygonOptions, intoNativeGroundOverlayOptions, intoNativePolylineOptions, hueFromColor, intoNativeJointType, toJointType, intoNativeTileOverlayOptions, deserialize, serialize } from './utils';

Expand Down Expand Up @@ -190,13 +190,6 @@ export class MapView extends MapViewBase {
marker: Marker.fromNative(marker),
});
break;
case 'click':
ref?.get?.().notify(<MarkerTapEvent>{
eventName: MapView.markerTapEvent,
object: ref?.get?.(),
marker: Marker.fromNative(marker),
});
break;
}
},
onMapClickEvent(latLng: com.google.android.gms.maps.model.LatLng, isLongClick: boolean) {
Expand Down Expand Up @@ -225,6 +218,10 @@ export class MapView extends MapViewBase {
ref?.get?.().notify({
eventName: MapView.myLocationButtonTapEvent,
object: ref?.get?.(),
location: {
lat: location.getLatitude(),
lng: location.getLongitude(),
},
herefishyfish marked this conversation as resolved.
Show resolved Hide resolved
herefishyfish marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
ref?.get?.().notify(<EventData>{
Expand Down Expand Up @@ -364,6 +361,7 @@ export class MapView extends MapViewBase {
tilt: owner.tilt,
zoom: owner.zoom,
});
owner._setMapClickListener(map, owner.disableMarkerTapHandler);
}

ref.get?.().notify?.({
Expand Down Expand Up @@ -426,6 +424,12 @@ export class MapView extends MapViewBase {
}
}

[disableMarkerTapHandlerProperty.setNative](value) {
if (this._map) {
this._setMapClickListener(this._map, value);
}
}

_updateCamera(
map,
owner: {
Expand Down Expand Up @@ -477,6 +481,22 @@ export class MapView extends MapViewBase {
}
}
}

_setMapClickListener(map, disableMarkerTapHandler) {
map.setOnMarkerClickListener(
new com.google.android.gms.maps.GoogleMap.OnMarkerClickListener({
onMarkerClick: (marker) => {
this.notify(<MarkerTapEvent>{
eventName: MapView.markerTapEvent,
object: this,
marker: Marker.fromNative(marker),
});

return disableMarkerTapHandler;
},
})
);
}
}

export class IndoorLevel implements IIndoorLevel {
Expand Down
60 changes: 54 additions & 6 deletions packages/google-maps/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
import { Color, EventData, ImageSource, Utils, View } from '@nativescript/core';
import { isNullOrUndefined } from '@nativescript/core/utils/types';
import { ActiveBuildingEvent, ActiveLevelEvent, CameraPositionEvent, CameraPositionStartEvent, CircleOptions, Coordinate, CoordinateBounds, GroundOverlayOptions, CircleTapEvent, PolygonTapEvent, PolylineTapEvent, GroundOverlayTapEvent, ICameraPosition, ICameraUpdate, ICircle, IGoogleMap, IGroundOverlay, IIndoorBuilding, IIndoorLevel, IMarker, InfoWindowEvent, IPatternItem, ICap, IPoi, IPolygon, IPolyline, IProjection, ITileOverlay, ITileProvider, IUISettings, IVisibleRegion, MapTapEvent, MarkerDragEvent, MarkerInfoEvent, MarkerOptions, MarkerTapEvent, PoiTapEvent, PolygonOptions, PolylineOptions, Style, TileOverlayOptions } from '.';
import {
ActiveBuildingEvent,
ActiveLevelEvent,
CameraPositionEvent,
CameraPositionStartEvent,
CircleOptions,
Coordinate,
CoordinateBounds,
GroundOverlayOptions,
CircleTapEvent,
PolygonTapEvent,
PolylineTapEvent,
GroundOverlayTapEvent,
ICameraPosition,
ICameraUpdate,
ICircle,
IGoogleMap,
IGroundOverlay,
IIndoorBuilding,
IIndoorLevel,
IMarker,
InfoWindowEvent,
IPatternItem,
ICap,
IPoi,
IPolygon,
IPolyline,
IProjection,
ITileOverlay,
ITileProvider,
IUISettings,
IVisibleRegion,
MapTapEvent,
MarkerDragEvent,
MarkerInfoEvent,
MarkerOptions,
MarkerTapEvent,
PoiTapEvent,
PolygonOptions,
PolylineOptions,
Style,
TileOverlayOptions,
} from '.';
import { bearingProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common';
import { deserialize, intoNativeCircleOptions, intoNativeGroundOverlayOptions, intoNativeMarkerOptions, intoNativePolygonOptions, intoNativePolylineOptions, serialize } from './utils';

Expand Down Expand Up @@ -278,11 +320,17 @@ class GMSMapViewDelegateImpl extends NSObject implements GMSMapViewDelegate {
}

mapViewDidTapMarker(mapView: GMSMapView, marker: GMSMarker): boolean {
this._owner?.get?.().notify(<EventData & MarkerTapEvent>{
eventName: MapView.markerTapEvent,
object: this._owner?.get?.(),
marker: Marker.fromNative(marker),
});
const owner = this._owner?.get?.();
if (owner) {
owner.notify(<EventData & MarkerTapEvent>{
eventName: MapView.markerTapEvent,
object: owner,
marker: Marker.fromNative(marker),
});

return owner.disableMarkerTapHandler;
}

return false;
}

Expand Down