putteabrahamsson / react-native-leaflet-ts

React Native Leaflet with Typescript support
MIT License
19 stars 2 forks source link

is there a way to delete all markers on the screen? #14

Closed loloide closed 6 months ago

putteabrahamsson commented 6 months ago

Implemented.

import Leaflet, { RNLeafletRef } from 'react-native-leaflet-ts';

const App = () => {
  const leafletRef = useRef<RNLeafletRef>(null);

  return (
    <SafeAreaView style={{ backgroundColor: 'gray', flex: 1 }}>
      <Leaflet
        ref={leafletRef}
        mapLayers={[
          {
            name: 'mapoverview',
            src,
            tileOptions: {
              attribution: 'hello! this is the attribution',
            },
          },
        ]}
        onMessage={d => console.log(d)}
        markers={[
          {
            latLng: [0, 0, -20],
            disabled: false,
            title: 'test',
            icon: 'https://as2.ftcdn.net/v2/jpg/03/29/26/39/1000_F_329263903_Oax03LQARwf34pbJn4rdcmQ2dgJMzo1D.jpg',
          },
        ]}
      />

      <Button
        onPress={() =>
          leafletRef.current?.flyTo({ latLng: [0, 0, -20], zoom: 5 })
        }
        title="flyto"></Button>

      <Button
        onPress={() => leafletRef.current?.clearMarkers()}
        title="clear markers"></Button>
    </SafeAreaView>
  );
}

`