@lugg/maps 0.2.0-alpha.9 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -19
- package/android/src/main/java/com/luggmaps/LuggMapView.kt +290 -0
- package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +99 -36
- package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +13 -5
- package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +157 -13
- package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +28 -0
- package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
- package/android/src/main/java/com/luggmaps/LuggPolygonView.kt +85 -0
- package/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt +100 -0
- package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
- package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
- package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +698 -0
- package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +60 -0
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +89 -24
- package/android/src/main/java/com/luggmaps/events/LongPressEvent.kt +29 -0
- package/android/src/main/java/com/luggmaps/events/MarkerDragEvent.kt +41 -0
- package/android/src/main/java/com/luggmaps/events/MarkerPressEvent.kt +34 -0
- package/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt +12 -0
- package/android/src/main/java/com/luggmaps/events/PressEvent.kt +29 -0
- package/ios/LuggMapView.h +9 -0
- package/ios/LuggMapView.mm +343 -0
- package/ios/LuggMarkerView.h +13 -0
- package/ios/LuggMarkerView.mm +119 -0
- package/ios/LuggPolygonView.h +31 -0
- package/ios/LuggPolygonView.mm +151 -0
- package/ios/LuggPolylineView.h +4 -0
- package/ios/LuggPolylineView.mm +23 -0
- package/ios/core/AppleMapProvider.h +15 -0
- package/ios/core/AppleMapProvider.mm +1029 -0
- package/ios/core/GMSPolylineAnimator.h +3 -0
- package/ios/core/GMSPolylineAnimator.m +101 -15
- package/ios/core/GoogleMapProvider.h +13 -0
- package/ios/core/GoogleMapProvider.mm +689 -0
- package/ios/core/MKPolylineAnimator.h +4 -0
- package/ios/core/MKPolylineAnimator.m +167 -42
- package/ios/core/MapProviderDelegate.h +84 -0
- package/ios/core/PolylineAnimatorBase.h +24 -1
- package/ios/core/PolylineAnimatorBase.m +82 -19
- package/ios/events/LongPressEvent.h +29 -0
- package/ios/events/MarkerDragEvent.h +69 -0
- package/ios/events/MarkerPressEvent.h +29 -0
- package/ios/events/PolygonPressEvent.h +20 -0
- package/ios/events/PressEvent.h +29 -0
- package/ios/extensions/MKMapView+Zoom.h +2 -0
- package/ios/extensions/MKMapView+Zoom.m +14 -4
- package/lib/module/MapProvider.js +2 -4
- package/lib/module/MapProvider.js.map +1 -1
- package/lib/module/MapProvider.web.js +12 -7
- package/lib/module/MapProvider.web.js.map +1 -1
- package/lib/module/MapView.js +33 -16
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +283 -181
- package/lib/module/MapView.web.js.map +1 -1
- package/lib/module/components/GeoJson.js +159 -0
- package/lib/module/components/GeoJson.js.map +1 -0
- package/lib/module/components/GeoJson.types.js +4 -0
- package/lib/module/components/GeoJson.types.js.map +1 -0
- package/lib/module/components/Marker.js +28 -4
- package/lib/module/components/Marker.js.map +1 -1
- package/lib/module/components/Marker.types.js +4 -0
- package/lib/module/components/Marker.types.js.map +1 -0
- package/lib/module/components/Marker.web.js +98 -27
- package/lib/module/components/Marker.web.js.map +1 -1
- package/lib/module/components/Polygon.js +46 -0
- package/lib/module/components/Polygon.js.map +1 -0
- package/lib/module/components/Polygon.types.js +4 -0
- package/lib/module/components/Polygon.types.js.map +1 -0
- package/lib/module/components/Polygon.web.js +87 -0
- package/lib/module/components/Polygon.web.js.map +1 -0
- package/lib/module/components/Polyline.js +17 -4
- package/lib/module/components/Polyline.js.map +1 -1
- package/lib/module/components/Polyline.types.js +4 -0
- package/lib/module/components/Polyline.types.js.map +1 -0
- package/lib/module/components/Polyline.web.js +108 -31
- package/lib/module/components/Polyline.web.js.map +1 -1
- package/lib/module/components/index.js +4 -2
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/index.web.js +2 -0
- package/lib/module/components/index.web.js.map +1 -1
- package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
- package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +49 -1
- package/lib/module/fabric/LuggPolygonViewNativeComponent.ts +25 -0
- package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +4 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/typescript/src/MapProvider.d.ts +1 -1
- package/lib/typescript/src/MapProvider.d.ts.map +1 -1
- package/lib/typescript/src/MapProvider.web.d.ts +17 -1
- package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
- package/lib/typescript/src/MapView.d.ts +4 -4
- package/lib/typescript/src/MapView.d.ts.map +1 -1
- package/lib/typescript/src/MapView.types.d.ts +35 -9
- package/lib/typescript/src/MapView.types.d.ts.map +1 -1
- package/lib/typescript/src/MapView.web.d.ts +2 -11
- package/lib/typescript/src/MapView.web.d.ts.map +1 -1
- package/lib/typescript/src/components/GeoJson.d.ts +4 -0
- package/lib/typescript/src/components/GeoJson.d.ts.map +1 -0
- package/lib/typescript/src/components/GeoJson.types.d.ts +79 -0
- package/lib/typescript/src/components/GeoJson.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Marker.d.ts +6 -33
- package/lib/typescript/src/components/Marker.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.types.d.ts +74 -0
- package/lib/typescript/src/components/Marker.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Marker.web.d.ts +2 -5
- package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Polygon.d.ts +10 -0
- package/lib/typescript/src/components/Polygon.d.ts.map +1 -0
- package/lib/typescript/src/components/Polygon.types.d.ts +33 -0
- package/lib/typescript/src/components/Polygon.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Polygon.web.d.ts +3 -0
- package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Polyline.d.ts +6 -21
- package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
- package/lib/typescript/src/components/Polyline.types.d.ts +53 -0
- package/lib/typescript/src/components/Polyline.types.d.ts.map +1 -0
- package/lib/typescript/src/components/Polyline.web.d.ts +2 -5
- package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
- package/lib/typescript/src/components/index.d.ts +8 -2
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/index.web.d.ts +6 -2
- package/lib/typescript/src/components/index.web.d.ts.map +1 -1
- package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +30 -4
- package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +45 -1
- package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts +18 -0
- package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
- package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +11 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +9 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +11 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/MapProvider.tsx +1 -3
- package/src/MapProvider.web.tsx +12 -3
- package/src/MapView.tsx +32 -26
- package/src/MapView.types.ts +43 -9
- package/src/MapView.web.tsx +345 -211
- package/src/components/GeoJson.tsx +221 -0
- package/src/components/GeoJson.types.ts +107 -0
- package/src/components/Marker.tsx +45 -36
- package/src/components/Marker.types.ts +75 -0
- package/src/components/Marker.web.tsx +116 -28
- package/src/components/Polygon.tsx +52 -0
- package/src/components/Polygon.types.ts +33 -0
- package/src/components/Polygon.web.tsx +104 -0
- package/src/components/Polyline.tsx +23 -22
- package/src/components/Polyline.types.ts +55 -0
- package/src/components/Polyline.web.tsx +151 -37
- package/src/components/index.ts +16 -2
- package/src/components/index.web.ts +6 -2
- package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
- package/src/fabric/LuggMarkerViewNativeComponent.ts +49 -1
- package/src/fabric/LuggPolygonViewNativeComponent.ts +25 -0
- package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
- package/src/index.ts +28 -1
- package/src/index.web.ts +15 -1
- package/src/types.ts +13 -0
- package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +0 -511
- package/ios/LuggAppleMapView.h +0 -16
- package/ios/LuggAppleMapView.mm +0 -592
- package/ios/LuggGoogleMapView.h +0 -13
- package/ios/LuggGoogleMapView.mm +0 -455
- package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
- package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
- package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
- package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { codegenNativeComponent } from 'react-native';
|
|
2
2
|
import type { ViewProps, HostComponent } from 'react-native';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
Double,
|
|
5
|
+
WithDefault,
|
|
6
|
+
DirectEventHandler,
|
|
7
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
8
|
|
|
5
9
|
export interface Coordinate {
|
|
6
10
|
latitude: Double;
|
|
@@ -18,6 +22,50 @@ export interface NativeProps extends ViewProps {
|
|
|
18
22
|
title?: string;
|
|
19
23
|
description?: string;
|
|
20
24
|
anchor?: Point;
|
|
25
|
+
rotate?: WithDefault<Double, 0>;
|
|
26
|
+
scale?: WithDefault<Double, 1>;
|
|
27
|
+
rasterize?: WithDefault<boolean, true>;
|
|
28
|
+
draggable?: WithDefault<boolean, false>;
|
|
29
|
+
onMarkerPress?: DirectEventHandler<{
|
|
30
|
+
coordinate: {
|
|
31
|
+
latitude: Double;
|
|
32
|
+
longitude: Double;
|
|
33
|
+
};
|
|
34
|
+
point: {
|
|
35
|
+
x: Double;
|
|
36
|
+
y: Double;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
onMarkerDragStart?: DirectEventHandler<{
|
|
40
|
+
coordinate: {
|
|
41
|
+
latitude: Double;
|
|
42
|
+
longitude: Double;
|
|
43
|
+
};
|
|
44
|
+
point: {
|
|
45
|
+
x: Double;
|
|
46
|
+
y: Double;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
onMarkerDragChange?: DirectEventHandler<{
|
|
50
|
+
coordinate: {
|
|
51
|
+
latitude: Double;
|
|
52
|
+
longitude: Double;
|
|
53
|
+
};
|
|
54
|
+
point: {
|
|
55
|
+
x: Double;
|
|
56
|
+
y: Double;
|
|
57
|
+
};
|
|
58
|
+
}>;
|
|
59
|
+
onMarkerDragEnd?: DirectEventHandler<{
|
|
60
|
+
coordinate: {
|
|
61
|
+
latitude: Double;
|
|
62
|
+
longitude: Double;
|
|
63
|
+
};
|
|
64
|
+
point: {
|
|
65
|
+
x: Double;
|
|
66
|
+
y: Double;
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
21
69
|
}
|
|
22
70
|
|
|
23
71
|
export default codegenNativeComponent<NativeProps>(
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { codegenNativeComponent } from 'react-native';
|
|
2
|
+
import type { ViewProps, HostComponent, ColorValue } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
Double,
|
|
5
|
+
DirectEventHandler,
|
|
6
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
7
|
+
|
|
8
|
+
export interface Coordinate {
|
|
9
|
+
latitude: Double;
|
|
10
|
+
longitude: Double;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface NativeProps extends ViewProps {
|
|
14
|
+
coordinates: ReadonlyArray<Coordinate>;
|
|
15
|
+
holes?: ReadonlyArray<ReadonlyArray<Coordinate>>;
|
|
16
|
+
strokeColor?: ColorValue;
|
|
17
|
+
strokeWidth?: Double;
|
|
18
|
+
fillColor?: ColorValue;
|
|
19
|
+
tappable?: boolean;
|
|
20
|
+
onPolygonPress?: DirectEventHandler<null>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default codegenNativeComponent<NativeProps>(
|
|
24
|
+
'LuggPolygonView'
|
|
25
|
+
) as HostComponent<NativeProps>;
|
|
@@ -7,11 +7,19 @@ export interface Coordinate {
|
|
|
7
7
|
longitude: Double;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export interface AnimatedOptions {
|
|
11
|
+
duration?: Double;
|
|
12
|
+
easing?: string;
|
|
13
|
+
trailLength?: Double;
|
|
14
|
+
delay?: Double;
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
export interface NativeProps extends ViewProps {
|
|
11
18
|
coordinates: ReadonlyArray<Coordinate>;
|
|
12
19
|
strokeColors?: ReadonlyArray<ColorValue>;
|
|
13
20
|
strokeWidth?: Double;
|
|
14
21
|
animated?: boolean;
|
|
22
|
+
animatedOptions?: AnimatedOptions;
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
export default codegenNativeComponent<NativeProps>(
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
export { MapView } from './MapView';
|
|
2
2
|
export { MapProvider } from './MapProvider';
|
|
3
3
|
export type { MapProviderProps } from './MapProvider.types';
|
|
4
|
-
export
|
|
4
|
+
export { Marker } from './components';
|
|
5
|
+
export type {
|
|
6
|
+
MarkerProps,
|
|
7
|
+
MarkerPressEvent,
|
|
8
|
+
MarkerDragEvent,
|
|
9
|
+
} from './components';
|
|
10
|
+
export { Polygon } from './components';
|
|
11
|
+
export type { PolygonProps } from './components';
|
|
12
|
+
export { Polyline } from './components';
|
|
13
|
+
export type {
|
|
14
|
+
PolylineProps,
|
|
15
|
+
PolylineEasing,
|
|
16
|
+
PolylineAnimatedOptions,
|
|
17
|
+
} from './components';
|
|
18
|
+
export { GeoJson } from './components';
|
|
19
|
+
export type { GeoJsonProps } from './components';
|
|
5
20
|
export type {
|
|
6
21
|
MapViewProps,
|
|
7
22
|
MapViewRef,
|
|
8
23
|
MoveCameraOptions,
|
|
9
24
|
FitCoordinatesOptions,
|
|
25
|
+
SetEdgeInsetsOptions,
|
|
10
26
|
CameraEventPayload,
|
|
27
|
+
MapCameraEvent,
|
|
28
|
+
MapPressEvent,
|
|
11
29
|
} from './MapView.types';
|
|
12
30
|
export type {
|
|
13
31
|
MapProvider as MapProviderType,
|
|
32
|
+
MapTheme,
|
|
14
33
|
Coordinate,
|
|
15
34
|
Point,
|
|
16
35
|
EdgeInsets,
|
|
36
|
+
PressEventPayload,
|
|
17
37
|
} from './types';
|
|
38
|
+
export type {
|
|
39
|
+
GeoJSON,
|
|
40
|
+
Feature,
|
|
41
|
+
FeatureCollection,
|
|
42
|
+
Geometry,
|
|
43
|
+
Position,
|
|
44
|
+
} from './components/GeoJson.types';
|
package/src/index.web.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export { MapView } from './MapView.web';
|
|
2
2
|
export { MapProvider } from './MapProvider.web';
|
|
3
3
|
export type { MapProviderProps } from './MapProvider.types';
|
|
4
|
-
export
|
|
4
|
+
export { Marker } from './components/index.web';
|
|
5
|
+
export type { MarkerProps } from './components/index.web';
|
|
6
|
+
export { Polygon } from './components/index.web';
|
|
7
|
+
export type { PolygonProps } from './components/index.web';
|
|
8
|
+
export { Polyline } from './components/index.web';
|
|
9
|
+
export type { PolylineProps } from './components/index.web';
|
|
10
|
+
export { GeoJson } from './components/index.web';
|
|
11
|
+
export type { GeoJsonProps } from './components/index.web';
|
|
5
12
|
export type {
|
|
6
13
|
MapViewProps,
|
|
7
14
|
MapViewRef,
|
|
@@ -15,3 +22,10 @@ export type {
|
|
|
15
22
|
Point,
|
|
16
23
|
EdgeInsets,
|
|
17
24
|
} from './types';
|
|
25
|
+
export type {
|
|
26
|
+
GeoJSON,
|
|
27
|
+
Feature,
|
|
28
|
+
FeatureCollection,
|
|
29
|
+
Geometry,
|
|
30
|
+
Position,
|
|
31
|
+
} from './components/GeoJson.types';
|
package/src/types.ts
CHANGED
|
@@ -28,3 +28,16 @@ export interface EdgeInsets {
|
|
|
28
28
|
bottom: number;
|
|
29
29
|
right: number;
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Map theme
|
|
34
|
+
*/
|
|
35
|
+
export type MapTheme = 'light' | 'dark' | 'system';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Press event payload
|
|
39
|
+
*/
|
|
40
|
+
export interface PressEventPayload {
|
|
41
|
+
coordinate: Coordinate;
|
|
42
|
+
point: Point;
|
|
43
|
+
}
|
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
package com.luggmaps
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint
|
|
4
|
-
import android.view.View
|
|
5
|
-
import android.view.ViewGroup
|
|
6
|
-
import com.facebook.react.uimanager.PixelUtil.dpToPx
|
|
7
|
-
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
-
import com.facebook.react.util.RNLog
|
|
9
|
-
import com.facebook.react.views.view.ReactViewGroup
|
|
10
|
-
import com.google.android.gms.maps.CameraUpdateFactory
|
|
11
|
-
import com.google.android.gms.maps.GoogleMap
|
|
12
|
-
import com.google.android.gms.maps.GoogleMapOptions
|
|
13
|
-
import com.google.android.gms.maps.MapView
|
|
14
|
-
import com.google.android.gms.maps.OnMapReadyCallback
|
|
15
|
-
import com.google.android.gms.maps.model.AdvancedMarker
|
|
16
|
-
import com.google.android.gms.maps.model.AdvancedMarkerOptions
|
|
17
|
-
import com.google.android.gms.maps.model.AdvancedMarkerOptions.CollisionBehavior
|
|
18
|
-
import com.google.android.gms.maps.model.LatLng
|
|
19
|
-
import com.google.android.gms.maps.model.PolylineOptions
|
|
20
|
-
import com.luggmaps.core.PolylineAnimator
|
|
21
|
-
|
|
22
|
-
interface LuggGoogleMapViewEventDelegate {
|
|
23
|
-
fun onCameraMove(
|
|
24
|
-
view: LuggGoogleMapView,
|
|
25
|
-
latitude: Double,
|
|
26
|
-
longitude: Double,
|
|
27
|
-
zoom: Float,
|
|
28
|
-
gesture: Boolean
|
|
29
|
-
)
|
|
30
|
-
fun onCameraIdle(
|
|
31
|
-
view: LuggGoogleMapView,
|
|
32
|
-
latitude: Double,
|
|
33
|
-
longitude: Double,
|
|
34
|
-
zoom: Float,
|
|
35
|
-
gesture: Boolean
|
|
36
|
-
)
|
|
37
|
-
fun onReady(view: LuggGoogleMapView)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@SuppressLint("ViewConstructor")
|
|
41
|
-
class LuggGoogleMapView(private val reactContext: ThemedReactContext) :
|
|
42
|
-
ReactViewGroup(reactContext),
|
|
43
|
-
OnMapReadyCallback,
|
|
44
|
-
LuggMarkerViewDelegate,
|
|
45
|
-
LuggPolylineViewDelegate,
|
|
46
|
-
GoogleMap.OnCameraMoveStartedListener,
|
|
47
|
-
GoogleMap.OnCameraMoveListener,
|
|
48
|
-
GoogleMap.OnCameraIdleListener {
|
|
49
|
-
|
|
50
|
-
var eventDelegate: LuggGoogleMapViewEventDelegate? = null
|
|
51
|
-
private var mapView: MapView? = null
|
|
52
|
-
private var mapWrapperView: LuggMapWrapperView? = null
|
|
53
|
-
private var googleMap: GoogleMap? = null
|
|
54
|
-
private var isMapReady = false
|
|
55
|
-
private var isDragging = false
|
|
56
|
-
private var mapId: String = DEMO_MAP_ID
|
|
57
|
-
private val pendingMarkerViews = mutableListOf<LuggMarkerView>()
|
|
58
|
-
private val pendingPolylineViews = mutableListOf<LuggPolylineView>()
|
|
59
|
-
private val polylineAnimators = mutableMapOf<LuggPolylineView, PolylineAnimator>()
|
|
60
|
-
|
|
61
|
-
// Initial camera settings
|
|
62
|
-
private var initialLatitude: Double = 37.78
|
|
63
|
-
private var initialLongitude: Double = -122.43
|
|
64
|
-
private var initialZoom: Float = 14f
|
|
65
|
-
|
|
66
|
-
// UI settings
|
|
67
|
-
private var zoomEnabled: Boolean = true
|
|
68
|
-
private var scrollEnabled: Boolean = true
|
|
69
|
-
private var rotateEnabled: Boolean = true
|
|
70
|
-
private var pitchEnabled: Boolean = true
|
|
71
|
-
private var userLocationEnabled: Boolean = false
|
|
72
|
-
|
|
73
|
-
// Zoom limits
|
|
74
|
-
private var minZoom: Float? = null
|
|
75
|
-
private var maxZoom: Float? = null
|
|
76
|
-
|
|
77
|
-
// Padding
|
|
78
|
-
private var paddingTop: Int = 0
|
|
79
|
-
private var paddingLeft: Int = 0
|
|
80
|
-
private var paddingBottom: Int = 0
|
|
81
|
-
private var paddingRight: Int = 0
|
|
82
|
-
|
|
83
|
-
// region View Lifecycle
|
|
84
|
-
|
|
85
|
-
override fun addView(child: View?, index: Int) {
|
|
86
|
-
super.addView(child, index)
|
|
87
|
-
when (child) {
|
|
88
|
-
is LuggMapWrapperView -> mapWrapperView = child
|
|
89
|
-
|
|
90
|
-
is LuggMarkerView -> {
|
|
91
|
-
child.delegate = this
|
|
92
|
-
syncMarkerView(child)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
is LuggPolylineView -> {
|
|
96
|
-
child.delegate = this
|
|
97
|
-
syncPolylineView(child)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
override fun removeViewAt(index: Int) {
|
|
103
|
-
val view = getChildAt(index)
|
|
104
|
-
if (view is LuggMarkerView) {
|
|
105
|
-
view.marker?.remove()
|
|
106
|
-
view.marker = null
|
|
107
|
-
} else if (view is LuggPolylineView) {
|
|
108
|
-
polylineAnimators[view]?.destroy()
|
|
109
|
-
polylineAnimators.remove(view)
|
|
110
|
-
view.polyline?.remove()
|
|
111
|
-
view.polyline = null
|
|
112
|
-
}
|
|
113
|
-
super.removeViewAt(index)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
override fun onAttachedToWindow() {
|
|
117
|
-
super.onAttachedToWindow()
|
|
118
|
-
if (mapView == null && mapWrapperView != null) {
|
|
119
|
-
initializeMap()
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
fun onDropViewInstance() {
|
|
124
|
-
pendingMarkerViews.clear()
|
|
125
|
-
pendingPolylineViews.clear()
|
|
126
|
-
polylineAnimators.values.forEach { it.destroy() }
|
|
127
|
-
polylineAnimators.clear()
|
|
128
|
-
googleMap?.clear()
|
|
129
|
-
googleMap = null
|
|
130
|
-
isMapReady = false
|
|
131
|
-
mapView?.onPause()
|
|
132
|
-
mapView?.onDestroy()
|
|
133
|
-
mapView = null
|
|
134
|
-
mapWrapperView = null
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// endregion
|
|
138
|
-
|
|
139
|
-
// region Map Initialization
|
|
140
|
-
|
|
141
|
-
private fun initializeMap() {
|
|
142
|
-
if (mapView != null || mapWrapperView == null) return
|
|
143
|
-
|
|
144
|
-
val options = GoogleMapOptions().mapId(mapId)
|
|
145
|
-
mapView = MapView(context, options).also { view ->
|
|
146
|
-
view.onCreate(null)
|
|
147
|
-
view.onResume()
|
|
148
|
-
view.getMapAsync(this)
|
|
149
|
-
mapWrapperView?.addView(
|
|
150
|
-
view,
|
|
151
|
-
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
override fun onMapReady(map: GoogleMap) {
|
|
157
|
-
googleMap = map
|
|
158
|
-
isMapReady = true
|
|
159
|
-
|
|
160
|
-
val position = LatLng(initialLatitude, initialLongitude)
|
|
161
|
-
map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, initialZoom))
|
|
162
|
-
|
|
163
|
-
map.setOnCameraMoveStartedListener(this)
|
|
164
|
-
map.setOnCameraMoveListener(this)
|
|
165
|
-
map.setOnCameraIdleListener(this)
|
|
166
|
-
|
|
167
|
-
applyUiSettings()
|
|
168
|
-
applyZoomLimits()
|
|
169
|
-
applyPadding()
|
|
170
|
-
applyUserLocation()
|
|
171
|
-
processPendingMarkers()
|
|
172
|
-
processPendingPolylines()
|
|
173
|
-
|
|
174
|
-
eventDelegate?.onReady(this)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
override fun onCameraMoveStarted(reason: Int) {
|
|
178
|
-
isDragging = reason == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
override fun onCameraMove() {
|
|
182
|
-
val map = googleMap ?: return
|
|
183
|
-
val position = map.cameraPosition
|
|
184
|
-
eventDelegate?.onCameraMove(this, position.target.latitude, position.target.longitude, position.zoom, isDragging)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
override fun onCameraIdle() {
|
|
188
|
-
val map = googleMap ?: return
|
|
189
|
-
val position = map.cameraPosition
|
|
190
|
-
eventDelegate?.onCameraIdle(this, position.target.latitude, position.target.longitude, position.zoom, isDragging)
|
|
191
|
-
isDragging = false
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private fun applyUiSettings() {
|
|
195
|
-
googleMap?.uiSettings?.apply {
|
|
196
|
-
isZoomGesturesEnabled = zoomEnabled
|
|
197
|
-
isScrollGesturesEnabled = scrollEnabled
|
|
198
|
-
isRotateGesturesEnabled = rotateEnabled
|
|
199
|
-
isTiltGesturesEnabled = pitchEnabled
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private fun applyZoomLimits() {
|
|
204
|
-
googleMap?.apply {
|
|
205
|
-
minZoom?.let { setMinZoomPreference(it) }
|
|
206
|
-
maxZoom?.let { setMaxZoomPreference(it) }
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private fun applyPadding() {
|
|
211
|
-
googleMap?.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
@SuppressLint("MissingPermission")
|
|
215
|
-
private fun applyUserLocation() {
|
|
216
|
-
val hasPermission =
|
|
217
|
-
context.checkSelfPermission(
|
|
218
|
-
android.Manifest.permission.ACCESS_FINE_LOCATION
|
|
219
|
-
) == android.content.pm.PackageManager.PERMISSION_GRANTED ||
|
|
220
|
-
context.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
|
|
221
|
-
android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
222
|
-
googleMap?.isMyLocationEnabled = userLocationEnabled && hasPermission
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// endregion
|
|
226
|
-
|
|
227
|
-
// region PolylineViewDelegate
|
|
228
|
-
|
|
229
|
-
override fun polylineViewDidUpdate(polylineView: LuggPolylineView) {
|
|
230
|
-
syncPolylineView(polylineView)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// endregion
|
|
234
|
-
|
|
235
|
-
// region MarkerViewDelegate
|
|
236
|
-
|
|
237
|
-
override fun markerViewDidLayout(markerView: LuggMarkerView) {
|
|
238
|
-
if (googleMap == null) {
|
|
239
|
-
if (!pendingMarkerViews.contains(markerView)) {
|
|
240
|
-
pendingMarkerViews.add(markerView)
|
|
241
|
-
}
|
|
242
|
-
return
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (markerView.hasCustomView) {
|
|
246
|
-
// Recreate marker with custom view
|
|
247
|
-
markerView.marker?.remove()
|
|
248
|
-
addMarkerViewToMap(markerView)
|
|
249
|
-
} else {
|
|
250
|
-
syncMarkerView(markerView)
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
override fun markerViewDidUpdate(markerView: LuggMarkerView) {
|
|
255
|
-
syncMarkerView(markerView)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// endregion
|
|
259
|
-
|
|
260
|
-
// region Marker Management
|
|
261
|
-
|
|
262
|
-
private fun syncMarkerView(markerView: LuggMarkerView) {
|
|
263
|
-
if (googleMap == null) {
|
|
264
|
-
if (!pendingMarkerViews.contains(markerView)) {
|
|
265
|
-
pendingMarkerViews.add(markerView)
|
|
266
|
-
}
|
|
267
|
-
return
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (markerView.marker == null) {
|
|
271
|
-
// Custom views need layout first before adding to map
|
|
272
|
-
if (markerView.hasCustomView) return
|
|
273
|
-
addMarkerViewToMap(markerView)
|
|
274
|
-
return
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
markerView.marker?.apply {
|
|
278
|
-
position = LatLng(markerView.latitude, markerView.longitude)
|
|
279
|
-
title = markerView.title
|
|
280
|
-
snippet = markerView.description
|
|
281
|
-
setAnchor(markerView.anchorX, markerView.anchorY)
|
|
282
|
-
zIndex = markerView.zIndex
|
|
283
|
-
if (!markerView.hasCustomView) {
|
|
284
|
-
iconView = null
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
private fun processPendingMarkers() {
|
|
290
|
-
if (googleMap == null) return
|
|
291
|
-
|
|
292
|
-
pendingMarkerViews.forEach { addMarkerViewToMap(it) }
|
|
293
|
-
pendingMarkerViews.clear()
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
private fun addMarkerViewToMap(markerView: LuggMarkerView) {
|
|
297
|
-
val map = googleMap ?: run {
|
|
298
|
-
RNLog.w(reactContext, "Lugg: addMarkerViewToMap called without a map")
|
|
299
|
-
return
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
val position = LatLng(markerView.latitude, markerView.longitude)
|
|
303
|
-
val iconView = markerView.iconView
|
|
304
|
-
|
|
305
|
-
(iconView.parent as? ViewGroup)?.removeView(iconView)
|
|
306
|
-
|
|
307
|
-
val options = AdvancedMarkerOptions()
|
|
308
|
-
.position(position)
|
|
309
|
-
.title(markerView.title)
|
|
310
|
-
.snippet(markerView.description)
|
|
311
|
-
|
|
312
|
-
if (markerView.hasCustomView) {
|
|
313
|
-
options.iconView(iconView)
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
val marker = map.addMarker(options) as AdvancedMarker
|
|
317
|
-
marker.setAnchor(markerView.anchorX, markerView.anchorY)
|
|
318
|
-
marker.zIndex = markerView.zIndex
|
|
319
|
-
|
|
320
|
-
markerView.marker = marker
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// endregion
|
|
324
|
-
|
|
325
|
-
// region Polyline Management
|
|
326
|
-
|
|
327
|
-
private fun syncPolylineView(polylineView: LuggPolylineView) {
|
|
328
|
-
if (googleMap == null) {
|
|
329
|
-
if (!pendingPolylineViews.contains(polylineView)) {
|
|
330
|
-
pendingPolylineViews.add(polylineView)
|
|
331
|
-
}
|
|
332
|
-
return
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if (polylineView.polyline == null) {
|
|
336
|
-
addPolylineViewToMap(polylineView)
|
|
337
|
-
return
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
polylineView.polyline?.width = polylineView.strokeWidth.dpToPx()
|
|
341
|
-
|
|
342
|
-
polylineAnimators[polylineView]?.apply {
|
|
343
|
-
coordinates = polylineView.coordinates
|
|
344
|
-
strokeColors = polylineView.strokeColors
|
|
345
|
-
strokeWidth = polylineView.strokeWidth.dpToPx()
|
|
346
|
-
animated = polylineView.animated
|
|
347
|
-
update()
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
private fun processPendingPolylines() {
|
|
352
|
-
if (googleMap == null) return
|
|
353
|
-
|
|
354
|
-
pendingPolylineViews.forEach { addPolylineViewToMap(it) }
|
|
355
|
-
pendingPolylineViews.clear()
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
private fun addPolylineViewToMap(polylineView: LuggPolylineView) {
|
|
359
|
-
val map = googleMap ?: return
|
|
360
|
-
|
|
361
|
-
val options = PolylineOptions()
|
|
362
|
-
.width(polylineView.strokeWidth.dpToPx())
|
|
363
|
-
|
|
364
|
-
val polyline = map.addPolyline(options)
|
|
365
|
-
polylineView.polyline = polyline
|
|
366
|
-
|
|
367
|
-
val animator = PolylineAnimator().apply {
|
|
368
|
-
this.polyline = polyline
|
|
369
|
-
coordinates = polylineView.coordinates
|
|
370
|
-
strokeColors = polylineView.strokeColors
|
|
371
|
-
strokeWidth = polylineView.strokeWidth.dpToPx()
|
|
372
|
-
animated = polylineView.animated
|
|
373
|
-
update()
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
polylineAnimators[polylineView] = animator
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// endregion
|
|
380
|
-
|
|
381
|
-
// region Property Setters
|
|
382
|
-
|
|
383
|
-
fun setMapId(value: String?) {
|
|
384
|
-
if (value.isNullOrEmpty()) return
|
|
385
|
-
|
|
386
|
-
if (mapView != null) {
|
|
387
|
-
RNLog.w(reactContext, "Lugg: mapId cannot be changed after map is initialized")
|
|
388
|
-
return
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
mapId = value
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
fun setInitialCoordinate(latitude: Double, longitude: Double) {
|
|
395
|
-
initialLatitude = latitude
|
|
396
|
-
initialLongitude = longitude
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
fun setInitialZoom(zoom: Double) {
|
|
400
|
-
initialZoom = zoom.toFloat()
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
fun setZoomEnabled(enabled: Boolean) {
|
|
404
|
-
zoomEnabled = enabled
|
|
405
|
-
googleMap?.uiSettings?.isZoomGesturesEnabled = enabled
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
fun setScrollEnabled(enabled: Boolean) {
|
|
409
|
-
scrollEnabled = enabled
|
|
410
|
-
googleMap?.uiSettings?.isScrollGesturesEnabled = enabled
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
fun setRotateEnabled(enabled: Boolean) {
|
|
414
|
-
rotateEnabled = enabled
|
|
415
|
-
googleMap?.uiSettings?.isRotateGesturesEnabled = enabled
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
fun setPitchEnabled(enabled: Boolean) {
|
|
419
|
-
pitchEnabled = enabled
|
|
420
|
-
googleMap?.uiSettings?.isTiltGesturesEnabled = enabled
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
fun setUserLocationEnabled(enabled: Boolean) {
|
|
424
|
-
userLocationEnabled = enabled
|
|
425
|
-
applyUserLocation()
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
fun setMinZoom(zoom: Double) {
|
|
429
|
-
minZoom = if (zoom > 0) zoom.toFloat() else null
|
|
430
|
-
googleMap?.let { map ->
|
|
431
|
-
minZoom?.let { map.setMinZoomPreference(it) } ?: map.resetMinMaxZoomPreference()
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
fun setMaxZoom(zoom: Double) {
|
|
436
|
-
maxZoom = if (zoom > 0) zoom.toFloat() else null
|
|
437
|
-
googleMap?.let { map ->
|
|
438
|
-
maxZoom?.let { map.setMaxZoomPreference(it) } ?: map.resetMinMaxZoomPreference()
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
fun setMapPadding(top: Int, left: Int, bottom: Int, right: Int) {
|
|
443
|
-
paddingTop = top
|
|
444
|
-
paddingLeft = left
|
|
445
|
-
paddingBottom = bottom
|
|
446
|
-
paddingRight = right
|
|
447
|
-
applyPadding()
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// endregion
|
|
451
|
-
|
|
452
|
-
// region Commands
|
|
453
|
-
|
|
454
|
-
fun moveCamera(latitude: Double, longitude: Double, zoom: Double, duration: Int) {
|
|
455
|
-
val map = googleMap ?: return
|
|
456
|
-
val position = LatLng(latitude, longitude)
|
|
457
|
-
val cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, zoom.toFloat())
|
|
458
|
-
when {
|
|
459
|
-
duration < 0 -> map.animateCamera(cameraUpdate)
|
|
460
|
-
duration > 0 -> map.animateCamera(cameraUpdate, duration, null)
|
|
461
|
-
else -> map.moveCamera(cameraUpdate)
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
fun fitCoordinates(
|
|
466
|
-
coordinates: List<LatLng>,
|
|
467
|
-
paddingTop: Int,
|
|
468
|
-
paddingLeft: Int,
|
|
469
|
-
paddingBottom: Int,
|
|
470
|
-
paddingRight: Int,
|
|
471
|
-
duration: Int
|
|
472
|
-
) {
|
|
473
|
-
val map = googleMap ?: return
|
|
474
|
-
if (coordinates.isEmpty()) return
|
|
475
|
-
|
|
476
|
-
val boundsBuilder = com.google.android.gms.maps.model.LatLngBounds.Builder()
|
|
477
|
-
coordinates.forEach { boundsBuilder.include(it) }
|
|
478
|
-
val bounds = boundsBuilder.build()
|
|
479
|
-
|
|
480
|
-
val top = paddingTop.toFloat().dpToPx().toInt()
|
|
481
|
-
val left = paddingLeft.toFloat().dpToPx().toInt()
|
|
482
|
-
val bottom = paddingBottom.toFloat().dpToPx().toInt()
|
|
483
|
-
val right = paddingRight.toFloat().dpToPx().toInt()
|
|
484
|
-
|
|
485
|
-
// Set padding before camera update, then restore after
|
|
486
|
-
map.setPadding(
|
|
487
|
-
this.paddingLeft + left,
|
|
488
|
-
this.paddingTop + top,
|
|
489
|
-
this.paddingRight + right,
|
|
490
|
-
this.paddingBottom + bottom
|
|
491
|
-
)
|
|
492
|
-
|
|
493
|
-
val cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 0)
|
|
494
|
-
|
|
495
|
-
when {
|
|
496
|
-
duration < 0 -> map.animateCamera(cameraUpdate)
|
|
497
|
-
duration > 0 -> map.animateCamera(cameraUpdate, duration, null)
|
|
498
|
-
else -> map.moveCamera(cameraUpdate)
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// Restore base padding
|
|
502
|
-
map.setPadding(this.paddingLeft, this.paddingTop, this.paddingRight, this.paddingBottom)
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// endregion
|
|
506
|
-
|
|
507
|
-
companion object {
|
|
508
|
-
private const val TAG = "Lugg"
|
|
509
|
-
const val DEMO_MAP_ID = "DEMO_MAP_ID"
|
|
510
|
-
}
|
|
511
|
-
}
|