From 0413bac33981e6f46bb311196ed14f946188e9b9 Mon Sep 17 00:00:00 2001 From: tomma_g <38555316+tommag21@users.noreply.github.com> Date: Fri, 15 Jul 2022 18:35:58 +0200 Subject: [PATCH 1/2] Fix/google maps ground overlay (#303) * fixes android ground overlay from position * adds ground overlay from bounds * fixes map style --- packages/google-maps/index.d.ts | 6 ++++-- packages/google-maps/utils/index.android.ts | 17 ++++++++++++----- packages/google-maps/utils/index.ios.ts | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/google-maps/index.d.ts b/packages/google-maps/index.d.ts index b3176dcf..2b761d0c 100644 --- a/packages/google-maps/index.d.ts +++ b/packages/google-maps/index.d.ts @@ -17,13 +17,15 @@ export type ElementTypeGeometry = 'geometry' | 'geometry.fill' | 'geometry.strok export type ElementTypeLabels = 'labels' | 'labels.icon' | 'labels.text' | 'labels.text.fill' | 'labels.text.stroke'; +export type StylersVisibility = 'on' | 'off' | 'simplified'; + export interface Stylers { hue?: string; lightness?: number; saturation?: number; gamma?: number; invert_lightness?: boolean; - visibility?: boolean; + visibility?: StylersVisibility; color?: string; weight?: number; } @@ -410,7 +412,7 @@ export interface IGoogleMap { } export class GoogleMap implements IGoogleMap { - mapStyle: Style; + mapStyle: Style[]; addTileOverlay(options: TileOverlayOptions): TileOverlay; removeTileOverlay(overlay: TileOverlay); buildingsEnabled: boolean; diff --git a/packages/google-maps/utils/index.android.ts b/packages/google-maps/utils/index.android.ts index 5ccd656f..122fb99c 100644 --- a/packages/google-maps/utils/index.android.ts +++ b/packages/google-maps/utils/index.android.ts @@ -253,6 +253,11 @@ export function intoNativePolylineOptions(options: PolylineOptions) { export function intoNativeGroundOverlayOptions(options: GroundOverlayOptions) { const opts = new com.google.android.gms.maps.model.GroundOverlayOptions(); + if (options?.position) { + const coords = options.position; + opts.position(new com.google.android.gms.maps.model.LatLng(coords.lat, coords.lng), options.width); + } + if (typeof options?.width === 'number') { opts.position(opts.getLocation(), options.width); } @@ -261,6 +266,13 @@ export function intoNativeGroundOverlayOptions(options: GroundOverlayOptions) { opts.position(opts.getLocation(), opts.getWidth(), options.height); } + if (options?.bounds) { + opts.positionFromBounds(new com.google.android.gms.maps.model.LatLngBounds( + new com.google.android.gms.maps.model.LatLng(options.bounds.southwest.lat, options.bounds.southwest.lng), + new com.google.android.gms.maps.model.LatLng(options.bounds.northeast.lat, options.bounds.northeast.lng) + )); + } + if (typeof options?.transparency) { opts.transparency(options.transparency); } @@ -273,11 +285,6 @@ export function intoNativeGroundOverlayOptions(options: GroundOverlayOptions) { opts.clickable(options.tappable); } - if (options?.position) { - const coords = options.position; - opts.position(new com.google.android.gms.maps.model.LatLng(coords.lat, coords.lng), opts.getWidth()); - } - if (typeof options?.tappable === 'boolean') { opts.clickable(options.tappable); } diff --git a/packages/google-maps/utils/index.ios.ts b/packages/google-maps/utils/index.ios.ts index 5d18056b..a3b6eaf1 100644 --- a/packages/google-maps/utils/index.ios.ts +++ b/packages/google-maps/utils/index.ios.ts @@ -259,6 +259,13 @@ export function intoNativeGroundOverlayOptions(options: GroundOverlayOptions) { // TODO } + if (options?.bounds) { + opts.bounds = new GMSCoordinateBounds({ + coordinate: CLLocationCoordinate2DMake(options.bounds.southwest.lat, options.bounds.southwest.lng), + coordinate2: CLLocationCoordinate2DMake(options.bounds.northeast.lat, options.bounds.northeast.lng) + }); + } + if (typeof options?.anchorU === 'number' || typeof options?.anchorV === 'number') { opts.anchor = CGPointMake(options?.anchorU ?? opts.anchor.x, options?.anchorV ?? opts.anchor.y); } From 4896204b89f96d7d97ddd5a3247633158340b70a Mon Sep 17 00:00:00 2001 From: Dylan Llewellyn <46717769+herefishyfish@users.noreply.github.com> Date: Thu, 4 Aug 2022 18:37:18 +0800 Subject: [PATCH 2/2] add iOS map type --- packages/google-maps/index.d.ts | 5 ++++- packages/google-maps/index.ios.ts | 37 ++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/google-maps/index.d.ts b/packages/google-maps/index.d.ts index 2b761d0c..996f81e4 100644 --- a/packages/google-maps/index.d.ts +++ b/packages/google-maps/index.d.ts @@ -1,5 +1,5 @@ import { Color, ImageSource, EventData, View } from '@nativescript/core'; -import { JointType, MapViewBase } from './common'; +import { JointType, MapType, MapViewBase } from './common'; export type FeatureTypeAdministrative = 'administrative' | 'administrative.country' | 'administrative.land_parcel' | 'administrative.locality' | 'administrative.neighborhood' | 'administrative.province'; @@ -380,6 +380,8 @@ export interface IGoogleMap { mapStyle: Style[]; + mapType: MapType; + snapshot(): Promise; animateCamera(update: CameraUpdate); @@ -413,6 +415,7 @@ export interface IGoogleMap { export class GoogleMap implements IGoogleMap { mapStyle: Style[]; + mapType: MapType; addTileOverlay(options: TileOverlayOptions): TileOverlay; removeTileOverlay(overlay: TileOverlay); buildingsEnabled: boolean; diff --git a/packages/google-maps/index.ios.ts b/packages/google-maps/index.ios.ts index 03940ca1..d9076fe7 100644 --- a/packages/google-maps/index.ios.ts +++ b/packages/google-maps/index.ios.ts @@ -1,7 +1,7 @@ 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, GroundOverlayTapEvent, ICameraPosition, ICameraUpdate, ICircle, IGoogleMap, IGroundOverlay, IIndoorBuilding, IIndoorLevel, IMarker, InfoWindowEvent, IPatternItem, IPoi, IPolygon, IPolyline, IProjection, ITileOverlay, ITileProvider, IUISettings, IVisibleRegion, MapTapEvent, MarkerDragEvent, MarkerInfoEvent, MarkerOptions, MarkerTapEvent, PoiTapEvent, PolygonOptions, PolylineOptions, Style, TileOverlayOptions } from '.'; -import { bearingProperty, JointType, latProperty, lngProperty, MapViewBase, tiltProperty, zoomProperty } from './common'; +import { bearingProperty, JointType, latProperty, lngProperty, MapType, MapViewBase, tiltProperty, zoomProperty } from './common'; import { deserialize, intoNativeCircleOptions, intoNativeGroundOverlayOptions, intoNativeMarkerOptions, intoNativePolygonOptions, intoNativePolylineOptions, serialize } from './utils'; export class CameraUpdate implements ICameraUpdate { @@ -820,6 +820,41 @@ export class GoogleMap implements IGoogleMap { return UISettings.fromNative(this.native.settings); } + get mapType() { + switch (this.native.mapType) { + case GMSMapViewType.kGMSTypeNone: + return MapType.None; + case GMSMapViewType.kGMSTypeNormal: + return MapType.Normal; + case GMSMapViewType.kGMSTypeSatellite: + return MapType.Satellite; + case GMSMapViewType.kGMSTypeTerrain: + return MapType.Terrain; + case GMSMapViewType.kGMSTypeHybrid: + return MapType.Hybrid; + } + } + + set mapType(value: MapType) { + switch (value) { + case MapType.None: + this.native.mapType = GMSMapViewType.kGMSTypeNone; + break; + case MapType.Normal: + this.native.mapType = GMSMapViewType.kGMSTypeNormal; + break; + case MapType.Satellite: + this.native.mapType = GMSMapViewType.kGMSTypeSatellite; + break; + case MapType.Terrain: + this.native.mapType = GMSMapViewType.kGMSTypeTerrain; + break; + case MapType.Hybrid: + this.native.mapType = GMSMapViewType.kGMSTypeHybrid; + break; + } + } + #mapStyle: Style[]; get mapStyle() { return this.#mapStyle;