New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-native-leaflet-view

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-leaflet-view

A LeafletView component using WebView and Leaflet map for React Native applications

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

react-native-leaflet

A LeafletView component using WebView and Leaflet map for React Native applications

Notes: This project is replacement for https://github.com/reggie3/react-native-webview-leaflet, which no longer maintain by author and work only with expo.

npm npm npm

Installation

Install using npm or yarn like this:

npm install --save react-native-leaflet-view

or

yarn add react-native-leaflet-view

react-native configuration

This package is required for proper file handling and WebView functionality in React Native:

  • react-native-webview. You can install it using yarn or npm:
npm install --save react-native-webview

or

yarn add react-native-webview

Expo configuration

For Expo projects, you'll need to add additional dependencies:

npx expo install react-native-webview expo-asset expo-file-system

These packages are required for proper file handling and WebView functionality in Expo:

You need to do this in the root of your project: Copy the required HTML file from the package with this one-liner

cp node_modules/react-native-leaflet-view/android/src/main/assets/leaflet.html assets

Usage with react-native-cli

import React from 'react';
import { LeafletView } from 'react-native-leaflet-view';

const DEFAULT_LOCATION = {
  latitude: -23.5489,
  longitude: -46.6388
}
const App: React.FC = () => {

  return (
    <LeafletView
      mapCenterPosition={{
        lat: DEFAULT_LOCATION.latitude,
        lng: DEFAULT_LOCATION.longitude,
      }}
    />
  );
}

export default App;

Usage with Expo


import React, { useEffect, useState } from 'react';
import { ActivityIndicator, Alert } from 'react-native';
import { Asset } from "expo-asset";
import * as FileSystem from "expo-file-system";
import { LatLng, LeafletView } from 'react-native-leaflet-view';

const DEFAULT_LOCATION = {
  latitude: -23.5489,
  longitude: -46.6388
}
const App: React.FC = () => {
  const [webViewContent, setWebViewContent] = useState<string | null>(null);
  useEffect(() => {
    let isMounted = true;

    const loadHtml = async () => {
      try {
        const path = require("./assets/leaflet.html");
        const asset = Asset.fromModule(path);
        await asset.downloadAsync();
        const htmlContent = await FileSystem.readAsStringAsync(asset.localUri!);

        if (isMounted) {
          setWebViewContent(htmlContent);
        }
      } catch (error) {
        Alert.alert('Error loading HTML', JSON.stringify(error));
        console.error('Error loading HTML:', error);
      }
    };

    loadHtml();

    return () => {
      isMounted = false;
    };
  }, []);

  if (!webViewContent) {
    return <ActivityIndicator size="large" />
  }
  return (
    <LeafletView
      source={{ html: webViewContent }}
      mapCenterPosition={{
        lat: DEFAULT_LOCATION.latitude,
        lng: DEFAULT_LOCATION.longitude,
      }}
    />
  );
}

export default App;

Props

propertyrequiredtypepurpose
loadingIndicatoroptionalReact.ReactElementcustom component displayed while the map is loading
onErroroptionalfunctionWill receive an error event
onLoadEndoptionalfunctionCalled when map stops loading
onLoadStartoptionalfunctionCalled when the map starts to load
onMessageReceivedrequiredfunctionThis function receives messages in the form of a WebviewLeafletMessage object from the map
mapLayersoptionalMapLayer arrayAn array of map layers
mapMarkersoptionalMapMarker arrayAn array of map markers
mapShapesoptionalMapShape[]An array of map shapes
mapCenterPositionoptional{lat: [Lat], lng: [Lng]} objectThe 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
ownPositionMarkeroptionalMarkerA special marker that has an ID of OWN_POSTION_MARKER_ID
zoomoptionalnumberDesired zoom value of the map
doDebugoptionalbooleanA flag for debug message logging
sourceoptionalWebView["source"]Loads static html or a uri (with optional headers) in the WebView.
zoomControloptionalbooleanControls the visibility of the zoom controls on the map.
attributionControloptionalbooleanControls the visibility of the attribution control on the map.

Contributing

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

License

MIT

Keywords

react-native

FAQs

Package last updated on 02 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts