From d72a40c2bec7f5de51f2e31dc52f6f96a0c9175e Mon Sep 17 00:00:00 2001 From: Dylan Llewellyn <46717769+herefishyfish@users.noreply.github.com> Date: Fri, 9 Dec 2022 10:49:09 +0800 Subject: [PATCH 1/5] feat(google-maps): toggle marker tap panning --- packages/google-maps/common.ts | 114 +++++++++++++------------- packages/google-maps/index.android.ts | 36 ++++++-- packages/google-maps/index.ios.ts | 60 ++++++++++++-- 3 files changed, 141 insertions(+), 69 deletions(-) diff --git a/packages/google-maps/common.ts b/packages/google-maps/common.ts index 6a7d955f..cd7528a0 100644 --- a/packages/google-maps/common.ts +++ b/packages/google-maps/common.ts @@ -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({ - name: "lat" + name: 'lat', }); export const lngProperty = new Property({ - name: "lng" + name: 'lng', }); export const zoomProperty = new Property({ - name: "zoom" + name: 'zoom', }); export const bearingProperty = new Property({ - name: 'bearing' -}) + name: 'bearing', +}); export const tiltProperty = new Property({ - 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({ + 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); \ No newline at end of file +tiltProperty.register(MapViewBase); +disableMarkerTapHandlerProperty.register(MapViewBase); diff --git a/packages/google-maps/index.android.ts b/packages/google-maps/index.android.ts index 3403d35e..3232a58e 100644 --- a/packages/google-maps/index.android.ts +++ b/packages/google-maps/index.android.ts @@ -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'; @@ -190,13 +190,6 @@ export class MapView extends MapViewBase { marker: Marker.fromNative(marker), }); break; - case 'click': - ref?.get?.().notify({ - eventName: MapView.markerTapEvent, - object: ref?.get?.(), - marker: Marker.fromNative(marker), - }); - break; } }, onMapClickEvent(latLng: com.google.android.gms.maps.model.LatLng, isLongClick: boolean) { @@ -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(), + }, }); } else { ref?.get?.().notify({ @@ -364,6 +361,7 @@ export class MapView extends MapViewBase { tilt: owner.tilt, zoom: owner.zoom, }); + owner._setMapClickListener(map, owner.disableMarkerTapHandler); } ref.get?.().notify?.({ @@ -426,6 +424,12 @@ export class MapView extends MapViewBase { } } + [disableMarkerTapHandlerProperty.setNative](value) { + if (this._map) { + this._setMapClickListener(this._map, value); + } + } + _updateCamera( map, owner: { @@ -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({ + eventName: MapView.markerTapEvent, + object: this, + marker: Marker.fromNative(marker), + }); + + return disableMarkerTapHandler; + }, + }) + ); + } } export class IndoorLevel implements IIndoorLevel { diff --git a/packages/google-maps/index.ios.ts b/packages/google-maps/index.ios.ts index 71036859..e96f10ea 100644 --- a/packages/google-maps/index.ios.ts +++ b/packages/google-maps/index.ios.ts @@ -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'; @@ -278,11 +320,17 @@ class GMSMapViewDelegateImpl extends NSObject implements GMSMapViewDelegate { } mapViewDidTapMarker(mapView: GMSMapView, marker: GMSMarker): boolean { - this._owner?.get?.().notify({ - eventName: MapView.markerTapEvent, - object: this._owner?.get?.(), - marker: Marker.fromNative(marker), - }); + const owner = this._owner?.get?.(); + if (owner) { + owner.notify({ + eventName: MapView.markerTapEvent, + object: owner, + marker: Marker.fromNative(marker), + }); + + return owner.disableMarkerTapHandler; + } + return false; } From 2ea91632278381626eb145416031b2b2ec2ebf79 Mon Sep 17 00:00:00 2001 From: Dylan Llewellyn <46717769+herefishyfish@users.noreply.github.com> Date: Fri, 9 Dec 2022 11:06:02 +0800 Subject: [PATCH 2/5] feat(google-maps): marker event readme --- packages/google-maps/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/google-maps/README.md b/packages/google-maps/README.md index 0b2759c6..a4132b4a 100644 --- a/packages/google-maps/README.md +++ b/packages/google-maps/README.md @@ -174,6 +174,7 @@ The following properties are available for adjusting the camera view on initiali `zoom` | number | Zoom level (described [here](https://developers.google.com/maps/documentation/javascript/tutorial#zoom-levels)) `bearing` | number | Bearing, in degrees `tilt` | number | Tilt, in degrees +`disableMarkerTapHandler` | boolean | Disables the default marker event handling (panning/info windows) done by Google Maps ### Events From f002d32adab4b17304bf37942053f13ed8cd3430 Mon Sep 17 00:00:00 2001 From: Dylan Llewellyn <46717769+herefishyfish@users.noreply.github.com> Date: Fri, 7 Jul 2023 09:47:41 +0800 Subject: [PATCH 3/5] Update packages/google-maps/index.android.ts --- packages/google-maps/index.android.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/google-maps/index.android.ts b/packages/google-maps/index.android.ts index 3232a58e..6eeb157d 100644 --- a/packages/google-maps/index.android.ts +++ b/packages/google-maps/index.android.ts @@ -218,10 +218,6 @@ export class MapView extends MapViewBase { ref?.get?.().notify({ eventName: MapView.myLocationButtonTapEvent, object: ref?.get?.(), - location: { - lat: location.getLatitude(), - lng: location.getLongitude(), - }, }); } else { ref?.get?.().notify({ From d51d7b8493d60d6547aa1336c71d7b39b584bab9 Mon Sep 17 00:00:00 2001 From: Dylan Llewellyn <46717769+herefishyfish@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:28:11 +0800 Subject: [PATCH 4/5] chore: update variable name --- packages/google-maps/README.md | 2 +- packages/google-maps/common.ts | 8 ++++---- packages/google-maps/index.android.ts | 10 +++++----- packages/google-maps/index.ios.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/google-maps/README.md b/packages/google-maps/README.md index f25059d2..9308f1da 100644 --- a/packages/google-maps/README.md +++ b/packages/google-maps/README.md @@ -313,7 +313,7 @@ The following properties are available for adjusting the camera view on initiali `zoom` | `number` | Zoom level (described [here](https://developers.google.com/maps/documentation/javascript/tutorial#zoom-levels)) `bearing` | `number` | Bearing, in degrees `tilt` | `number` | Tilt, in degrees -`disableMarkerTapHandler` | `boolean` | Disables the default marker event handling (panning/info windows) done by Google Maps +`preventDefaultMarkerTapBehavior ` | `boolean` | Prevents the default marker event handling (panning/info windows) done by Google Maps #### Events diff --git a/packages/google-maps/common.ts b/packages/google-maps/common.ts index c70ddc29..a1727107 100644 --- a/packages/google-maps/common.ts +++ b/packages/google-maps/common.ts @@ -35,8 +35,8 @@ export const tiltProperty = new Property({ name: 'tilt', }); -export const disableMarkerTapHandlerProperty = new Property({ - name: 'disableMarkerTapHandler', +export const preventDefaultMarkerTapBehaviorProperty = new Property({ + name: 'preventDefaultMarkerTapBehavior', defaultValue: false, }); @@ -78,7 +78,7 @@ export class MapViewBase extends ContentView { zoom: number; bearing: number; tilt: number; - disableMarkerTapHandler: boolean; + preventDefaultMarkerTapBehavior: boolean; } latProperty.register(MapViewBase); @@ -86,4 +86,4 @@ lngProperty.register(MapViewBase); zoomProperty.register(MapViewBase); bearingProperty.register(MapViewBase); tiltProperty.register(MapViewBase); -disableMarkerTapHandlerProperty.register(MapViewBase); +preventDefaultMarkerTapBehaviorProperty.register(MapViewBase); diff --git a/packages/google-maps/index.android.ts b/packages/google-maps/index.android.ts index d4676da7..085edd6f 100644 --- a/packages/google-maps/index.android.ts +++ b/packages/google-maps/index.android.ts @@ -45,7 +45,7 @@ import { Style, TileOverlayOptions, } from '.'; -import { bearingProperty, disableMarkerTapHandlerProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common'; +import { bearingProperty, preventDefaultMarkerTapBehaviorProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common'; import { intoNativeMarkerOptions, intoNativeCircleOptions, intoNativePolygonOptions, intoNativeGroundOverlayOptions, intoNativePolylineOptions, hueFromColor, intoNativeJointType, toJointType, intoNativeTileOverlayOptions, deserialize, serialize } from './utils'; @@ -355,7 +355,7 @@ export class MapView extends MapViewBase { tilt: owner.tilt, zoom: owner.zoom, }); - owner._setMapClickListener(map, owner.disableMarkerTapHandler); + owner._setMapClickListener(map, owner.preventDefaultMarkerTapBehavior); } ref.get?.().notify?.({ @@ -491,7 +491,7 @@ export class MapView extends MapViewBase { } } - [disableMarkerTapHandlerProperty.setNative](value) { + [preventDefaultMarkerTapBehaviorProperty.setNative](value) { if (this._map) { this._setMapClickListener(this._map, value); } @@ -549,7 +549,7 @@ export class MapView extends MapViewBase { } } - _setMapClickListener(map, disableMarkerTapHandler) { + _setMapClickListener(map, preventDefaultMarkerTapBehavior) { map.setOnMarkerClickListener( new com.google.android.gms.maps.GoogleMap.OnMarkerClickListener({ onMarkerClick: (marker) => { @@ -559,7 +559,7 @@ export class MapView extends MapViewBase { marker: Marker.fromNative(marker), }); - return disableMarkerTapHandler; + return preventDefaultMarkerTapBehavior; }, }) ); diff --git a/packages/google-maps/index.ios.ts b/packages/google-maps/index.ios.ts index 8fae2560..1e9da85c 100644 --- a/packages/google-maps/index.ios.ts +++ b/packages/google-maps/index.ios.ts @@ -378,7 +378,7 @@ class GMSMapViewDelegateImpl extends NSObject implements GMSMapViewDelegate { marker: Marker.fromNative(marker), }); - return owner.disableMarkerTapHandler; + return owner.preventDefaultMarkerTapBehavior; } return false; From b6b2523f4638c0161adc5605b3482375c424f294 Mon Sep 17 00:00:00 2001 From: Dylan Llewellyn <46717769+herefishyfish@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:29:33 +0800 Subject: [PATCH 5/5] fix: readme --- packages/google-maps/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google-maps/README.md b/packages/google-maps/README.md index 9308f1da..9d6bb846 100644 --- a/packages/google-maps/README.md +++ b/packages/google-maps/README.md @@ -313,7 +313,7 @@ The following properties are available for adjusting the camera view on initiali `zoom` | `number` | Zoom level (described [here](https://developers.google.com/maps/documentation/javascript/tutorial#zoom-levels)) `bearing` | `number` | Bearing, in degrees `tilt` | `number` | Tilt, in degrees -`preventDefaultMarkerTapBehavior ` | `boolean` | Prevents the default marker event handling (panning/info windows) done by Google Maps +`preventDefaultMarkerTapBehavior` | `boolean` | Prevents the default marker event handling (panning/info windows) done by Google Maps #### Events