react-native-map4d-map-dtqg 0.1.3 → 0.1.4
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/LICENSE +21 -21
- package/README.md +133 -133
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
- package/android/.gradle/9.2.0/fileChanges/last-build.bin +0 -0
- package/android/.gradle/9.2.0/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/9.2.0/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +60 -60
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/com/reactnativemap4dmap/ImageUtils.java +87 -87
- package/android/src/main/java/com/reactnativemap4dmap/Map4dMapModule.java +298 -298
- package/android/src/main/java/com/reactnativemap4dmap/Map4dMapPackage.java +35 -35
- package/android/src/main/java/com/reactnativemap4dmap/Map4dMapViewManager.java +31 -31
- package/android/src/main/java/com/reactnativemap4dmap/RMFBuilding.java +167 -167
- package/android/src/main/java/com/reactnativemap4dmap/RMFBuildingManager.java +121 -121
- package/android/src/main/java/com/reactnativemap4dmap/RMFCircle.java +105 -105
- package/android/src/main/java/com/reactnativemap4dmap/RMFCircleManager.java +121 -121
- package/android/src/main/java/com/reactnativemap4dmap/RMFDirectionsRenderer.java +502 -502
- package/android/src/main/java/com/reactnativemap4dmap/RMFDirectionsRendererManager.java +143 -143
- package/android/src/main/java/com/reactnativemap4dmap/RMFFeature.java +17 -17
- package/android/src/main/java/com/reactnativemap4dmap/RMFMapView.java +1172 -1172
- package/android/src/main/java/com/reactnativemap4dmap/RMFMapViewManager.java +231 -231
- package/android/src/main/java/com/reactnativemap4dmap/RMFMarker.java +412 -412
- package/android/src/main/java/com/reactnativemap4dmap/RMFMarkerManager.java +211 -211
- package/android/src/main/java/com/reactnativemap4dmap/RMFPOI.java +222 -222
- package/android/src/main/java/com/reactnativemap4dmap/RMFPOIManager.java +119 -119
- package/android/src/main/java/com/reactnativemap4dmap/RMFPolygon.java +172 -172
- package/android/src/main/java/com/reactnativemap4dmap/RMFPolygonManager.java +147 -147
- package/android/src/main/java/com/reactnativemap4dmap/RMFPolyline.java +146 -146
- package/android/src/main/java/com/reactnativemap4dmap/RMFPolylineManager.java +137 -137
- package/android/src/main/java/com/reactnativemap4dmap/RMFTileOverlay.java +95 -95
- package/android/src/main/java/com/reactnativemap4dmap/RMFTileOverlayManager.java +64 -64
- package/android/src/main/java/com/reactnativemap4dmap/SizeReportingShadowNode.java +31 -31
- package/android/src/main/java/com/reactnativemap4dmap/ViewAttacherGroup.java +31 -31
- package/android/src/main/java/com/reactnativemap4dmap/ViewChangesTracker.java +70 -70
- package/android/src/main/java/vn/map4d/map/annotations/RMFBitmapDescriptor.java +9 -9
- package/ios/Map4dMap.h +7 -7
- package/ios/Map4dMap.m +14 -14
- package/ios/Map4dMapViewManager.m +34 -34
- package/ios/RCTConvert+Map4dMap.h +33 -33
- package/ios/RCTConvert+Map4dMap.m +112 -112
- package/ios/RMFCircle.h +37 -37
- package/ios/RMFCircle.m +100 -100
- package/ios/RMFCircleManager.h +18 -18
- package/ios/RMFCircleManager.m +155 -155
- package/ios/RMFCircleMap4d.h +23 -23
- package/ios/RMFCircleMap4d.m +13 -13
- package/ios/RMFCoordinate.h +22 -22
- package/ios/RMFCoordinate.m +13 -13
- package/ios/RMFDirectionsMarkerOptions.h +24 -24
- package/ios/RMFDirectionsMarkerOptions.m +23 -23
- package/ios/RMFDirectionsRenderer.h +47 -47
- package/ios/RMFDirectionsRenderer.m +182 -182
- package/ios/RMFDirectionsRendererManager.h +17 -17
- package/ios/RMFDirectionsRendererManager.m +84 -84
- package/ios/RMFDirectionsRendererMap4d.h +21 -21
- package/ios/RMFDirectionsRendererMap4d.m +12 -12
- package/ios/RMFDummyView.h +6 -6
- package/ios/RMFDummyView.m +12 -12
- package/ios/RMFEventResponse.h +39 -39
- package/ios/RMFEventResponse.m +98 -98
- package/ios/RMFIcon.h +24 -24
- package/ios/RMFIcon.m +35 -35
- package/ios/RMFMapView.h +84 -84
- package/ios/RMFMapView.m +376 -376
- package/ios/RMFMapViewManager.h +17 -17
- package/ios/RMFMapViewManager.m +509 -509
- package/ios/RMFMarker.h +57 -57
- package/ios/RMFMarker.m +267 -267
- package/ios/RMFMarkerManager.h +17 -17
- package/ios/RMFMarkerManager.m +156 -156
- package/ios/RMFMarkerMap4d.h +19 -19
- package/ios/RMFMarkerMap4d.m +13 -13
- package/ios/RMFPOI.h +38 -38
- package/ios/RMFPOI.m +123 -123
- package/ios/RMFPOIManager.h +18 -18
- package/ios/RMFPOIManager.m +168 -168
- package/ios/RMFPOIMap4d.h +22 -22
- package/ios/RMFPOIMap4d.m +12 -12
- package/ios/RMFPolygon.h +41 -41
- package/ios/RMFPolygon.m +106 -106
- package/ios/RMFPolygonManager.h +18 -18
- package/ios/RMFPolygonManager.m +141 -141
- package/ios/RMFPolygonMap4d.h +23 -23
- package/ios/RMFPolygonMap4d.m +15 -15
- package/ios/RMFPolyline.h +38 -38
- package/ios/RMFPolyline.m +101 -101
- package/ios/RMFPolylineManager.h +18 -18
- package/ios/RMFPolylineManager.m +139 -139
- package/ios/RMFPolylineMap4d.h +22 -22
- package/ios/RMFPolylineMap4d.m +15 -15
- package/ios/building/RMFBuilding.h +41 -41
- package/ios/building/RMFBuilding.m +104 -104
- package/ios/building/RMFBuildingManager.h +19 -19
- package/ios/building/RMFBuildingManager.m +133 -133
- package/ios/building/RMFBuildingMap4d.h +23 -23
- package/ios/building/RMFBuildingMap4d.m +15 -15
- package/ios/overlays/RMFTileOverlay.h +36 -36
- package/ios/overlays/RMFTileOverlay.m +64 -64
- package/ios/overlays/RMFTileOverlayManager.h +17 -17
- package/ios/overlays/RMFTileOverlayManager.m +27 -27
- package/lib/commonjs/components/MFBanDoSo.js.map +1 -1
- package/lib/commonjs/components/MFBuilding.js +50 -32
- package/lib/commonjs/components/MFBuilding.js.map +1 -1
- package/lib/commonjs/components/MFCircle.js +44 -26
- package/lib/commonjs/components/MFCircle.js.map +1 -1
- package/lib/commonjs/components/MFDirectionsRenderer.js +56 -38
- package/lib/commonjs/components/MFDirectionsRenderer.js.map +1 -1
- package/lib/commonjs/components/MFMapView.js +91 -74
- package/lib/commonjs/components/MFMapView.js.map +1 -1
- package/lib/commonjs/components/MFMarker.js +59 -41
- package/lib/commonjs/components/MFMarker.js.map +1 -1
- package/lib/commonjs/components/MFPOI.js +44 -26
- package/lib/commonjs/components/MFPOI.js.map +1 -1
- package/lib/commonjs/components/MFPolygon.js +46 -28
- package/lib/commonjs/components/MFPolygon.js.map +1 -1
- package/lib/commonjs/components/MFPolyline.js +42 -24
- package/lib/commonjs/components/MFPolyline.js.map +1 -1
- package/lib/commonjs/components/MFTileOverlay.js +9 -9
- package/lib/commonjs/components/MFTileOverlay.js.map +1 -1
- package/lib/commonjs/components/Map4dMapView.js.map +1 -1
- package/lib/commonjs/components/extends/AreaFocusManager.js +16 -16
- package/lib/commonjs/components/extends/AreaFocusManager.js.map +1 -1
- package/lib/commonjs/components/extends/AreaFocuser.js +2 -2
- package/lib/commonjs/components/extends/AreaFocuser.js.map +1 -1
- package/lib/commonjs/components/extends/BoundHelper.js.map +1 -1
- package/lib/commonjs/components/extends/area/AreaFocusAreas.js.map +1 -1
- package/lib/commonjs/components/extends/area/AreaFocusGeometryUtils.js.map +1 -1
- package/lib/commonjs/components/extends/area/AreaFocusSession.js.map +1 -1
- package/lib/commonjs/components/extends/area/AreaFocusTypes.js +18 -18
- package/lib/commonjs/components/extends/area/AreaFocusTypes.js.map +1 -1
- package/lib/commonjs/components/internal/DefaultRoadmapStyle.js.map +1 -1
- package/lib/commonjs/components/internal/GeojsonStyleUtils.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/MFBanDoSo.js.map +1 -1
- package/lib/module/components/MFBuilding.js +51 -33
- package/lib/module/components/MFBuilding.js.map +1 -1
- package/lib/module/components/MFCircle.js +45 -27
- package/lib/module/components/MFCircle.js.map +1 -1
- package/lib/module/components/MFDirectionsRenderer.js +57 -39
- package/lib/module/components/MFDirectionsRenderer.js.map +1 -1
- package/lib/module/components/MFMapView.js +92 -75
- package/lib/module/components/MFMapView.js.map +1 -1
- package/lib/module/components/MFMarker.js +60 -42
- package/lib/module/components/MFMarker.js.map +1 -1
- package/lib/module/components/MFPOI.js +45 -27
- package/lib/module/components/MFPOI.js.map +1 -1
- package/lib/module/components/MFPolygon.js +47 -29
- package/lib/module/components/MFPolygon.js.map +1 -1
- package/lib/module/components/MFPolyline.js +43 -25
- package/lib/module/components/MFPolyline.js.map +1 -1
- package/lib/module/components/MFTileOverlay.js +9 -9
- package/lib/module/components/MFTileOverlay.js.map +1 -1
- package/lib/module/components/Map4dMapView.js.map +1 -1
- package/lib/module/components/extends/AreaFocusManager.js +16 -16
- package/lib/module/components/extends/AreaFocusManager.js.map +1 -1
- package/lib/module/components/extends/AreaFocuser.js +2 -2
- package/lib/module/components/extends/AreaFocuser.js.map +1 -1
- package/lib/module/components/extends/BoundHelper.js.map +1 -1
- package/lib/module/components/extends/area/AreaFocusAreas.js.map +1 -1
- package/lib/module/components/extends/area/AreaFocusGeometryUtils.js.map +1 -1
- package/lib/module/components/extends/area/AreaFocusSession.js.map +1 -1
- package/lib/module/components/extends/area/AreaFocusTypes.js +18 -18
- package/lib/module/components/extends/area/AreaFocusTypes.js.map +1 -1
- package/lib/module/components/internal/DefaultRoadmapStyle.js.map +1 -1
- package/lib/module/components/internal/GeojsonStyleUtils.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/Map4dMapView.d.ts +7 -7
- package/package.json +152 -152
- package/react-native-map4d-map.podspec +20 -20
- package/src/components/MFBanDoSo.js +124 -124
- package/src/components/MFBuilding.js +200 -187
- package/src/components/MFCircle.js +186 -173
- package/src/components/MFDirectionsRenderer.js +250 -237
- package/src/components/MFMapView.js +480 -464
- package/src/components/MFMarker.js +259 -246
- package/src/components/MFPOI.js +197 -184
- package/src/components/MFPolygon.js +199 -186
- package/src/components/MFPolyline.js +185 -172
- package/src/components/MFTileOverlay.js +45 -45
- package/src/components/Map4dMapView.tsx +26 -26
- package/src/components/extends/AreaFocusManager.js +196 -196
- package/src/components/extends/AreaFocuser.js +61 -61
- package/src/components/extends/BoundHelper.js +31 -31
- package/src/components/extends/area/AreaFocusAreas.js +164 -164
- package/src/components/extends/area/AreaFocusGeometryUtils.js +164 -164
- package/src/components/extends/area/AreaFocusSession.js +100 -100
- package/src/components/extends/area/AreaFocusTypes.js +36 -36
- package/src/components/internal/DefaultRoadmapStyle.js +3365 -3365
- package/src/components/internal/GeojsonStyleUtils.js +143 -143
- package/src/index.js +25 -25
|
@@ -1,412 +1,412 @@
|
|
|
1
|
-
package com.reactnativemap4dmap;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.BitmapFactory;
|
|
5
|
-
import android.graphics.Color;
|
|
6
|
-
import android.graphics.Canvas;
|
|
7
|
-
import android.graphics.drawable.Drawable;
|
|
8
|
-
import android.view.View;
|
|
9
|
-
import android.graphics.drawable.Animatable;
|
|
10
|
-
import android.graphics.Bitmap;
|
|
11
|
-
import android.net.Uri;
|
|
12
|
-
|
|
13
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
14
|
-
|
|
15
|
-
import com.facebook.common.references.CloseableReference;
|
|
16
|
-
import com.facebook.datasource.DataSource;
|
|
17
|
-
import com.facebook.drawee.backends.pipeline.Fresco;
|
|
18
|
-
import com.facebook.drawee.view.DraweeHolder;
|
|
19
|
-
import com.facebook.drawee.interfaces.DraweeController;
|
|
20
|
-
import com.facebook.drawee.controller.ControllerListener;
|
|
21
|
-
import com.facebook.drawee.controller.BaseControllerListener;
|
|
22
|
-
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
|
23
|
-
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
|
24
|
-
import com.facebook.drawee.drawable.ScalingUtils;
|
|
25
|
-
import com.facebook.imagepipeline.image.CloseableImage;
|
|
26
|
-
import com.facebook.imagepipeline.image.ImageInfo;
|
|
27
|
-
import com.facebook.imagepipeline.request.ImageRequest;
|
|
28
|
-
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
29
|
-
import com.facebook.imagepipeline.image.CloseableStaticBitmap;
|
|
30
|
-
import com.facebook.imagepipeline.core.ImagePipeline;
|
|
31
|
-
import com.facebook.imagepipeline.common.ResizeOptions;
|
|
32
|
-
|
|
33
|
-
import vn.map4d.map.core.*;
|
|
34
|
-
import vn.map4d.map.annotations.*;
|
|
35
|
-
|
|
36
|
-
import vn.map4d.types.MFLocationCoordinate;
|
|
37
|
-
import vn.map4d.utils.android.collections.MFMarkerManager;
|
|
38
|
-
|
|
39
|
-
import javax.annotation.Nullable;
|
|
40
|
-
|
|
41
|
-
public class RMFMarker extends RMFFeature {
|
|
42
|
-
private MFMarkerOptions markerOptions;
|
|
43
|
-
private MFLocationCoordinate position;
|
|
44
|
-
private double rotation;
|
|
45
|
-
private String title;
|
|
46
|
-
private String snippet;
|
|
47
|
-
private boolean draggable;
|
|
48
|
-
private float zIndex;
|
|
49
|
-
private boolean visible;
|
|
50
|
-
private float windowAnchorU;
|
|
51
|
-
private float windowAnchorV;
|
|
52
|
-
private double anchorU;
|
|
53
|
-
private double anchorV;
|
|
54
|
-
private double elevation;
|
|
55
|
-
private MFBitmapDescriptor iconBitmapDescriptor;
|
|
56
|
-
private Bitmap iconBitmap;
|
|
57
|
-
private Bitmap mLastBitmapCreated = null;
|
|
58
|
-
private String userData;
|
|
59
|
-
private MFMarker marker;
|
|
60
|
-
|
|
61
|
-
private boolean hasCustomMarkerView = false;
|
|
62
|
-
private boolean tracksViewChangesActive = false;
|
|
63
|
-
|
|
64
|
-
private int width;
|
|
65
|
-
private int height;
|
|
66
|
-
|
|
67
|
-
private MFMarkerManager.Collection markerCollection;
|
|
68
|
-
|
|
69
|
-
private final DraweeHolder<?> logoHolder;
|
|
70
|
-
private DataSource<CloseableReference<CloseableImage>> dataSource;
|
|
71
|
-
private final ControllerListener<ImageInfo> mLogoControllerListener =
|
|
72
|
-
new BaseControllerListener<ImageInfo>() {
|
|
73
|
-
@Override
|
|
74
|
-
public void onFinalImageSet(
|
|
75
|
-
String id,
|
|
76
|
-
@Nullable final ImageInfo imageInfo,
|
|
77
|
-
@Nullable Animatable animatable) {
|
|
78
|
-
CloseableReference<CloseableImage> imageReference = null;
|
|
79
|
-
try {
|
|
80
|
-
imageReference = dataSource.getResult();
|
|
81
|
-
if (imageReference != null) {
|
|
82
|
-
CloseableImage image = imageReference.get();
|
|
83
|
-
if (image != null && image instanceof CloseableStaticBitmap) {
|
|
84
|
-
CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
|
|
85
|
-
Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
|
|
86
|
-
if (bitmap != null) {
|
|
87
|
-
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
88
|
-
iconBitmap = bitmap;
|
|
89
|
-
iconBitmapDescriptor = MFBitmapDescriptorFactory.fromBitmap(bitmap);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} finally {
|
|
94
|
-
dataSource.close();
|
|
95
|
-
if (imageReference != null) {
|
|
96
|
-
CloseableReference.closeSafely(imageReference);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (RMFMarker.this.marker != null) {
|
|
101
|
-
RMFMarker.this.marker.setIcon(iconBitmapDescriptor);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
public RMFMarker(Context context) {
|
|
107
|
-
super(context);
|
|
108
|
-
this.position = new MFLocationCoordinate(0, 0);
|
|
109
|
-
this.rotation = 0.0;
|
|
110
|
-
this.title = "";
|
|
111
|
-
this.snippet = "";
|
|
112
|
-
this.draggable = false;
|
|
113
|
-
this.zIndex = 0.0f;
|
|
114
|
-
this.visible = true;
|
|
115
|
-
this.windowAnchorU = 0.5f;
|
|
116
|
-
this.windowAnchorV = 0.0f;
|
|
117
|
-
this.anchorU = 0.5;
|
|
118
|
-
this.anchorV = 0.5;
|
|
119
|
-
this.elevation = 0.0;
|
|
120
|
-
this.userData = null;
|
|
121
|
-
|
|
122
|
-
logoHolder = DraweeHolder.create(createDraweeHierarchy(), context);
|
|
123
|
-
logoHolder.onAttach();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private GenericDraweeHierarchy createDraweeHierarchy() {
|
|
127
|
-
return new GenericDraweeHierarchyBuilder(getResources())
|
|
128
|
-
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
|
|
129
|
-
.setFadeDuration(0)
|
|
130
|
-
.build();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public void setIcon(String uri, int width, int height) {
|
|
134
|
-
if (uri == null) {
|
|
135
|
-
iconBitmapDescriptor = null;
|
|
136
|
-
}
|
|
137
|
-
else if (uri.startsWith("http://") || uri.startsWith("https://") ||
|
|
138
|
-
uri.startsWith("file://") || uri.startsWith("asset://") || uri.startsWith("data:")) {
|
|
139
|
-
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri));
|
|
140
|
-
if (width != 0 && height != 0) {
|
|
141
|
-
builder.setResizeOptions(ResizeOptions.forDimensions(width, height));
|
|
142
|
-
}
|
|
143
|
-
ImageRequest imageRequest = builder.build();
|
|
144
|
-
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
|
145
|
-
dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
|
|
146
|
-
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
|
147
|
-
.setImageRequest(imageRequest)
|
|
148
|
-
.setControllerListener(mLogoControllerListener)
|
|
149
|
-
.setOldController(logoHolder.getController())
|
|
150
|
-
.build();
|
|
151
|
-
logoHolder.setController(controller);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
iconBitmapDescriptor = ImageUtils.getBitmapByName(this, uri, width, height);
|
|
155
|
-
if (iconBitmapDescriptor != null) {
|
|
156
|
-
int drawableId = ImageUtils.getDrawableResourceByName(this, uri);
|
|
157
|
-
iconBitmap = BitmapFactory.decodeResource(getResources(), drawableId);
|
|
158
|
-
if (iconBitmap == null) { // VectorDrawable or similar
|
|
159
|
-
Drawable drawable = getResources().getDrawable(drawableId);
|
|
160
|
-
iconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
161
|
-
drawable.setBounds(0, 0, width, height);
|
|
162
|
-
Canvas canvas = new Canvas(iconBitmap);
|
|
163
|
-
drawable.draw(canvas);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public void setPosition(ReadableMap data) {
|
|
170
|
-
this.position = new MFLocationCoordinate(data.getDouble("latitude"), data.getDouble("longitude"));
|
|
171
|
-
if (marker != null) {
|
|
172
|
-
marker.setPosition(this.position);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public void setRotation(double rotation) {
|
|
177
|
-
this.rotation = rotation;
|
|
178
|
-
if (marker != null) {
|
|
179
|
-
marker.setRotation(this.rotation);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public void setTitle(String title) {
|
|
184
|
-
this.title = title;
|
|
185
|
-
if (marker != null) {
|
|
186
|
-
marker.setTitle(this.title);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
public void setSnippet(String snippet) {
|
|
191
|
-
this.snippet = snippet;
|
|
192
|
-
if (marker != null) {
|
|
193
|
-
marker.setSnippet(this.snippet);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
public void setDraggable(boolean draggable) {
|
|
198
|
-
this.draggable = draggable;
|
|
199
|
-
if (marker != null) {
|
|
200
|
-
marker.setDraggable(this.draggable);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public void setZIndex(double zIndex) {
|
|
205
|
-
this.zIndex = (float) zIndex;
|
|
206
|
-
if (marker != null) {
|
|
207
|
-
marker.setZIndex(this.zIndex);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public void setVisible(boolean visible) {
|
|
212
|
-
this.visible = visible;
|
|
213
|
-
if (marker != null) {
|
|
214
|
-
marker.setVisible(this.visible);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
public void setAnchor(ReadableMap data) {
|
|
219
|
-
this.anchorU = data != null && data.hasKey("x") ? data.getDouble("x") : 0.5;
|
|
220
|
-
this.anchorV = data != null && data.hasKey("y") ? data.getDouble("y") : 0.5;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
public void setInfoWindowAnchor(ReadableMap data) {
|
|
224
|
-
double x = data != null && data.hasKey("x") ? data.getDouble("x") : 0.5;
|
|
225
|
-
double y = data != null && data.hasKey("y") ? data.getDouble("y") : 0.0;
|
|
226
|
-
this.windowAnchorU = (float) x;
|
|
227
|
-
this.windowAnchorV = (float) y;
|
|
228
|
-
if (marker != null) {
|
|
229
|
-
marker.setWindowAnchor(this.windowAnchorU, this.windowAnchorV);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
public void setElevation(double elevation) {
|
|
234
|
-
this.elevation = elevation;
|
|
235
|
-
if (marker != null) {
|
|
236
|
-
marker.setElevation(elevation);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
public void setUserData(ReadableMap userData) {
|
|
241
|
-
this.userData = userData.toString();
|
|
242
|
-
if (marker != null) {
|
|
243
|
-
marker.setUserData(this.userData);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
public void setMarkerCollection(MFMarkerManager.Collection markerCollection) {
|
|
248
|
-
this.markerCollection = markerCollection;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public void addToMap(Map4D map) {
|
|
252
|
-
/** Because use Utils library, we should use marker collection to add Marker to Map **/
|
|
253
|
-
this.marker = markerCollection.addMarker(getMarkerOptions());
|
|
254
|
-
updateTracksViewChanges();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
public void removeFromMap(Map4D map) {
|
|
258
|
-
if (marker == null) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
/** Because use Utils library, we should use marker collection to remove Marker from Map **/
|
|
262
|
-
markerCollection.remove(marker);
|
|
263
|
-
marker = null;
|
|
264
|
-
updateTracksViewChanges();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
public MFMarkerOptions getMarkerOptions() {
|
|
268
|
-
if (markerOptions == null) {
|
|
269
|
-
markerOptions = new MFMarkerOptions();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
fillMarkerOptions(markerOptions);
|
|
273
|
-
return markerOptions;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private MFMarkerOptions fillMarkerOptions(MFMarkerOptions options) {
|
|
277
|
-
options.position(position);
|
|
278
|
-
options.anchor((float) anchorU, (float) anchorV);
|
|
279
|
-
options.infoWindowAnchor(windowAnchorU, windowAnchorV);
|
|
280
|
-
options.title(title);
|
|
281
|
-
options.snippet(snippet);
|
|
282
|
-
options.rotation(rotation);
|
|
283
|
-
options.draggable(draggable);
|
|
284
|
-
options.elevation(elevation);
|
|
285
|
-
options.zIndex(zIndex);
|
|
286
|
-
options.icon(getIcon());
|
|
287
|
-
options.userData(userData);
|
|
288
|
-
return options;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
private MFBitmapDescriptor getIcon() {
|
|
292
|
-
if (hasCustomMarkerView) {
|
|
293
|
-
// creating a bitmap from an arbitrary view
|
|
294
|
-
if (iconBitmapDescriptor != null) {
|
|
295
|
-
Bitmap viewBitmap = createDrawable();
|
|
296
|
-
int width = Math.max(iconBitmap.getWidth(), viewBitmap.getWidth());
|
|
297
|
-
int height = Math.max(iconBitmap.getHeight(), viewBitmap.getHeight());
|
|
298
|
-
Bitmap combinedBitmap = Bitmap.createBitmap(width, height, iconBitmap.getConfig());
|
|
299
|
-
Canvas canvas = new Canvas(combinedBitmap);
|
|
300
|
-
canvas.drawBitmap(iconBitmap, 0, 0, null);
|
|
301
|
-
canvas.drawBitmap(viewBitmap, 0, 0, null);
|
|
302
|
-
return MFBitmapDescriptorFactory.fromBitmap(combinedBitmap);
|
|
303
|
-
} else {
|
|
304
|
-
return MFBitmapDescriptorFactory.fromBitmap(createDrawable());
|
|
305
|
-
}
|
|
306
|
-
} else if (iconBitmapDescriptor != null) {
|
|
307
|
-
// use local image as a marker
|
|
308
|
-
return iconBitmapDescriptor;
|
|
309
|
-
} else {
|
|
310
|
-
// render the default marker
|
|
311
|
-
return MFBitmapDescriptorFactory.defaultMarker();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
public void update(int width, int height) {
|
|
316
|
-
this.width = width;
|
|
317
|
-
this.height = height;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
private Bitmap createDrawable() {
|
|
321
|
-
int width = this.width <= 0 ? 100 : this.width;
|
|
322
|
-
int height = this.height <= 0 ? 100 : this.height;
|
|
323
|
-
this.buildDrawingCache();
|
|
324
|
-
|
|
325
|
-
// Do not create the doublebuffer-bitmap each time. reuse it to save memory.
|
|
326
|
-
Bitmap bitmap = mLastBitmapCreated;
|
|
327
|
-
|
|
328
|
-
if (bitmap == null ||
|
|
329
|
-
bitmap.isRecycled() ||
|
|
330
|
-
bitmap.getWidth() != width ||
|
|
331
|
-
bitmap.getHeight() != height) {
|
|
332
|
-
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
333
|
-
mLastBitmapCreated = bitmap;
|
|
334
|
-
} else {
|
|
335
|
-
bitmap.eraseColor(Color.TRANSPARENT);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
Canvas canvas = new Canvas(bitmap);
|
|
339
|
-
this.draw(canvas);
|
|
340
|
-
|
|
341
|
-
return bitmap;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
@Override
|
|
345
|
-
public void addView(View child, int index) {
|
|
346
|
-
super.addView(child, index);
|
|
347
|
-
// if children are added, it means we are rendering a custom marker
|
|
348
|
-
hasCustomMarkerView = true;
|
|
349
|
-
updateTracksViewChanges();
|
|
350
|
-
updateMarkerIcon();
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
private void updateTracksViewChanges() {
|
|
354
|
-
boolean shouldTrack = hasCustomMarkerView && marker != null;
|
|
355
|
-
if (shouldTrack == tracksViewChangesActive) return;
|
|
356
|
-
tracksViewChangesActive = shouldTrack;
|
|
357
|
-
|
|
358
|
-
if (shouldTrack) {
|
|
359
|
-
ViewChangesTracker.getInstance().addMarker(this);
|
|
360
|
-
} else {
|
|
361
|
-
ViewChangesTracker.getInstance().removeMarker(this);
|
|
362
|
-
|
|
363
|
-
// Let it render one more time to avoid race conditions.
|
|
364
|
-
// i.e. Image onLoad ->
|
|
365
|
-
// ViewChangesTracker may not get a chance to render ->
|
|
366
|
-
// setState({ tracksViewChanges: false }) ->
|
|
367
|
-
// image loaded but not rendered.
|
|
368
|
-
updateMarkerIcon();
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
public void updateMarkerIcon() {
|
|
373
|
-
if (marker != null) {
|
|
374
|
-
marker.setIcon(getIcon());
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
public boolean updateCustomForTracking() {
|
|
379
|
-
if (!tracksViewChangesActive)
|
|
380
|
-
return false;
|
|
381
|
-
updateMarkerIcon();
|
|
382
|
-
return true;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
private void clearDrawableCache() {
|
|
386
|
-
mLastBitmapCreated = null;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
@Override
|
|
390
|
-
public void requestLayout() {
|
|
391
|
-
super.requestLayout();
|
|
392
|
-
if (getChildCount() == 0) {
|
|
393
|
-
if (hasCustomMarkerView) {
|
|
394
|
-
hasCustomMarkerView = false;
|
|
395
|
-
clearDrawableCache();
|
|
396
|
-
updateTracksViewChanges();
|
|
397
|
-
updateMarkerIcon();
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
@Override
|
|
403
|
-
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
404
|
-
super.onLayout(changed, l, t, r, b);
|
|
405
|
-
this.height = b - t;
|
|
406
|
-
this.width = r - l;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
public Object getFeature() {
|
|
410
|
-
return marker;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
1
|
+
package com.reactnativemap4dmap;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.BitmapFactory;
|
|
5
|
+
import android.graphics.Color;
|
|
6
|
+
import android.graphics.Canvas;
|
|
7
|
+
import android.graphics.drawable.Drawable;
|
|
8
|
+
import android.view.View;
|
|
9
|
+
import android.graphics.drawable.Animatable;
|
|
10
|
+
import android.graphics.Bitmap;
|
|
11
|
+
import android.net.Uri;
|
|
12
|
+
|
|
13
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
14
|
+
|
|
15
|
+
import com.facebook.common.references.CloseableReference;
|
|
16
|
+
import com.facebook.datasource.DataSource;
|
|
17
|
+
import com.facebook.drawee.backends.pipeline.Fresco;
|
|
18
|
+
import com.facebook.drawee.view.DraweeHolder;
|
|
19
|
+
import com.facebook.drawee.interfaces.DraweeController;
|
|
20
|
+
import com.facebook.drawee.controller.ControllerListener;
|
|
21
|
+
import com.facebook.drawee.controller.BaseControllerListener;
|
|
22
|
+
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
|
23
|
+
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
|
24
|
+
import com.facebook.drawee.drawable.ScalingUtils;
|
|
25
|
+
import com.facebook.imagepipeline.image.CloseableImage;
|
|
26
|
+
import com.facebook.imagepipeline.image.ImageInfo;
|
|
27
|
+
import com.facebook.imagepipeline.request.ImageRequest;
|
|
28
|
+
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
29
|
+
import com.facebook.imagepipeline.image.CloseableStaticBitmap;
|
|
30
|
+
import com.facebook.imagepipeline.core.ImagePipeline;
|
|
31
|
+
import com.facebook.imagepipeline.common.ResizeOptions;
|
|
32
|
+
|
|
33
|
+
import vn.map4d.map.core.*;
|
|
34
|
+
import vn.map4d.map.annotations.*;
|
|
35
|
+
|
|
36
|
+
import vn.map4d.types.MFLocationCoordinate;
|
|
37
|
+
import vn.map4d.utils.android.collections.MFMarkerManager;
|
|
38
|
+
|
|
39
|
+
import javax.annotation.Nullable;
|
|
40
|
+
|
|
41
|
+
public class RMFMarker extends RMFFeature {
|
|
42
|
+
private MFMarkerOptions markerOptions;
|
|
43
|
+
private MFLocationCoordinate position;
|
|
44
|
+
private double rotation;
|
|
45
|
+
private String title;
|
|
46
|
+
private String snippet;
|
|
47
|
+
private boolean draggable;
|
|
48
|
+
private float zIndex;
|
|
49
|
+
private boolean visible;
|
|
50
|
+
private float windowAnchorU;
|
|
51
|
+
private float windowAnchorV;
|
|
52
|
+
private double anchorU;
|
|
53
|
+
private double anchorV;
|
|
54
|
+
private double elevation;
|
|
55
|
+
private MFBitmapDescriptor iconBitmapDescriptor;
|
|
56
|
+
private Bitmap iconBitmap;
|
|
57
|
+
private Bitmap mLastBitmapCreated = null;
|
|
58
|
+
private String userData;
|
|
59
|
+
private MFMarker marker;
|
|
60
|
+
|
|
61
|
+
private boolean hasCustomMarkerView = false;
|
|
62
|
+
private boolean tracksViewChangesActive = false;
|
|
63
|
+
|
|
64
|
+
private int width;
|
|
65
|
+
private int height;
|
|
66
|
+
|
|
67
|
+
private MFMarkerManager.Collection markerCollection;
|
|
68
|
+
|
|
69
|
+
private final DraweeHolder<?> logoHolder;
|
|
70
|
+
private DataSource<CloseableReference<CloseableImage>> dataSource;
|
|
71
|
+
private final ControllerListener<ImageInfo> mLogoControllerListener =
|
|
72
|
+
new BaseControllerListener<ImageInfo>() {
|
|
73
|
+
@Override
|
|
74
|
+
public void onFinalImageSet(
|
|
75
|
+
String id,
|
|
76
|
+
@Nullable final ImageInfo imageInfo,
|
|
77
|
+
@Nullable Animatable animatable) {
|
|
78
|
+
CloseableReference<CloseableImage> imageReference = null;
|
|
79
|
+
try {
|
|
80
|
+
imageReference = dataSource.getResult();
|
|
81
|
+
if (imageReference != null) {
|
|
82
|
+
CloseableImage image = imageReference.get();
|
|
83
|
+
if (image != null && image instanceof CloseableStaticBitmap) {
|
|
84
|
+
CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
|
|
85
|
+
Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
|
|
86
|
+
if (bitmap != null) {
|
|
87
|
+
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
88
|
+
iconBitmap = bitmap;
|
|
89
|
+
iconBitmapDescriptor = MFBitmapDescriptorFactory.fromBitmap(bitmap);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
dataSource.close();
|
|
95
|
+
if (imageReference != null) {
|
|
96
|
+
CloseableReference.closeSafely(imageReference);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (RMFMarker.this.marker != null) {
|
|
101
|
+
RMFMarker.this.marker.setIcon(iconBitmapDescriptor);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
public RMFMarker(Context context) {
|
|
107
|
+
super(context);
|
|
108
|
+
this.position = new MFLocationCoordinate(0, 0);
|
|
109
|
+
this.rotation = 0.0;
|
|
110
|
+
this.title = "";
|
|
111
|
+
this.snippet = "";
|
|
112
|
+
this.draggable = false;
|
|
113
|
+
this.zIndex = 0.0f;
|
|
114
|
+
this.visible = true;
|
|
115
|
+
this.windowAnchorU = 0.5f;
|
|
116
|
+
this.windowAnchorV = 0.0f;
|
|
117
|
+
this.anchorU = 0.5;
|
|
118
|
+
this.anchorV = 0.5;
|
|
119
|
+
this.elevation = 0.0;
|
|
120
|
+
this.userData = null;
|
|
121
|
+
|
|
122
|
+
logoHolder = DraweeHolder.create(createDraweeHierarchy(), context);
|
|
123
|
+
logoHolder.onAttach();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private GenericDraweeHierarchy createDraweeHierarchy() {
|
|
127
|
+
return new GenericDraweeHierarchyBuilder(getResources())
|
|
128
|
+
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
|
|
129
|
+
.setFadeDuration(0)
|
|
130
|
+
.build();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public void setIcon(String uri, int width, int height) {
|
|
134
|
+
if (uri == null) {
|
|
135
|
+
iconBitmapDescriptor = null;
|
|
136
|
+
}
|
|
137
|
+
else if (uri.startsWith("http://") || uri.startsWith("https://") ||
|
|
138
|
+
uri.startsWith("file://") || uri.startsWith("asset://") || uri.startsWith("data:")) {
|
|
139
|
+
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri));
|
|
140
|
+
if (width != 0 && height != 0) {
|
|
141
|
+
builder.setResizeOptions(ResizeOptions.forDimensions(width, height));
|
|
142
|
+
}
|
|
143
|
+
ImageRequest imageRequest = builder.build();
|
|
144
|
+
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
|
145
|
+
dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
|
|
146
|
+
DraweeController controller = Fresco.newDraweeControllerBuilder()
|
|
147
|
+
.setImageRequest(imageRequest)
|
|
148
|
+
.setControllerListener(mLogoControllerListener)
|
|
149
|
+
.setOldController(logoHolder.getController())
|
|
150
|
+
.build();
|
|
151
|
+
logoHolder.setController(controller);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
iconBitmapDescriptor = ImageUtils.getBitmapByName(this, uri, width, height);
|
|
155
|
+
if (iconBitmapDescriptor != null) {
|
|
156
|
+
int drawableId = ImageUtils.getDrawableResourceByName(this, uri);
|
|
157
|
+
iconBitmap = BitmapFactory.decodeResource(getResources(), drawableId);
|
|
158
|
+
if (iconBitmap == null) { // VectorDrawable or similar
|
|
159
|
+
Drawable drawable = getResources().getDrawable(drawableId);
|
|
160
|
+
iconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
161
|
+
drawable.setBounds(0, 0, width, height);
|
|
162
|
+
Canvas canvas = new Canvas(iconBitmap);
|
|
163
|
+
drawable.draw(canvas);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public void setPosition(ReadableMap data) {
|
|
170
|
+
this.position = new MFLocationCoordinate(data.getDouble("latitude"), data.getDouble("longitude"));
|
|
171
|
+
if (marker != null) {
|
|
172
|
+
marker.setPosition(this.position);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public void setRotation(double rotation) {
|
|
177
|
+
this.rotation = rotation;
|
|
178
|
+
if (marker != null) {
|
|
179
|
+
marker.setRotation(this.rotation);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public void setTitle(String title) {
|
|
184
|
+
this.title = title;
|
|
185
|
+
if (marker != null) {
|
|
186
|
+
marker.setTitle(this.title);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public void setSnippet(String snippet) {
|
|
191
|
+
this.snippet = snippet;
|
|
192
|
+
if (marker != null) {
|
|
193
|
+
marker.setSnippet(this.snippet);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public void setDraggable(boolean draggable) {
|
|
198
|
+
this.draggable = draggable;
|
|
199
|
+
if (marker != null) {
|
|
200
|
+
marker.setDraggable(this.draggable);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public void setZIndex(double zIndex) {
|
|
205
|
+
this.zIndex = (float) zIndex;
|
|
206
|
+
if (marker != null) {
|
|
207
|
+
marker.setZIndex(this.zIndex);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
public void setVisible(boolean visible) {
|
|
212
|
+
this.visible = visible;
|
|
213
|
+
if (marker != null) {
|
|
214
|
+
marker.setVisible(this.visible);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
public void setAnchor(ReadableMap data) {
|
|
219
|
+
this.anchorU = data != null && data.hasKey("x") ? data.getDouble("x") : 0.5;
|
|
220
|
+
this.anchorV = data != null && data.hasKey("y") ? data.getDouble("y") : 0.5;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public void setInfoWindowAnchor(ReadableMap data) {
|
|
224
|
+
double x = data != null && data.hasKey("x") ? data.getDouble("x") : 0.5;
|
|
225
|
+
double y = data != null && data.hasKey("y") ? data.getDouble("y") : 0.0;
|
|
226
|
+
this.windowAnchorU = (float) x;
|
|
227
|
+
this.windowAnchorV = (float) y;
|
|
228
|
+
if (marker != null) {
|
|
229
|
+
marker.setWindowAnchor(this.windowAnchorU, this.windowAnchorV);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public void setElevation(double elevation) {
|
|
234
|
+
this.elevation = elevation;
|
|
235
|
+
if (marker != null) {
|
|
236
|
+
marker.setElevation(elevation);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public void setUserData(ReadableMap userData) {
|
|
241
|
+
this.userData = userData.toString();
|
|
242
|
+
if (marker != null) {
|
|
243
|
+
marker.setUserData(this.userData);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public void setMarkerCollection(MFMarkerManager.Collection markerCollection) {
|
|
248
|
+
this.markerCollection = markerCollection;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public void addToMap(Map4D map) {
|
|
252
|
+
/** Because use Utils library, we should use marker collection to add Marker to Map **/
|
|
253
|
+
this.marker = markerCollection.addMarker(getMarkerOptions());
|
|
254
|
+
updateTracksViewChanges();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
public void removeFromMap(Map4D map) {
|
|
258
|
+
if (marker == null) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
/** Because use Utils library, we should use marker collection to remove Marker from Map **/
|
|
262
|
+
markerCollection.remove(marker);
|
|
263
|
+
marker = null;
|
|
264
|
+
updateTracksViewChanges();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
public MFMarkerOptions getMarkerOptions() {
|
|
268
|
+
if (markerOptions == null) {
|
|
269
|
+
markerOptions = new MFMarkerOptions();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
fillMarkerOptions(markerOptions);
|
|
273
|
+
return markerOptions;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private MFMarkerOptions fillMarkerOptions(MFMarkerOptions options) {
|
|
277
|
+
options.position(position);
|
|
278
|
+
options.anchor((float) anchorU, (float) anchorV);
|
|
279
|
+
options.infoWindowAnchor(windowAnchorU, windowAnchorV);
|
|
280
|
+
options.title(title);
|
|
281
|
+
options.snippet(snippet);
|
|
282
|
+
options.rotation(rotation);
|
|
283
|
+
options.draggable(draggable);
|
|
284
|
+
options.elevation(elevation);
|
|
285
|
+
options.zIndex(zIndex);
|
|
286
|
+
options.icon(getIcon());
|
|
287
|
+
options.userData(userData);
|
|
288
|
+
return options;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private MFBitmapDescriptor getIcon() {
|
|
292
|
+
if (hasCustomMarkerView) {
|
|
293
|
+
// creating a bitmap from an arbitrary view
|
|
294
|
+
if (iconBitmapDescriptor != null) {
|
|
295
|
+
Bitmap viewBitmap = createDrawable();
|
|
296
|
+
int width = Math.max(iconBitmap.getWidth(), viewBitmap.getWidth());
|
|
297
|
+
int height = Math.max(iconBitmap.getHeight(), viewBitmap.getHeight());
|
|
298
|
+
Bitmap combinedBitmap = Bitmap.createBitmap(width, height, iconBitmap.getConfig());
|
|
299
|
+
Canvas canvas = new Canvas(combinedBitmap);
|
|
300
|
+
canvas.drawBitmap(iconBitmap, 0, 0, null);
|
|
301
|
+
canvas.drawBitmap(viewBitmap, 0, 0, null);
|
|
302
|
+
return MFBitmapDescriptorFactory.fromBitmap(combinedBitmap);
|
|
303
|
+
} else {
|
|
304
|
+
return MFBitmapDescriptorFactory.fromBitmap(createDrawable());
|
|
305
|
+
}
|
|
306
|
+
} else if (iconBitmapDescriptor != null) {
|
|
307
|
+
// use local image as a marker
|
|
308
|
+
return iconBitmapDescriptor;
|
|
309
|
+
} else {
|
|
310
|
+
// render the default marker
|
|
311
|
+
return MFBitmapDescriptorFactory.defaultMarker();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
public void update(int width, int height) {
|
|
316
|
+
this.width = width;
|
|
317
|
+
this.height = height;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private Bitmap createDrawable() {
|
|
321
|
+
int width = this.width <= 0 ? 100 : this.width;
|
|
322
|
+
int height = this.height <= 0 ? 100 : this.height;
|
|
323
|
+
this.buildDrawingCache();
|
|
324
|
+
|
|
325
|
+
// Do not create the doublebuffer-bitmap each time. reuse it to save memory.
|
|
326
|
+
Bitmap bitmap = mLastBitmapCreated;
|
|
327
|
+
|
|
328
|
+
if (bitmap == null ||
|
|
329
|
+
bitmap.isRecycled() ||
|
|
330
|
+
bitmap.getWidth() != width ||
|
|
331
|
+
bitmap.getHeight() != height) {
|
|
332
|
+
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
333
|
+
mLastBitmapCreated = bitmap;
|
|
334
|
+
} else {
|
|
335
|
+
bitmap.eraseColor(Color.TRANSPARENT);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
Canvas canvas = new Canvas(bitmap);
|
|
339
|
+
this.draw(canvas);
|
|
340
|
+
|
|
341
|
+
return bitmap;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
@Override
|
|
345
|
+
public void addView(View child, int index) {
|
|
346
|
+
super.addView(child, index);
|
|
347
|
+
// if children are added, it means we are rendering a custom marker
|
|
348
|
+
hasCustomMarkerView = true;
|
|
349
|
+
updateTracksViewChanges();
|
|
350
|
+
updateMarkerIcon();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private void updateTracksViewChanges() {
|
|
354
|
+
boolean shouldTrack = hasCustomMarkerView && marker != null;
|
|
355
|
+
if (shouldTrack == tracksViewChangesActive) return;
|
|
356
|
+
tracksViewChangesActive = shouldTrack;
|
|
357
|
+
|
|
358
|
+
if (shouldTrack) {
|
|
359
|
+
ViewChangesTracker.getInstance().addMarker(this);
|
|
360
|
+
} else {
|
|
361
|
+
ViewChangesTracker.getInstance().removeMarker(this);
|
|
362
|
+
|
|
363
|
+
// Let it render one more time to avoid race conditions.
|
|
364
|
+
// i.e. Image onLoad ->
|
|
365
|
+
// ViewChangesTracker may not get a chance to render ->
|
|
366
|
+
// setState({ tracksViewChanges: false }) ->
|
|
367
|
+
// image loaded but not rendered.
|
|
368
|
+
updateMarkerIcon();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
public void updateMarkerIcon() {
|
|
373
|
+
if (marker != null) {
|
|
374
|
+
marker.setIcon(getIcon());
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
public boolean updateCustomForTracking() {
|
|
379
|
+
if (!tracksViewChangesActive)
|
|
380
|
+
return false;
|
|
381
|
+
updateMarkerIcon();
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private void clearDrawableCache() {
|
|
386
|
+
mLastBitmapCreated = null;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
@Override
|
|
390
|
+
public void requestLayout() {
|
|
391
|
+
super.requestLayout();
|
|
392
|
+
if (getChildCount() == 0) {
|
|
393
|
+
if (hasCustomMarkerView) {
|
|
394
|
+
hasCustomMarkerView = false;
|
|
395
|
+
clearDrawableCache();
|
|
396
|
+
updateTracksViewChanges();
|
|
397
|
+
updateMarkerIcon();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
@Override
|
|
403
|
+
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
404
|
+
super.onLayout(changed, l, t, r, b);
|
|
405
|
+
this.height = b - t;
|
|
406
|
+
this.width = r - l;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public Object getFeature() {
|
|
410
|
+
return marker;
|
|
411
|
+
}
|
|
412
|
+
}
|