Maps.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React, { useEffect, useRef } from 'react';
  2. import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
  3. //import Maps1 from './Maps1'
  4. import Maps2 from './Maps2'
  5. import Maps3 from './Maps3'
  6. import { MyMarker } from './Cluster';
  7. const MapOnly= ({region, stopList, onMapReady, onMarkerPress}) => {
  8. const mapRef = useRef();
  9. useEffect(() => {
  10. console.log('mapRef.current', mapRef.current);
  11. //mapRef.current.animateToRegion(region, 500);
  12. mapRef.current.animateCamera({ center: region, zoom: 17 }, { duration: 500 }); //移动地图到当前位置并放大
  13. }, [region])
  14. return (
  15. <MapView
  16. ref={mapRef}
  17. style={ui.flex1}
  18. initialRegion={region}
  19. onMapReady={onMapReady}
  20. provider={PROVIDER_GOOGLE}
  21. showsUserLocation={true}>
  22. { stopList.map((marker, index) => {
  23. return (
  24. <MyMarker
  25. key={index}
  26. coordinate={marker}
  27. onPress={() => onMarkerPress(marker.id)}
  28. />
  29. );
  30. })}
  31. </MapView>
  32. )
  33. }
  34. export default {
  35. Maps1: Maps2,
  36. Maps2: Maps2,
  37. Maps3: Maps3,
  38. MapOnly: MapOnly
  39. }