Skip to content

feat/google-map-utils #298

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

Merged
merged 41 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6d98a2a
feat(google-map-utils): Init
herefishyfish Jul 5, 2022
424d5d0
chore(google-maps-utils): ReadMe
herefishyfish Jul 5, 2022
f6cd792
feat(google-maps-utils): iOS init
herefishyfish Jul 6, 2022
8f3a61f
feat(google-maps-utils): iOS GeoJson wip
herefishyfish Jul 6, 2022
48f174b
feat(google-maps-utils): iOS GeoJson
herefishyfish Jul 6, 2022
c1c68de
feat(google-maps-utils): Android GeoJson Styles
herefishyfish Jul 6, 2022
4cf8289
feat(google-maps-utils): Android map clustering
herefishyfish Jul 9, 2022
08ec261
fix(google-maps-utils): Android heatmap provider
herefishyfish Jul 9, 2022
755958c
feat(google-maps-utils): ios heatmap wip
herefishyfish Jul 10, 2022
3afbca1
feat(google-maps-utils): iOS Heatmap Tiles
herefishyfish Jul 11, 2022
8b62441
feat(google-maps-utils): iOS clustering
herefishyfish Jul 11, 2022
b635450
feat(google-maps-utils): demo marker info
herefishyfish Jul 11, 2022
8b74920
Merge branch 'NativeScript:main' into feat/google-map-utils
herefishyfish Jul 14, 2022
0413bac
Fix/google maps ground overlay (#303)
tommag21 Jul 15, 2022
47c5e9f
Merge branch 'NativeScript:main' into feat/google-map-utils
herefishyfish Jul 16, 2022
860f3c3
feat(google-maps-utils):android clustermarker opts
herefishyfish Jul 16, 2022
08b7f6a
feat(google-maps-utils): match cluster styles
herefishyfish Jul 16, 2022
34e85fd
feat(google-maps-utils): Readme
herefishyfish Jul 16, 2022
94c63c5
cleanup wip
herefishyfish Jul 21, 2022
a7f29ad
fix: remove wip functionality from demo
herefishyfish Jul 21, 2022
1aa9756
fix: android heatmap gradient
herefishyfish Jul 21, 2022
3bf7f5e
Merge branch 'main' into feat/google-map-utils
NathanWalker Aug 8, 2022
f9ffcfa
fix: remove console log
herefishyfish Aug 8, 2022
0f9209c
Merge branch 'main' into feat/google-map-utils
NathanWalker Sep 23, 2022
6c1c567
Merge branch 'NativeScript:main' into feat/google-map-utils
herefishyfish Oct 7, 2022
5959139
fix(gmaps-utils): refactor to align more with gmap
herefishyfish Nov 12, 2022
83ef5da
fix(gmap-utils): ios refactor
herefishyfish Nov 12, 2022
d1f4b2e
chore(google-map-utils): rename member functions
herefishyfish Dec 1, 2022
064ad74
Merge branch 'NativeScript:main' into feat/google-map-utils
herefishyfish Dec 6, 2022
b14f552
feat(google-map-utils): use mixin
herefishyfish Dec 16, 2022
87ce260
Merge branch 'feat/google-map-utils' of https://github.com/herefishyf…
herefishyfish Dec 16, 2022
0922e78
fix(google-map-utils): mixin
herefishyfish Dec 16, 2022
1d91771
fix(google-map-utils): ios geojson
herefishyfish Dec 16, 2022
51a871b
fix(google-map-utils): remove logging
herefishyfish Dec 16, 2022
eb87b86
Merge branch 'main' into feat/google-map-utils
herefishyfish May 19, 2023
0972ed0
chore: update android
herefishyfish May 19, 2023
050136b
Merge branch 'main' into feat/google-map-utils
herefishyfish May 19, 2023
0904788
Merge branch 'main' into feat/google-map-utils
herefishyfish Jul 7, 2023
6da8e45
Merge branch 'main' into feat/google-map-utils
herefishyfish Aug 9, 2023
cb9c7bf
chore: update cluster item
herefishyfish Jan 28, 2024
6bb43e4
Merge branch 'main' of https://github.com/NativeScript/plugins into f…
herefishyfish May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(google-maps-utils): Android map clustering
  • Loading branch information
herefishyfish committed Jul 9, 2022
commit 4cf82898b537a285afff362d5d00b89ea3de347e
93 changes: 86 additions & 7 deletions packages/google-maps-utils/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Color } from '@nativescript/core';
import { Coordinate, MapView } from '@nativescript/google-maps';
import { IGeoJsonLayer, IGeometryStyle } from '.';
import { Color, Utils } from '@nativescript/core';
import { Coordinate, GoogleMap, MapView, Marker, MarkerOptions } from '@nativescript/google-maps';
import { intoNativeMarkerOptions } from '../google-maps/utils';
import { IClusterManager, IGeoJsonLayer, IGeometryStyle } from '.';
import { GoogleMapsUtilsCommon } from './common';

