react-native-map-clustering 的性能问题

问题描述 投票:0回答:1

我从 Overpass API (OpenStreetMap) 加载一些标记并在 ClusterMap 中显示它们。虽然现在Markers已经集群化,但App的性能较差,交互延迟较高。是否可以获得更好的交互性?

世博会:https://expo.dev/@ezcodeezlife/markercluster-test

代码:


import { ActivityIndicator, FlatList, Text, View, StyleSheet  } from 'react-native';
import { Marker } from 'react-native-maps'; 
import { ClusterMap, AnimatedRegion  } from 'react-native-cluster-map'; 

//This function was provided here: https://github.com/react-native-maps/react-native-maps/issues/356#issuecomment-515694070
export const getBoundByRegion = (region, scale = 1) => {
}

export default App = () => {
  const [isLoading, setLoading] = useState(true);
  const [data, setData] = useState([]);
  const [region, setRegion] = useState({
    latitude: 50.22364,
    longitude: 8.4491,
    latitudeDelta: 0.0922,
    longitudeDelta: 0.0421,
  });
  

  const getBenches = async () => {
     try {
      const response = await fetch('https://overpass.openstreetmap.fr/api/interpreter?data=[out:json];(node[%27amenity%27=%27bench%27](50.22364307664712,8.449115594560567,50.24036141038248,8.46567765838438);node[%27leisure%27=%27picnic_table%27](50.22364307664712,8.449115594560567,50.24036141038248,8.46567765838438););out%20body;');
      const json = await response.json();
      setData(json);
    } catch (error) {
      console.error(error);
    } finally {
      setLoading(false);
    }
  }

  const getNewBenches = async (bounds) => {
    try {
     const response = await fetch("https://overpass.openstreetmap.fr/api/interpreter?data=[out:json];node[%27amenity%27=%27bench%27](" + bounds.minLat +"," + bounds.minLng + "," + bounds.maxLat + "," + bounds.maxLng + ");out%20body;");
     const json = await response.json();
     setData(json);
   } catch (error) {
     console.error(error);
   } finally {
   }
 }
  useEffect(() => {
    getBenches();
  }, []);

  if(isLoading == false) {
    return (
      <>
        <View>
          <ClusterMap 
            style={styles.container}
            region={ region }
            mapType={"satellite"}
            onRegionChangeComplete={(region) => {
              setRegion(region);
              getNewBenches(getBoundByRegion(region));
            } }
            //onMapReady={() => onMapReady()}
          >
            {data.elements.map((marker) => (
              <Marker
               tracksViewChanges={false}
               key={marker.id}
               coordinate={{ latitude: marker.lat, longitude:  marker.lon }}
              />
            ))}
        </ClusterMap >
        </View>
      </>
    )
  } else {
    return (
      <View>
        <ActivityIndicator />
      </View>
    )
  }
};

//styles

是否可以获得更好的交互性?

react-native react-native-maps react-native-map-clustering
1个回答
1
投票

我遇到了类似的问题,这是因为我在代码中留下了许多控制台日志。删除它们后,我的地图交互性好多了。尝试删除尽可能多的不必要的控制台日志。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.