@maplibre/maplibre-react-native 11.0.0-alpha.42 → 11.0.0-alpha.43
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/android/build.gradle +1 -3
- package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +3 -3
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/callout/MLRNCallout.kt +7 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/callout/MLRNCalloutManager.kt +29 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerView.kt +220 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerViewContent.kt +50 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerViewManager.kt +81 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MarkerViewManager.kt +127 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/pointannotation/MLRNPointAnnotation.kt +407 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/pointannotation/MLRNPointAnnotationManager.kt +105 -0
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +38 -37
- package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationClickEvent.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationDragEvent.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/PointAnnotationEvent.kt +30 -0
- package/ios/components/annotations/callout/MLRNCalloutComponentView.h +10 -0
- package/ios/components/annotations/callout/MLRNCalloutComponentView.mm +91 -0
- package/ios/components/annotations/point-annotation/MLRNPointAnnotation.h +44 -0
- package/ios/components/annotations/{MLRNPointAnnotation.m → point-annotation/MLRNPointAnnotation.m} +69 -35
- package/ios/components/annotations/point-annotation/MLRNPointAnnotationComponentView.h +10 -0
- package/ios/components/annotations/point-annotation/MLRNPointAnnotationComponentView.mm +331 -0
- package/ios/components/map-view/MLRNMapView.m +4 -5
- package/lib/commonjs/components/annotations/callout/Callout.js +94 -0
- package/lib/commonjs/components/annotations/callout/Callout.js.map +1 -0
- package/lib/commonjs/components/annotations/callout/CalloutNativeComponent.ts +11 -0
- package/lib/commonjs/components/annotations/marker-view/MarkerView.js +70 -0
- package/lib/commonjs/components/annotations/marker-view/MarkerView.js.map +1 -0
- package/lib/commonjs/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
- package/lib/commonjs/components/annotations/point-annotation/PointAnnotation.js +88 -0
- package/lib/commonjs/components/annotations/point-annotation/PointAnnotation.js.map +1 -0
- package/lib/commonjs/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
- package/lib/commonjs/index.js +3 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/Anchor.js +68 -0
- package/lib/commonjs/types/Anchor.js.map +1 -0
- package/lib/commonjs/utils/animated/Animated.js +4 -0
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/module/components/annotations/callout/Callout.js +88 -0
- package/lib/module/components/annotations/callout/Callout.js.map +1 -0
- package/lib/module/components/annotations/callout/CalloutNativeComponent.ts +11 -0
- package/lib/module/components/annotations/marker-view/MarkerView.js +64 -0
- package/lib/module/components/annotations/marker-view/MarkerView.js.map +1 -0
- package/lib/module/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
- package/lib/module/components/annotations/point-annotation/PointAnnotation.js +83 -0
- package/lib/module/components/annotations/point-annotation/PointAnnotation.js.map +1 -0
- package/lib/module/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/Anchor.js +64 -0
- package/lib/module/types/Anchor.js.map +1 -0
- package/lib/module/utils/animated/Animated.js +4 -0
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/typescript/{module/src/components/annotations → commonjs/src/components/annotations/callout}/Callout.d.ts +9 -9
- package/lib/typescript/commonjs/src/components/annotations/callout/Callout.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/callout/CalloutNativeComponent.d.ts +6 -0
- package/lib/typescript/commonjs/src/components/annotations/callout/CalloutNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerView.d.ts +52 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts +21 -0
- package/lib/typescript/commonjs/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotation.d.ts +95 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotation.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts +43 -0
- package/lib/typescript/commonjs/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -4
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/Anchor.d.ts +17 -0
- package/lib/typescript/commonjs/src/types/Anchor.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +1 -0
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/{commonjs/src/components/annotations → module/src/components/annotations/callout}/Callout.d.ts +9 -9
- package/lib/typescript/module/src/components/annotations/callout/Callout.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/callout/CalloutNativeComponent.d.ts +6 -0
- package/lib/typescript/module/src/components/annotations/callout/CalloutNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerView.d.ts +52 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts +21 -0
- package/lib/typescript/module/src/components/annotations/marker-view/MarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotation.d.ts +95 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotation.d.ts.map +1 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts +43 -0
- package/lib/typescript/module/src/components/annotations/point-annotation/PointAnnotationNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -4
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/types/Anchor.d.ts +17 -0
- package/lib/typescript/module/src/types/Anchor.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/animated/Animated.d.ts +1 -0
- package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/components/annotations/callout/Callout.tsx +145 -0
- package/src/components/annotations/callout/CalloutNativeComponent.ts +11 -0
- package/src/components/annotations/marker-view/MarkerView.tsx +124 -0
- package/src/components/annotations/marker-view/MarkerViewNativeComponent.ts +30 -0
- package/src/components/annotations/point-annotation/PointAnnotation.tsx +219 -0
- package/src/components/annotations/point-annotation/PointAnnotationNativeComponent.ts +58 -0
- package/src/index.ts +15 -4
- package/src/types/Anchor.ts +44 -0
- package/src/utils/animated/Animated.tsx +6 -0
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNCallout.java +0 -11
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNCalloutManager.java +0 -18
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNMarkerView.java +0 -112
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNMarkerViewManager.java +0 -45
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNPointAnnotation.java +0 -361
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MLRNPointAnnotationManager.java +0 -84
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerView.java +0 -23
- package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerViewManager.java +0 -69
- package/ios/components/annotations/MLRNCalloutManager.h +0 -5
- package/ios/components/annotations/MLRNCalloutManager.m +0 -12
- package/ios/components/annotations/MLRNPointAnnotation.h +0 -33
- package/ios/components/annotations/MLRNPointAnnotationManager.h +0 -5
- package/ios/components/annotations/MLRNPointAnnotationManager.m +0 -27
- package/lib/commonjs/components/annotations/Callout.js +0 -101
- package/lib/commonjs/components/annotations/Callout.js.map +0 -1
- package/lib/commonjs/components/annotations/MarkerView.js +0 -60
- package/lib/commonjs/components/annotations/MarkerView.js.map +0 -1
- package/lib/commonjs/components/annotations/PointAnnotation.js +0 -114
- package/lib/commonjs/components/annotations/PointAnnotation.js.map +0 -1
- package/lib/module/components/annotations/Callout.js +0 -96
- package/lib/module/components/annotations/Callout.js.map +0 -1
- package/lib/module/components/annotations/MarkerView.js +0 -55
- package/lib/module/components/annotations/MarkerView.js.map +0 -1
- package/lib/module/components/annotations/PointAnnotation.js +0 -110
- package/lib/module/components/annotations/PointAnnotation.js.map +0 -1
- package/lib/typescript/commonjs/src/components/annotations/Callout.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/annotations/MarkerView.d.ts +0 -44
- package/lib/typescript/commonjs/src/components/annotations/MarkerView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/annotations/PointAnnotation.d.ts +0 -90
- package/lib/typescript/commonjs/src/components/annotations/PointAnnotation.d.ts.map +0 -1
- package/lib/typescript/module/src/components/annotations/Callout.d.ts.map +0 -1
- package/lib/typescript/module/src/components/annotations/MarkerView.d.ts +0 -44
- package/lib/typescript/module/src/components/annotations/MarkerView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/annotations/PointAnnotation.d.ts +0 -90
- package/lib/typescript/module/src/components/annotations/PointAnnotation.d.ts.map +0 -1
- package/src/components/annotations/Callout.tsx +0 -139
- package/src/components/annotations/MarkerView.tsx +0 -86
- package/src/components/annotations/PointAnnotation.tsx +0 -240
- /package/ios/components/annotations/{MLRNCallout.h → callout/MLRNCallout.h} +0 -0
- /package/ios/components/annotations/{MLRNCallout.m → callout/MLRNCallout.m} +0 -0
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.annotations;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.PointF;
|
|
5
|
-
import android.graphics.Bitmap;
|
|
6
|
-
import android.view.View;
|
|
7
|
-
import androidx.annotation.NonNull;
|
|
8
|
-
|
|
9
|
-
import org.maplibre.geojson.Point;
|
|
10
|
-
import org.maplibre.android.geometry.LatLng;
|
|
11
|
-
import org.maplibre.android.maps.Style;
|
|
12
|
-
import org.maplibre.android.plugins.annotation.Symbol;
|
|
13
|
-
import org.maplibre.android.plugins.annotation.SymbolManager;
|
|
14
|
-
import org.maplibre.android.plugins.annotation.SymbolOptions;
|
|
15
|
-
import org.maplibre.android.maps.MapLibreMap;
|
|
16
|
-
|
|
17
|
-
import org.maplibre.reactnative.components.AbstractMapFeature;
|
|
18
|
-
import org.maplibre.reactnative.components.mapview.MLRNMapView;
|
|
19
|
-
import org.maplibre.reactnative.events.PointAnnotationClickEvent;
|
|
20
|
-
import org.maplibre.reactnative.events.PointAnnotationDragEvent;
|
|
21
|
-
import org.maplibre.reactnative.events.constants.EventTypes;
|
|
22
|
-
import org.maplibre.reactnative.utils.GeoJSONUtils;
|
|
23
|
-
import org.maplibre.reactnative.utils.BitmapUtils;
|
|
24
|
-
|
|
25
|
-
public class MLRNPointAnnotation extends AbstractMapFeature implements View.OnLayoutChangeListener {
|
|
26
|
-
private Context mContext;
|
|
27
|
-
private MLRNPointAnnotationManager mManager;
|
|
28
|
-
private Symbol mAnnotation;
|
|
29
|
-
private MapLibreMap mMap;
|
|
30
|
-
private MLRNMapView mMapView;
|
|
31
|
-
|
|
32
|
-
private boolean mHasChildren;
|
|
33
|
-
|
|
34
|
-
private Point mCoordinate;
|
|
35
|
-
|
|
36
|
-
private String mID;
|
|
37
|
-
private String mTitle;
|
|
38
|
-
private String mSnippet;
|
|
39
|
-
|
|
40
|
-
private Float[] mAnchor;
|
|
41
|
-
private boolean mIsSelected;
|
|
42
|
-
private boolean mDraggable;
|
|
43
|
-
|
|
44
|
-
private View mChildView;
|
|
45
|
-
private Bitmap mChildBitmap;
|
|
46
|
-
private String mChildBitmapId;
|
|
47
|
-
|
|
48
|
-
private View mCalloutView;
|
|
49
|
-
private Symbol mCalloutSymbol;
|
|
50
|
-
private Bitmap mCalloutBitmap;
|
|
51
|
-
private String mCalloutBitmapId;
|
|
52
|
-
|
|
53
|
-
private static final String MARKER_IMAGE_ID = "MARKER_IMAGE_ID";
|
|
54
|
-
|
|
55
|
-
public MLRNPointAnnotation(Context context, MLRNPointAnnotationManager manager) {
|
|
56
|
-
super(context);
|
|
57
|
-
mContext = context;
|
|
58
|
-
mManager = manager;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Override
|
|
62
|
-
public void addView(View childView, int childPosition) {
|
|
63
|
-
if (childView instanceof MLRNCallout) {
|
|
64
|
-
mCalloutView = childView;
|
|
65
|
-
} else {
|
|
66
|
-
mChildView = childView;
|
|
67
|
-
}
|
|
68
|
-
childView.addOnLayoutChangeListener(this);
|
|
69
|
-
if (mMapView != null) {
|
|
70
|
-
mMapView.offscreenAnnotationViewContainer().addView(childView);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
@Override
|
|
75
|
-
public void removeView(View childView) {
|
|
76
|
-
if (mChildView != null) {
|
|
77
|
-
mMap.getStyle(new Style.OnStyleLoaded() {
|
|
78
|
-
@Override
|
|
79
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
80
|
-
style.removeImage(mChildBitmapId);
|
|
81
|
-
mChildView = null;
|
|
82
|
-
mCalloutView = null;
|
|
83
|
-
mChildBitmap = null;
|
|
84
|
-
mChildBitmapId = null;
|
|
85
|
-
updateOptions();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (mMapView != null) {
|
|
90
|
-
mMapView.offscreenAnnotationViewContainer().removeView(childView);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@Override
|
|
95
|
-
public void addToMap(MLRNMapView mapView) {
|
|
96
|
-
mMapView = mapView;
|
|
97
|
-
mMap = mapView.getMapLibreMap();
|
|
98
|
-
makeMarker();
|
|
99
|
-
|
|
100
|
-
if (mChildView != null) {
|
|
101
|
-
if (!mChildView.isAttachedToWindow()) {
|
|
102
|
-
mMapView.offscreenAnnotationViewContainer().addView(mChildView);
|
|
103
|
-
}
|
|
104
|
-
addBitmapToStyle(mChildBitmap, mChildBitmapId);
|
|
105
|
-
updateOptions();
|
|
106
|
-
}
|
|
107
|
-
if (mCalloutView != null) {
|
|
108
|
-
if (!mCalloutView.isAttachedToWindow()) {
|
|
109
|
-
mMapView.offscreenAnnotationViewContainer().addView(mCalloutView);
|
|
110
|
-
}
|
|
111
|
-
addBitmapToStyle(mCalloutBitmap, mCalloutBitmapId);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@Override
|
|
116
|
-
public void removeFromMap(MLRNMapView mapView) {
|
|
117
|
-
MLRNMapView map = (mMapView != null) ? mMapView : mapView;
|
|
118
|
-
if (map == null) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (mAnnotation != null) {
|
|
123
|
-
map.getSymbolManager().delete(mAnnotation);
|
|
124
|
-
}
|
|
125
|
-
if (mChildView != null) {
|
|
126
|
-
map.offscreenAnnotationViewContainer().removeView(mChildView);
|
|
127
|
-
}
|
|
128
|
-
if (mCalloutView != null) {
|
|
129
|
-
map.offscreenAnnotationViewContainer().removeView(mCalloutView);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
@Override
|
|
134
|
-
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
|
|
135
|
-
int oldRight, int oldBottom) {
|
|
136
|
-
if (left == 0 && top == 0 && right == 0 && bottom == 0) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom) {
|
|
140
|
-
refreshBitmap(v, left, top, right, bottom);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private void refreshBitmap(View v, int left, int top, int right, int bottom) {
|
|
145
|
-
Bitmap bitmap = BitmapUtils.viewToBitmap(v, left, top, right, bottom);
|
|
146
|
-
String bitmapId = Integer.toString(v.getId());
|
|
147
|
-
addBitmapToStyle(bitmap, bitmapId);
|
|
148
|
-
if (v instanceof MLRNCallout) {
|
|
149
|
-
mCalloutBitmap = bitmap;
|
|
150
|
-
mCalloutBitmapId = bitmapId;
|
|
151
|
-
} else {
|
|
152
|
-
if (bitmap != null) {
|
|
153
|
-
mChildBitmap = bitmap;
|
|
154
|
-
mChildBitmapId = bitmapId;
|
|
155
|
-
updateOptions();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private void refreshBitmap(View v) {
|
|
161
|
-
refreshBitmap(v, v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
public LatLng getLatLng() {
|
|
165
|
-
return GeoJSONUtils.toLatLng(mCoordinate);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
public long getMapboxID() {
|
|
169
|
-
return mAnnotation == null ? -1 : mAnnotation.getId();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
public String getID() {
|
|
173
|
-
return mID;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public void setID(String id) {
|
|
177
|
-
mID = id;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public View getCalloutView() {
|
|
181
|
-
return mCalloutView;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
public void setCoordinate(Point point) {
|
|
185
|
-
mCoordinate = point;
|
|
186
|
-
|
|
187
|
-
if (mAnnotation != null) {
|
|
188
|
-
mAnnotation.setLatLng(GeoJSONUtils.toLatLng(point));
|
|
189
|
-
mMapView.getSymbolManager().update(mAnnotation);
|
|
190
|
-
}
|
|
191
|
-
if (mCalloutSymbol != null) {
|
|
192
|
-
mCalloutSymbol.setLatLng(GeoJSONUtils.toLatLng(point));
|
|
193
|
-
mMapView.getSymbolManager().update(mCalloutSymbol);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
public void setAnchor(float x, float y) {
|
|
198
|
-
mAnchor = new Float[]{x, y};
|
|
199
|
-
|
|
200
|
-
if (mAnnotation != null) {
|
|
201
|
-
updateAnchor();
|
|
202
|
-
mMapView.getSymbolManager().update(mAnnotation);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
public void setDraggable(Boolean draggable) {
|
|
207
|
-
mDraggable = draggable;
|
|
208
|
-
if (mAnnotation != null) {
|
|
209
|
-
mAnnotation.setDraggable(draggable);
|
|
210
|
-
mMapView.getSymbolManager().update(mAnnotation);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
public Symbol getMarker() {
|
|
215
|
-
return mAnnotation;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
public void onSelect(boolean shouldSendEvent) {
|
|
219
|
-
if (mCalloutView != null) {
|
|
220
|
-
makeCallout();
|
|
221
|
-
}
|
|
222
|
-
if (shouldSendEvent) {
|
|
223
|
-
mManager.handleEvent(makeEvent(true));
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
public void onDeselect() {
|
|
228
|
-
mManager.handleEvent(makeEvent(false));
|
|
229
|
-
if (mCalloutSymbol != null) {
|
|
230
|
-
mMapView.getSymbolManager().delete(mCalloutSymbol);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public void onDragStart() {
|
|
235
|
-
LatLng latLng = mAnnotation.getLatLng();
|
|
236
|
-
mCoordinate = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
|
|
237
|
-
mManager.handleEvent(makeDragEvent(EventTypes.ANNOTATION_DRAG_START));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
public void onDrag() {
|
|
241
|
-
LatLng latLng = mAnnotation.getLatLng();
|
|
242
|
-
mCoordinate = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
|
|
243
|
-
mManager.handleEvent(makeDragEvent(EventTypes.ANNOTATION_DRAG));
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
public void onDragEnd() {
|
|
247
|
-
LatLng latLng = mAnnotation.getLatLng();
|
|
248
|
-
mCoordinate = Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude());
|
|
249
|
-
mManager.handleEvent(makeDragEvent(EventTypes.ANNOTATION_DRAG_END));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
public void makeMarker() {
|
|
253
|
-
SymbolOptions options = new SymbolOptions()
|
|
254
|
-
.withLatLng(GeoJSONUtils.toLatLng(mCoordinate))
|
|
255
|
-
.withDraggable(mDraggable)
|
|
256
|
-
.withIconSize(1.0f)
|
|
257
|
-
.withSymbolSortKey(10.0f);
|
|
258
|
-
SymbolManager symbolManager = mMapView.getSymbolManager();
|
|
259
|
-
if (symbolManager != null) {
|
|
260
|
-
mAnnotation = symbolManager.create(options);
|
|
261
|
-
updateOptions();
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private void updateOptions() {
|
|
266
|
-
if (mAnnotation != null) {
|
|
267
|
-
updateIconImage();
|
|
268
|
-
updateAnchor();
|
|
269
|
-
mMapView.getSymbolManager().update(mAnnotation);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
private void updateIconImage() {
|
|
274
|
-
if (mChildView != null) {
|
|
275
|
-
if (mChildBitmapId != null) {
|
|
276
|
-
mAnnotation.setIconImage(mChildBitmapId);
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
mAnnotation.setIconImage(MARKER_IMAGE_ID);
|
|
280
|
-
mAnnotation.setIconAnchor("bottom");
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
private void updateAnchor() {
|
|
285
|
-
if (mAnchor != null && mChildView != null && mChildBitmap != null) {
|
|
286
|
-
int w = mChildBitmap.getWidth();
|
|
287
|
-
int h = mChildBitmap.getHeight();
|
|
288
|
-
final float scale = getResources().getDisplayMetrics().density;
|
|
289
|
-
w = (int) (w / scale);
|
|
290
|
-
h = (int) (h / scale);
|
|
291
|
-
mAnnotation.setIconAnchor("top-left");
|
|
292
|
-
mAnnotation.setIconOffset(new PointF(w * mAnchor[0] * -1, h * mAnchor[1] * -1));
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
private void makeCallout() {
|
|
297
|
-
float yOffset = -28f;
|
|
298
|
-
if (mChildView != null) {
|
|
299
|
-
if (mChildBitmap != null) {
|
|
300
|
-
float scale = getResources().getDisplayMetrics().density;
|
|
301
|
-
int h = (int) mChildBitmap.getHeight() / 2;
|
|
302
|
-
h = (int) (h / scale);
|
|
303
|
-
yOffset = (float) h * -1;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
SymbolOptions options = new SymbolOptions()
|
|
307
|
-
.withLatLng(GeoJSONUtils.toLatLng(mCoordinate))
|
|
308
|
-
.withIconImage(mCalloutBitmapId)
|
|
309
|
-
.withIconSize(1.0f)
|
|
310
|
-
.withIconAnchor("bottom")
|
|
311
|
-
.withIconOffset(new Float[] {0f, yOffset})
|
|
312
|
-
.withSymbolSortKey(11.0f)
|
|
313
|
-
.withDraggable(false);
|
|
314
|
-
SymbolManager symbolManager = mMapView.getSymbolManager();
|
|
315
|
-
if (symbolManager != null) {
|
|
316
|
-
mCalloutSymbol = symbolManager.create(options);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
private void addBitmapToStyle(final Bitmap bitmap, final String bitmapId) {
|
|
321
|
-
if (mMap != null && bitmapId != null && bitmap != null) {
|
|
322
|
-
mMap.getStyle(new Style.OnStyleLoaded() {
|
|
323
|
-
@Override
|
|
324
|
-
public void onStyleLoaded(@NonNull Style style) {
|
|
325
|
-
style.addImage(bitmapId, bitmap);
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
private PointAnnotationClickEvent makeEvent(boolean isSelect) {
|
|
332
|
-
String type = isSelect ? EventTypes.ANNOTATION_SELECTED : EventTypes.ANNOTATION_DESELECTED;
|
|
333
|
-
LatLng latLng = GeoJSONUtils.toLatLng(mCoordinate);
|
|
334
|
-
PointF screenPos = getScreenPosition(latLng);
|
|
335
|
-
return new PointAnnotationClickEvent(this, latLng, screenPos, type);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
private PointAnnotationDragEvent makeDragEvent(String type) {
|
|
339
|
-
LatLng latLng = GeoJSONUtils.toLatLng(mCoordinate);
|
|
340
|
-
PointF screenPos = getScreenPosition(latLng);
|
|
341
|
-
return new PointAnnotationDragEvent(this, latLng, screenPos, type);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
private float getDisplayDensity() {
|
|
345
|
-
return mContext.getResources().getDisplayMetrics().density;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
private PointF getScreenPosition(LatLng latLng) {
|
|
349
|
-
PointF screenPos = mMap.getProjection().toScreenLocation(latLng);
|
|
350
|
-
float density = getDisplayDensity();
|
|
351
|
-
screenPos.x /= density;
|
|
352
|
-
screenPos.y /= density;
|
|
353
|
-
return screenPos;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
public void refresh() {
|
|
357
|
-
if (mChildView != null) {
|
|
358
|
-
refreshBitmap(mChildView);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.annotations;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.Nullable;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
7
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
8
|
-
import com.facebook.react.common.MapBuilder;
|
|
9
|
-
import com.facebook.react.uimanager.ThemedReactContext;
|
|
10
|
-
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
11
|
-
import org.maplibre.reactnative.components.AbstractEventEmitter;
|
|
12
|
-
import org.maplibre.reactnative.events.constants.EventKeys;
|
|
13
|
-
import org.maplibre.reactnative.utils.GeoJSONUtils;
|
|
14
|
-
|
|
15
|
-
import java.util.Map;
|
|
16
|
-
|
|
17
|
-
public class MLRNPointAnnotationManager extends AbstractEventEmitter<MLRNPointAnnotation> {
|
|
18
|
-
public static final String REACT_CLASS = "MLRNPointAnnotation";
|
|
19
|
-
|
|
20
|
-
public MLRNPointAnnotationManager(ReactApplicationContext reactApplicationContext) {
|
|
21
|
-
super(reactApplicationContext);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Override
|
|
25
|
-
public Map<String, String> customEvents() {
|
|
26
|
-
return MapBuilder.<String, String>builder()
|
|
27
|
-
.put(EventKeys.POINT_ANNOTATION_SELECTED, "onMapboxPointAnnotationSelected")
|
|
28
|
-
.put(EventKeys.POINT_ANNOTATION_DESELECTED, "onMapboxPointAnnotationDeselected")
|
|
29
|
-
.put(EventKeys.POINT_ANNOTATION_DRAG_START, "onMapboxPointAnnotationDragStart")
|
|
30
|
-
.put(EventKeys.POINT_ANNOTATION_DRAG, "onMapboxPointAnnotationDrag")
|
|
31
|
-
.put(EventKeys.POINT_ANNOTATION_DRAG_END, "onMapboxPointAnnotationDragEnd")
|
|
32
|
-
.build();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//region React Methods
|
|
36
|
-
public static final int METHOD_REFRESH = 2;
|
|
37
|
-
|
|
38
|
-
@Nullable
|
|
39
|
-
@Override
|
|
40
|
-
public Map<String, Integer> getCommandsMap() {
|
|
41
|
-
return MapBuilder.<String, Integer>builder()
|
|
42
|
-
.put("refresh", METHOD_REFRESH)
|
|
43
|
-
.build();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@Override
|
|
47
|
-
public String getName() {
|
|
48
|
-
return REACT_CLASS;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@Override
|
|
52
|
-
protected MLRNPointAnnotation createViewInstance(ThemedReactContext reactContext) {
|
|
53
|
-
return new MLRNPointAnnotation(reactContext, this);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@ReactProp(name="id")
|
|
57
|
-
public void setId(MLRNPointAnnotation annotation, String id) {
|
|
58
|
-
annotation.setID(id);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@ReactProp(name="coordinate")
|
|
62
|
-
public void setCoordinate(MLRNPointAnnotation annotation, String geoJSONStr) {
|
|
63
|
-
annotation.setCoordinate(GeoJSONUtils.toPointGeometry(geoJSONStr));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@ReactProp(name="anchor")
|
|
67
|
-
public void setAnchor(MLRNPointAnnotation annotation, ReadableMap map) {
|
|
68
|
-
annotation.setAnchor((float) map.getDouble("x"), (float) map.getDouble("y"));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@ReactProp(name="draggable")
|
|
72
|
-
public void setDraggable(MLRNPointAnnotation annotation, Boolean draggable) {
|
|
73
|
-
annotation.setDraggable(draggable);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@Override
|
|
77
|
-
public void receiveCommand(MLRNPointAnnotation annotation, int commandID, @Nullable ReadableArray args) {
|
|
78
|
-
switch (commandID) {
|
|
79
|
-
case METHOD_REFRESH:
|
|
80
|
-
annotation.refresh();
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerView.java
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.annotations;
|
|
2
|
-
|
|
3
|
-
import android.view.View;
|
|
4
|
-
|
|
5
|
-
import androidx.annotation.NonNull;
|
|
6
|
-
|
|
7
|
-
import org.maplibre.android.geometry.LatLng;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Subclass of MarkerView so we MarkerViewManager can implement remove/restoreViews
|
|
11
|
-
*/
|
|
12
|
-
public class MarkerView extends org.maplibre.android.plugins.markerview.MarkerView {
|
|
13
|
-
View view;
|
|
14
|
-
|
|
15
|
-
public MarkerView(@NonNull LatLng latLng, @NonNull View view) {
|
|
16
|
-
super(latLng, view);
|
|
17
|
-
this.view = view;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public View getView() {
|
|
21
|
-
return this.view;
|
|
22
|
-
}
|
|
23
|
-
}
|
package/android/src/main/java/org/maplibre/reactnative/components/annotations/MarkerViewManager.java
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
package org.maplibre.reactnative.components.annotations;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import org.maplibre.android.maps.MapView;
|
|
6
|
-
import org.maplibre.android.maps.MapLibreMap;
|
|
7
|
-
|
|
8
|
-
import java.util.ArrayList;
|
|
9
|
-
import java.util.List;
|
|
10
|
-
|
|
11
|
-
import java.lang.reflect.InvocationTargetException;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Subclass of MarkerViewManager implementing removeViews and restoreViews
|
|
15
|
-
*/
|
|
16
|
-
public class MarkerViewManager extends org.maplibre.android.plugins.markerview.MarkerViewManager {
|
|
17
|
-
private final List<MarkerView> markers = new ArrayList<>();
|
|
18
|
-
private MapView mapView;
|
|
19
|
-
private java.lang.reflect.Method markerUpdate;
|
|
20
|
-
|
|
21
|
-
public MarkerViewManager(MapView mapView, MapLibreMap map) {
|
|
22
|
-
super(mapView, map);
|
|
23
|
-
this.mapView = mapView;
|
|
24
|
-
// this.map = map;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
markerUpdate = MarkerView.class.getSuperclass().getDeclaredMethod("update");
|
|
28
|
-
markerUpdate.setAccessible(true);
|
|
29
|
-
}
|
|
30
|
-
catch (NoSuchMethodException e) {System.out.println(e.toString());}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public void addMarker(@NonNull MarkerView markerView) {
|
|
34
|
-
super.addMarker(markerView);
|
|
35
|
-
markers.add(markerView);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public void removeMarker(@NonNull MarkerView markerView) {
|
|
39
|
-
super.removeMarker(markerView);
|
|
40
|
-
markers.remove(markerView);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public void removeViews() {
|
|
44
|
-
for (MarkerView marker: markers) {
|
|
45
|
-
mapView.removeView(marker.getView());
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public void restoreViews() {
|
|
50
|
-
for (MarkerView marker: markers) {
|
|
51
|
-
mapView.addView(marker.getView());
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public void updateMarkers(){
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
if (markerUpdate != null) {
|
|
59
|
-
for( int i = 0; i < markers.size(); i++ ){
|
|
60
|
-
markerUpdate.invoke(markers.get(i));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (IllegalArgumentException e) { System.out.println(e.toString()); }
|
|
65
|
-
catch (IllegalAccessException e) { System.out.println(e.toString()); }
|
|
66
|
-
catch (InvocationTargetException e) { System.out.println(e.toString()); }
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#import <React/RCTComponent.h>
|
|
2
|
-
#import <React/RCTView.h>
|
|
3
|
-
#import <UIKit/UIKit.h>
|
|
4
|
-
#import "MLRNCallout.h"
|
|
5
|
-
|
|
6
|
-
#import <MapLibre/MapLibre.h>
|
|
7
|
-
|
|
8
|
-
@interface MLRNPointAnnotation : MLNAnnotationView <MLNAnnotation>
|
|
9
|
-
|
|
10
|
-
@property (nonatomic, weak) MLNMapView *map;
|
|
11
|
-
@property (nonatomic, strong) MLRNCallout *calloutView;
|
|
12
|
-
|
|
13
|
-
@property (nonatomic, copy) NSString *id;
|
|
14
|
-
@property (nonatomic, copy) NSString *reactTitle;
|
|
15
|
-
@property (nonatomic, copy) NSString *reactSnippet;
|
|
16
|
-
|
|
17
|
-
@property (nonatomic, copy) NSString *reactCoordinate;
|
|
18
|
-
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
|
|
19
|
-
|
|
20
|
-
@property (nonatomic, copy) NSDictionary<NSString *, NSNumber *> *anchor;
|
|
21
|
-
|
|
22
|
-
@property (nonatomic, copy) RCTBubblingEventBlock onSelected;
|
|
23
|
-
@property (nonatomic, copy) RCTBubblingEventBlock onDeselected;
|
|
24
|
-
@property (nonatomic, copy) RCTBubblingEventBlock onDragStart;
|
|
25
|
-
@property (nonatomic, copy) RCTBubblingEventBlock onDrag;
|
|
26
|
-
@property (nonatomic, copy) RCTBubblingEventBlock onDragEnd;
|
|
27
|
-
|
|
28
|
-
@property (nonatomic, assign) BOOL reactSelected;
|
|
29
|
-
@property (nonatomic, assign) BOOL reactDraggable;
|
|
30
|
-
|
|
31
|
-
- (MLNAnnotationView *)getAnnotationView;
|
|
32
|
-
|
|
33
|
-
@end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#import "MLRNPointAnnotationManager.h"
|
|
2
|
-
#import "MLRNPointAnnotation.h"
|
|
3
|
-
|
|
4
|
-
@implementation MLRNPointAnnotationManager
|
|
5
|
-
|
|
6
|
-
RCT_EXPORT_MODULE()
|
|
7
|
-
|
|
8
|
-
RCT_EXPORT_VIEW_PROPERTY(id, NSString)
|
|
9
|
-
RCT_EXPORT_VIEW_PROPERTY(anchor, NSDictionary)
|
|
10
|
-
|
|
11
|
-
RCT_REMAP_VIEW_PROPERTY(selected, reactSelected, BOOL)
|
|
12
|
-
RCT_REMAP_VIEW_PROPERTY(title, reactTitle, NSString)
|
|
13
|
-
RCT_REMAP_VIEW_PROPERTY(snippet, reactSnippet, NSString)
|
|
14
|
-
RCT_REMAP_VIEW_PROPERTY(coordinate, reactCoordinate, NSString)
|
|
15
|
-
RCT_REMAP_VIEW_PROPERTY(draggable, reactDraggable, BOOL)
|
|
16
|
-
|
|
17
|
-
RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationSelected, onSelected, RCTBubblingEventBlock)
|
|
18
|
-
RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDeselected, onDeselected, RCTBubblingEventBlock)
|
|
19
|
-
RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDragStart, onDragStart, RCTBubblingEventBlock)
|
|
20
|
-
RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDrag, onDrag, RCTBubblingEventBlock)
|
|
21
|
-
RCT_REMAP_VIEW_PROPERTY(onMapboxPointAnnotationDragEnd, onDragEnd, RCTBubblingEventBlock)
|
|
22
|
-
|
|
23
|
-
- (UIView *)view {
|
|
24
|
-
return [[MLRNPointAnnotation alloc] init];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@end
|