export class GoogleMapsUtils extends GoogleMapsUtilsCommon {
constructor(private map: MapView) {
constructor(private map: GoogleMap) {
super();
}

Expand Down Expand Up @@ -195,12 +196,12 @@ export class GeoJsonLayer extends DataLayer<com.google.maps.android.data.geojson
#native: com.google.maps.android.data.geojson.GeoJsonLayer;
style: GeometryStyle;

constructor(mapView: MapView, geoJson: any, geometryStyle?: IGeometryStyle) {
constructor(map: GoogleMap, geoJson: any, geometryStyle?: IGeometryStyle) {
super();
if (mapView && geoJson) {
if (map && geoJson) {
try {
const geoJsonData = new org.json.JSONObject(JSON.stringify(geoJson));
this.#native = new com.google.maps.android.data.geojson.GeoJsonLayer((mapView as any)._map, geoJsonData);
this.#native = new com.google.maps.android.data.geojson.GeoJsonLayer(map.native, geoJsonData);
this.style = new GeometryStyle(this.#native.getDefaultPolygonStyle(), this.#native.getDefaultLineStringStyle(), this.#native.getDefaultPointStyle());

if (geometryStyle) {
Expand Down Expand Up @@ -278,3 +279,81 @@ export class KmlLayer extends DataLayer<com.google.maps.android.data.kml.KmlLaye
return this.native.getGroundOverlays();
}
}

export class ClusterItem extends com.google.maps.android.clustering.ClusterItem {
constructor(public options: MarkerOptions) {
super({
getPosition: (): com.google.android.gms.maps.model.LatLng => {
return new com.google.android.gms.maps.model.LatLng(options?.position?.lat ?? 0, options?.position?.lng ?? 0);
},
getSnippet: (): string => {
return this.options?.snippet ?? '';
},
getTitle: (): string => {
return this.options?.title ?? '';
},
});
}
}

export class ClusterRenderer extends com.google.maps.android.clustering.view.DefaultClusterRenderer<any> {
constructor(map: GoogleMap, clusterManager: ClusterManager) {
console.log('custom renderer');
super(Utils.ad.getApplicationContext(), map.native, clusterManager.native);
}

onBeforeClusterItemRendered(item: com.google.maps.android.clustering.Cluster<any>, markerOptions: com.google.android.gms.maps.model.MarkerOptions): void {
console.log(item.getItems()?.[0]?.title);
super.onBeforeClusterItemRendered(item, markerOptions);
console.log(item.getItems());
}

public onClustersChanged(param0: java.util.Set<any>): void {
super.onClustersChanged(param0);
}
}

export class ClusterManager implements IClusterManager {
#native: com.google.maps.android.clustering.ClusterManager<com.google.maps.android.clustering.ClusterItem>;

constructor(private map: GoogleMap) {
this.#native = new com.google.maps.android.clustering.ClusterManager(Utils.ad.getApplicationContext(), map.native);

if (map?.native?.setOnCameraIdleListener) {
(map.native as com.google.android.gms.maps.GoogleMap).setOnCameraIdleListener(this.#native);
}
}

static fromNative(nativeClusterManager: com.google.maps.android.clustering.ClusterManager<any>) {
if (ClusterManager instanceof com.google.maps.android.clustering.ClusterManager) {
const geoJsonLayer = new ClusterManager(null);
geoJsonLayer.#native = nativeClusterManager;
return geoJsonLayer;
}
return null;
}

get native() {
return this.#native;
}

setRenderer(renderer) {
this.native.setRenderer(renderer);
}

addItem(clusterItem: ClusterItem) {
this.native.addItem(clusterItem);
}

addItems(clusterItems: ClusterItem[]) {
const clusterItemArray = new java.util.ArrayList();
for (const clusterItem of clusterItems) {
clusterItemArray.add(clusterItem);
}
this.native.addItems(clusterItemArray);
}

cluster() {
this.native.cluster();
}
}
24 changes: 22 additions & 2 deletions packages/google-maps-utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import { Color } from '@nativescript/core';
import { MapView } from '@nativescript/google-maps';
import { GoogleMap, Marker, MarkerOptions } from '@nativescript/google-maps';
import { GoogleMapsUtilsCommon } from './common';

export declare class GoogleMapsUtils extends GoogleMapsUtilsCommon {}

export class ClusterItem {
constructor(markerOptions: MarkerOptions);
}

export interface IClusterManager {
native: any;
}

export class ClusterRenderer {
constructor(private map: GoogleMap, private manager: ClusterManager);
}

export class ClusterManager implements IClusterManager {
constructor(private map: GoogleMap);
addItems: (markers: ClusterItem[]) => void;
addItem: (marker: ClusterItem) => void;
cluster: () => void;
setRenderer(clusterRenderer: ClusterRenderer): () => void;
}

export interface IGeoJsonLayer {
style: GeometryStyle;
addLayerToMap: () => void;
Expand All @@ -15,7 +35,7 @@ export class GeoJsonLayer implements IGeoJsonLayer {
android: any;
native: any;
style: GeometryStyle;
constructor(map: MapView, geojson: any, styles?: Partial<IGeometryStyle>);
constructor(map: GoogleMap, geojson: any, styles?: Partial<IGeometryStyle>);
addLayerToMap: () => void;
removeLayerFromMap: () => void;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/google-maps-utils/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Color, encoding } from '@nativescript/core';
import { MapView } from '@nativescript/google-maps';
import { GoogleMap, MapView } from '@nativescript/google-maps';
import { IGeoJsonLayer, IGeometryStyle } from '.';
import { GoogleMapsUtilsCommon } from './common';

let UNIQUE_STYLE_ID = 0;

export class GoogleMapsUtils extends GoogleMapsUtilsCommon {
constructor(private map: MapView) {
constructor(private map: GoogleMap) {
super();
}

addGeoJsonLayer(geoJson: any) {
try {
const layer = new GeoJsonLayer(this.map.nativeView, geoJson);
const layer = new GeoJsonLayer(this.map.native, geoJson);
layer.addLayerToMap();
return layer;
} catch (error) {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class GeoJsonLayer implements IGeoJsonLayer {
#native: GMUGeometryRenderer;
style: GeometryStyle;

constructor(private map: MapView, private geometries: any, private styles?: Partial<IGeometryStyle>) {
constructor(private map: GoogleMap, private geometries: any, private styles?: Partial<IGeometryStyle>) {
this.style = new GeometryStyle(styles);

const jsonString = new NSString({ UTF8String: JSON.stringify(geometries) });
Expand All @@ -72,7 +72,7 @@ export class GeoJsonLayer implements IGeoJsonLayer {
feature.style = this.style.native;
}

this.#native = new GMUGeometryRenderer({ map: this.map.nativeView, geometries: features });
this.#native = new GMUGeometryRenderer({ map: this.map.native, geometries: features });
}

static fromNative(nativeGeoJsonLayer: GMUGeometryRenderer) {
Expand Down
41 changes: 34 additions & 7 deletions tools/demo/google-maps-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DemoSharedBase } from '../utils';
import { GeoJsonLayer, GeoJsonLayer, GoogleMapsUtils, IGeometryStyle } from '@nativescript/google-maps-utils';
import { GeoJsonLayer, GeoJsonLayer, ClusterManager, GoogleMapsUtils, IGeometryStyle, ClusterItem, ClusterRenderer } from '@nativescript/google-maps-utils';
import { Color, LoadEventData } from '@nativescript/core';
import { CameraUpdate, MapReadyEvent, MapView } from '@nativescript/google-maps';
import { CameraUpdate, GoogleMap, MapReadyEvent, MapView, Marker } from '@nativescript/google-maps';
import { australia } from './geojson.example';
import { intoNativeTileOverlayOptions } from '@nativescript/google-maps/utils';
import { intoNativeMarkerOptions, intoNativeTileOverlayOptions } from '@nativescript/google-maps/utils';
import { zoomProperty } from '@nativescript/google-maps/common';

function generateRandomPosition(position, distance) {
Expand All @@ -26,6 +26,7 @@ function generateRandomPosition(position, distance) {

export class DemoSharedGoogleMapsUtils extends DemoSharedBase {
mapView: MapView;
map: GoogleMap;
geoJson: GeoJsonLayer;
// heatmapProvider: HeatmapTileProvider;
heatmapOverlay;
Expand All @@ -37,17 +38,43 @@ export class DemoSharedGoogleMapsUtils extends DemoSharedBase {
}

this.geoJson.removeLayerFromMap();

//creating cluster manager');
const clusterManager = new ClusterManager(this.map);
const clusterRenderer = new ClusterRenderer(this.map, clusterManager);
clusterManager.setRenderer(clusterRenderer);

//building marker list');
const clusterSet: ClusterItem[] = [];
for (var i = 0; i < 100; i++) {
//creating new markers to cluster
const position = generateRandomPosition([-32.093407, 116.240609], 10000);

const clusterItem = new ClusterItem({
position: position,
color: 'blue',
});

clusterSet.push(clusterItem);
}

//adding markers to cluster manager
clusterManager.addItems(clusterSet);

//clustering!
clusterManager.cluster();

// this.heatmapProvider.setData(positionSet);
// this.heatmapProvider.opacity = 0.1;
// Need to clear cache to show adjustments
// this.heatmapOverlay.clearTileCache();
}

async onMapReady(args: MapReadyEvent) {
this.mapView = args.object as unknown as MapView;
this.mapView = args.object as MapView;

const map = args.map;
map.animateCamera(
this.map = args.map;
this.map.animateCamera(
CameraUpdate.fromCoordinate(
{
lat: -27.74278,
Expand All @@ -57,7 +84,7 @@ export class DemoSharedGoogleMapsUtils extends DemoSharedBase {
)
);

this.geoJson = new GeoJsonLayer(this.mapView, australia, {
this.geoJson = new GeoJsonLayer(this.map, australia, {
fillColor: new Color('blue'),
strokeColor: new Color('red'),
width: 4,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy