Skip to content

Commit a2d8cd2

Browse files
committed
fix: receiveCommand
1 parent 3ae833d commit a2d8cd2

File tree

3 files changed

+111
-89
lines changed

3 files changed

+111
-89
lines changed

android/src/main/java/com/osmdroid/OsmMapManager.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void setMaxZoomLevel(OsmMapView view, float maxZoomLevel) {
208208
}
209209

210210
@Override
211-
public void receiveCommand(OsmMapView view, int commandId, @Nullable ReadableArray args) {
211+
public void receiveCommand(OsmMapView view, String commandId, @Nullable ReadableArray args) {
212212
Integer duration;
213213
Double lat;
214214
Double lng;
@@ -219,18 +219,18 @@ public void receiveCommand(OsmMapView view, int commandId, @Nullable ReadableArr
219219
ReadableMap camera;
220220

221221
switch (commandId) {
222-
case SET_CAMERA:
222+
case "setCamera":
223223
camera = args.getMap(0);
224224
view.animateToCamera(camera, 0);
225225
break;
226226

227-
case ANIMATE_CAMERA:
227+
case "animateCamera":
228228
camera = args.getMap(0);
229229
duration = args.getInt(1);
230230
view.animateToCamera(camera, duration);
231231
break;
232232

233-
case ANIMATE_TO_REGION:
233+
case "animateToRegion":
234234
region = args.getMap(0);
235235
duration = args.getInt(1);
236236
lng = region.getDouble("longitude");
@@ -244,32 +244,30 @@ public void receiveCommand(OsmMapView view, int commandId, @Nullable ReadableArr
244244
view.animateToRegion(bounds, duration);
245245
break;
246246

247-
case ANIMATE_TO_COORDINATE:
247+
case "animateToCoordinate":
248248
region = args.getMap(0);
249249
duration = args.getInt(1);
250250
lng = region.getDouble("longitude");
251251
lat = region.getDouble("latitude");
252252
view.animateToCoordinate(new GeoPoint(lat, lng), duration);
253253
break;
254254

255-
case ANIMATE_TO_VIEWING_ANGLE:
256-
// not supported!
257-
break;
258255

259-
case ANIMATE_TO_BEARING:
256+
257+
case "animateToBearing":
260258
bearing = (float) args.getDouble(0);
261259
duration = args.getInt(1);
262260
view.animateToBearing(bearing, duration);
263261
break;
264262

265-
case FIT_TO_ELEMENTS:
263+
case "fitToElements":
266264
view.fitToElements(args.getBoolean(0));
267265
break;
268266

269-
case FIT_TO_SUPPLIED_MARKERS:
267+
case "fitToSuppliedMarkers":
270268
view.fitToSuppliedMarkers(args.getArray(0), args.getMap(1), args.getBoolean(2));
271269
break;
272-
case FIT_TO_COORDINATES:
270+
case "fitToCoordinates":
273271
view.fitToCoordinates(args.getArray(0), args.getMap(1), args.getBoolean(2));
274272
break;
275273
}

example/src/App.tsx

Lines changed: 99 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as React from 'react';
22

3-
import { StyleSheet, Text } from 'react-native';
3+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
44
import MapView, {
5-
Callout,
65
Circle,
76
Marker,
87
Polygon,
@@ -21,85 +20,109 @@ export default function App() {
2120
const toner =
2221
'https://api.maptiler.com/maps/toner-v2/{z}/{x}/{y}.png?key=j46yoHMlBMQRgTY3lCMk';
2322
const mapRef = React.useRef<MapView>();
24-
23+
const zelenograd: Region = {
24+
latitude: 55.9825,
25+
longitude: 40.18139,
26+
latitudeDelta: 0.5,
27+
longitudeDelta: 0.5,
28+
};
29+
const goHome = () => {
30+
mapRef.current?.animateToRegion(zelenograd);
31+
};
2532
return (
26-
<MapView.Animated
27-
ref={mapRef}
28-
onMapReady={async () => {
29-
// const mapBoundaries = await mapRef.current?.getMapBoundaries();
30-
// console.log(
31-
// '🚀 ~ file: App.tsx:30 ~ onMapReady={ ~ mapBoundaries',
32-
// mapBoundaries
33-
// );
34-
}}
35-
onRegionChangeComplete={async () => {
36-
// const mapBoundaries = await mapRef.current?.getMapBoundaries();
37-
// console.log(
38-
// '🚀 ~ file: App.tsx:30 ~ onMapReady={ ~ mapBoundaries',
39-
// mapBoundaries
40-
// );
41-
}}
42-
style={styles.container}
43-
initialRegion={initialRegion}
44-
>
45-
<Marker
46-
coordinate={{
47-
latitude: 55.75222,
48-
longitude: 37.61556,
33+
<View style={{ flex: 1, position: 'relative' }}>
34+
<MapView.Animated
35+
ref={mapRef}
36+
onMapReady={async () => {
37+
// const mapBoundaries = await mapRef.current?.getMapBoundaries();
38+
// console.log(
39+
// '🚀 ~ file: App.tsx:30 ~ onMapReady={ ~ mapBoundaries',
40+
// mapBoundaries
41+
// );
42+
}}
43+
onRegionChangeComplete={async () => {
44+
const mapBoundaries = await mapRef.current?.getMapBoundaries();
45+
console.log(
46+
'🚀 ~ file: App.tsx:30 ~ onMapReady={ ~ mapBoundaries',
47+
mapBoundaries
48+
);
4949
}}
50+
style={styles.container}
51+
initialRegion={initialRegion}
5052
>
51-
<Text>Marker</Text>
52-
<Callout>
53-
<Text>Callout</Text>
54-
</Callout>
55-
</Marker>
56-
<Polyline
57-
strokeColor="red"
58-
strokeWidth={30}
59-
coordinates={[
60-
{
61-
latitude: 55.7521,
62-
longitude: 37.60556,
63-
},
64-
{
65-
latitude: 55.75223,
66-
longitude: 37.61557,
67-
},
68-
{
69-
latitude: 55.75224,
70-
longitude: 37.61558,
71-
},
72-
]}
73-
/>
74-
<Polygon
75-
strokeColor="blue"
76-
strokeWidth={30}
77-
coordinates={[
78-
{
79-
latitude: 55.7221,
80-
longitude: 37.62556,
81-
},
82-
{
83-
latitude: 55.72223,
84-
longitude: 37.62557,
85-
},
86-
{
87-
latitude: 55.72224,
88-
longitude: 37.62558,
89-
},
90-
]}
91-
/>
92-
<Circle
93-
strokeWidth={40}
94-
strokeColor="white"
95-
center={{
96-
latitude: 55.72324,
97-
longitude: 37.62358,
53+
<Marker
54+
coordinate={{
55+
latitude: 55.75222,
56+
longitude: 36.61556,
57+
}}
58+
>
59+
<Text>
60+
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem
61+
blanditiis nobis, assumenda ipsam ex cupiditate delectus inventore
62+
labore autem optio eum illo adipisci exercitationem quas incidunt
63+
distinctio! Iure, ex quisquam!
64+
</Text>
65+
</Marker>
66+
<Polyline
67+
strokeColor="red"
68+
strokeWidth={30}
69+
coordinates={[
70+
{
71+
latitude: 55.7521,
72+
longitude: 37.60556,
73+
},
74+
{
75+
latitude: 55.75223,
76+
longitude: 37.61557,
77+
},
78+
{
79+
latitude: 55.75224,
80+
longitude: 37.61558,
81+
},
82+
]}
83+
/>
84+
<Polygon
85+
strokeColor="blue"
86+
strokeWidth={30}
87+
coordinates={[
88+
{
89+
latitude: 55.7221,
90+
longitude: 37.62556,
91+
},
92+
{
93+
latitude: 55.72223,
94+
longitude: 37.62557,
95+
},
96+
{
97+
latitude: 55.72224,
98+
longitude: 37.62558,
99+
},
100+
]}
101+
/>
102+
<Circle
103+
strokeWidth={40}
104+
strokeColor="white"
105+
center={{
106+
latitude: 55.72324,
107+
longitude: 37.62358,
108+
}}
109+
radius={40}
110+
/>
111+
<UrlTile urlTemplate={toner} />
112+
</MapView.Animated>
113+
<TouchableOpacity
114+
style={{
115+
backgroundColor: 'red',
116+
width: 400,
117+
height: 40,
118+
position: 'absolute',
119+
top: 0,
120+
left: 0,
121+
zIndex: 200,
98122
}}
99-
radius={40}
123+
onPress={goHome}
100124
/>
101-
<UrlTile urlTemplate={toner} />
102-
</MapView.Animated>
125+
</View>
103126
);
104127
}
105128

src/MapView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class MapView extends React.Component<MapViewProps, State> {
479479
animateToRegion(region: Region, duration: number = 500) {
480480
if (this.map.current) {
481481
Commands.animateToRegion(this.map.current, region, duration);
482+
console.log('animateToRegion');
482483
}
483484
}
484485

@@ -705,7 +706,7 @@ const AnimatedMapView = Animated.createAnimatedComponent(MapView);
705706
MapView.Animated = AnimatedMapView;
706707

707708
export const enableLatestRenderer = () => {
708-
return NativeModules.AirMapModule.enableLatestRenderer();
709+
return NativeModules.OsmMapModule.enableLatestRenderer();
709710
};
710711

711712
export default MapView;

0 commit comments

Comments
 (0)