npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-leaflet-map

v0.4.2

Published

A React Native component that provides Leaflet MapView using the WebView

Downloads

305

Readme

react-native-leaflet-map

A React Native component that provides Leaflet MapView using the WebView

Installation

npm install react-native-leaflet-map

Usage

import LeafletMapView from 'react-native-leaflet-map';

// ...

<View style={{ flex: 1 }}>
  <LeafletMapView
    mapLayers={[
      {
        baseLayer: true,
        url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        minNativeZoom: 11,
        maxNativeZoom: 18,
        minZoom: 11,
        maxZoom: 20,
      },
    ]}
    mapMarkers={[
      {
        id: 'location-marker',
        icon: 'https://cdn-icons-png.flaticon.com/64/2776/2776067.png',
        size: [64, 64],
        iconAnchor: [32, 64],
        position: {
          lat: 1.305587412732045,
          lng: 103.83318545292657,
        },
      },
    ]}
    onMessage={onLeafletMessageReceivedHandler}
    mapCenterPosition={{ lat: 1.358479, lng: 103.815201 }}
  />
</View>;

Props

| property | required | type | purpose | | ----------------- | -------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | mapLayers | optional | MapLayer array | An array of map layers *** Current only suppport 1 layer | | mapMarkers | optional | MapMarker array | An array of map markers | | mapCenterPosition | optional | {lat: [Lat], lng: [Lng]} object | The center position of the map. This coordinate will not be accurate if the map has been moved manually. However, calling the map's setMapCenterPosition function will cause the map to revert to this location | | onMessageReceived | required | function | This function receives messages in the form of a WebviewLeafletMessage object from the map | | zoom | optional | number | Desired zoom int value of the map. Typically (1 to 22) |

Map Layer

mapLayer Prop Type

type MapLayer = {
  url?: string;
  baseLayer?: boolean;
  baseLayerIsChecked?: boolean;
  baseLayerName?: string;
  bounds?: LatLngBoundsLiteral;
  id?: string;
  opacity?: number;
  pane?: string;
  subLayer?: string;
  zIndex?: number;
}

Example with OpenStreetMap

{
  "baseLayer": true,
  "url": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
  "minNativeZoom": 11,
  "maxNativeZoom": 18,
  "minZoom": 11,
  "maxZoom": 20
}
Screenshot

Example with Singapore's OneMap

{
  "baseLayer": true,
  "url": "https://www.onemap.gov.sg/maps/tiles/Default/{z}/{x}/{y}.png",
  "minNativeZoom": 11,
  "maxNativeZoom": 18,
  "minZoom": 11,
  "maxZoom": 20
}
Screenshot

Map Markers & Marker Cluster

For regular Map Markers without clustering, simply use the mapMarkers prop

mapClustermarkers Prop Type

type MapClusterMarkers = {
  mapMarkers: Array<MapMarker>;
  maxClusterRadius?: number;
  clusterIcon: string;
  clusterIconAnchor?: PointTuple;
  clusterIconSize?: PointTuple;
  clusterCountStyle?: {
    backgroundColor?: string; // Default: #880123
    color?: string; // text color Default: #FFF
    topPos?: number; // Absolute top position Default: -5
    rightPos?: number; // Absolute right position Default: -5
    width?: number; // Default: 20
    height?: number; // Default: 20
    borderRadius?: number; // Default: 9999
  };
};

MapMarker Type

type MapMarker = {
  icon: string;
  iconAnchor?: PointTuple;
  id: string;
  position: LatLngLiteral;
  size?: PointTuple;
  zIndexOffset?: number;
  popup?: {
    id: string;
    content: string;
    offset?: PointExpression;
    className?: string;
    defaultOpen?: boolean;
  };
};

Example Usage

mapClusterMarkers={{
  mapMarkers: hawkersJSON.SrchResults.map((data) => {
    const [lat, lng] = data.LatLng.split(',').map((d) => Number(d));
    return {
      id: data.LatLng,
      icon: 'https://cdn-icons-png.flaticon.com/128/5193/5193665.png',
      size: [40, 40],
      iconAnchor: [20, 40],
      position: {
        lat: lat,
        lng: lng,
      },
    } as MapMarker;
  }),
  maxClusterRadius: 100,
  clusterIcon:
    'https://cdn-icons-png.flaticon.com/128/5193/5193665.png',
  clusterIconSize: [40, 40],
  clusterIconAnchor: [40 / 2, 40],
  clusterCountStyle: {
    borderRadius: 3,
    backgroundColor: '#001f55',
  },
}}

Demo Video

Markers Clustering Demo

Acknowledgement & References

This project incorporates tailored integrations of functionalities sourced from various open-source repositories. The author extends sincere appreciation to the following repositories for their invaluable contributions. This project owes its success to their foundational support:

Leaflet js

react-leaflet

Leaflet.markercluster

react-native-webview-leaflet

expo-leaflet

react-native-leaflet

react-leaflet-cluster

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library