react-native-webview-leaflet
A React Native component that uses a React Native WebView to provide a Leaflet map.
Last updated 8 months ago by reggie3 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-native-webview-leaflet 
SYNC missed versions from official npm registry.

# React Native Webview Leaflet

A Leaflet map component with no native code for React Native applications

⚠️ This is version 4 of this library. It includes breaking changes from previous versions.

Difference Between Versions

Like version 2, version 3 builds on react-leaflet. The primary new feature is the ability to specify map tiles. See below for more details.

Why Use This Library

This component is useful if you want to display HTML elements on an interactive map. Since the elements are just HTML items, you can use SVG's, emojis, text, images, etc., and they can even be animated, updated, and changed as required.

Why Not Use This Library

You may not want to use this library if you'd rather use Google map tiles and data vice the tiles and map data from Open Street Maps.

npm npm npm npm

Image

Installation

Install using npm or yarn like this:

npm install --save react-native-webview-leaflet

or

yarn add react-native-webview-leaflet

Usage

and import like so

import WebViewLeaflet from "react-native-webview-leaflet";

A typical example is shown below:

<WebViewLeaflet
  ref={component => (this.webViewLeaflet = component)}
  // Optional: a callback that will be called when the map is loaded
  onLoad={this.onLoad}

  // Optional: the component that will receive map events}
  eventReceiver={this} 

  // Optional: the center of the displayed map
  centerPosition={this.state.mapCenterPosition}

  // Optional: a list of markers that will be displayed on the map
  markers={this.state.markers}

  // Required: the map layers that will be displayed on the map. See below for a description of the map layers object
  mapLayers={mapLayers}

  // Optional: display a marker to be at a given location
  ownPositionMarker={{
    coords: this.state.currentLocation,
    icon: "❤️",
    size: [24, 24],
    animation: {
      name: "pulse",
      duration: ".5",
      delay: 0,
      interationCount: "infinite"
    }
  }}

  // Optional (defaults to false): display a button that centers the map on the coordinates of ownPostionMarker. Requires that "ownPositionMarker" prop be set
  centerButton={true}

  // Optional (defaults to false): cluster icons that are in the same area
  useMarkerClustering={true}
/>

After loading, the map expects to receive an array of map layer information objects. A sample object showing a MapBox tile layer is shown below.

  {
    name: 'streets',  // the name of the layer, this will be seen in the layer selection control
    checked: 'true',  // if the layer is selected in the layer selection control
    type: 'TileLayer',  // the type of layer as shown at https://react-leaflet.js.org/docs/en/components.html#raster-layers
    baseLayer: true,
    // url of tiles
    url: `https://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=${mapboxToken}`,
    // attribution string to be shown for this layer
    attribution:
      '&amp;copy <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors'
  }

The format of the object depends on the type of layer to be displayed, and corresponds to the Raster Layers in react-leaflet
https://react-leaflet.js.org/docs/en/components.html#raster-layers

NOTE: Image and VideoOverlay layers do not currently work.

Example objects are shown in the mockMapLayers.js file in this repository.

Communicating with the map

Listening for Events

This library supports map clicked, map marker clicked, and the map events that are exposed by Leaflet.

Map Clicked and Map Marker Clicked Events

To receive map clicked and on map marker clicked events, add the following functions to the component identified by the eventReceiver prop.

onMapClicked = ({ payload }) => {
  console.log(`Map Clicked: app received: ${payload.coords}`);
  this.showAlert("Map Clicked", `Coordinates = ${payload.coords}`);
};

onMapMarkerClicked = ({ payload }) => {
  console.log(`Marker Clicked: ${payload.id}`);
  this.showAlert("Marker Clicked", `Marker ID = ${payload.id}`);
};
Leaflet Map Events

To react to leaflet map events, you need to create functions in your component to handle them. These functions' names must be camelCased and prefixed by 'on'. For example, to listen for Leaflet's zoomlevelschange event, you will need to create a function called onZoomLevelsChange. These functions will receive the following object

{
  center, // center of the map
    bounds, // the bounds of the map
    zoom; // the zoom level of the map
}

Sending Events to the Map

The map can be be updated by sending messages from your component to the WebViewLeaflet component via its reference like so:

this.webViewLeaflet.sendMessage({
  zoom: 6,
  locations: this.state.locations, // an array of locations
  showAttributionControl: this.state.mapState.showAttributionControl, // a boolean controlling whether the map displays its attribution control
  showZoomControl: this.state.mapState.showZoomControl // a boolean controlling whether the map displays its zoom control
});

A react-leaflet component makes up the map that is rendered by WebViewLeaflet. This allows messages like the one above to be used to directly set values in the map's state.

Creating Map Markers

The map builds and displays its markers based on the value of the locations key in its own state. You can update the value of it's locations by sending a message containing an object that contains a key of locations and a value that is an array of location objects like the one shown below. An example of such a call and a location object is show below.

// sending locations to the map
this.webViewLeaflet.sendMessage({
  locations: [...this.state.locations]
});
// a location object
{
  id: uuidV1(), // The ID attached to the marker. It will be returned when onMarkerClicked is called
  coords: [LATITUDE, LONGITUDE], // Latitude and Longitude of the marker
  icon: '????', // HTML element that will be displayed as the marker.  It can also be text or an SVG string.

  // The child object, "animation", controls the optional animation that will be attached to the marker.
  // See below for a list of available animations
  animation: {
    name: animations[Math.floor(Math.random() * animations.length)],
    duration: Math.floor(Math.random() _ 3) + 1,
    delay: Math.floor(Math.random()) _ 0.5,
    interationCount
  }
  // optional size for this individual icon
  // will default to the WebViewLeaflet `defaultIconSize` property if not provided
  size: [64, 64],
}

Available Animations

Animations for "bounce", "fade", "pulse", "jump", "waggle", "spin", and "beat" can be specified in the animation.name property of an individual location.

Animation Information

Animations are kept in the file markers.css They are just keyframe animations like this:

@keyframes spin {
  50% {
    transform: rotateZ(-20deg);
    animation-timing-function: ease;
  }
  100% {
    transform: rotateZ(360deg);
  }
}
## Changelog

### 4.3.1

* Fixed issue with using expo-asset-utils that prevented this package from working with iOS apps in simulator

### 4.2.0

* Replace Expo dependency with expo-asset-utils
* Fixed bug that caused map to not display when no ownPositionMarker was provided

### 4.1.15

* Keep own position marker from being clustered

### 4.1.0

* Added optional marker clustering using react-leaflet-markercluster
* Update preview video in readme

### 4.0.0

* Fixed map centering, and map centering button (see issue #36(https://github.com/reggie3/react-native-webview-leaflet/issues/36) )
#### BREAKING CHANGES:
* Center map on own current location button defaults to not being shown
* Center map on own current location button requires that a "ownPositionMarker" object be passed to the WebViewLeaflet component
* WebViewLeaflet component requires a "centerPosition" prop for initial centering
* Map tile Layers are now passed as props to the WebViewLeaflet component


### 3.1.45

* Works in production APK files.
* Renders http images as map icons.

### 3.0.0

* Introduced user specified tile layers.

### 2.0.0

* Initial release of version 2 built on React-Leaflet

## LICENSE

MIT

Current Tags

  • 4.2.12                                ...           beta (8 months ago)
  • 4.3.4                                ...           latest (8 months ago)

228 Versions

  • 4.3.4                                ...           8 months ago
  • 4.2.14                                ...           8 months ago
  • 4.2.13                                ...           8 months ago
  • 4.2.12                                ...           8 months ago
  • 4.3.2                                ...           8 months ago
  • 4.3.1                                ...           8 months ago
  • 4.2.9                                ...           8 months ago
  • 4.2.8                                ...           8 months ago
  • 4.2.4                                ...           8 months ago
  • 4.2.3                                ...           8 months ago
  • 4.2.2                                ...           8 months ago
  • 4.2.1                                ...           8 months ago
  • 4.1.24                                ...           8 months ago
  • 4.1.23                                ...           8 months ago
  • 4.1.22                                ...           a year ago
  • 4.1.21                                ...           a year ago
  • 4.1.20                                ...           a year ago
  • 4.1.19                                ...           a year ago
  • 4.1.18                                ...           a year ago
  • 4.1.17                                ...           a year ago
  • 4.1.16                                ...           a year ago
  • 4.1.15                                ...           a year ago
  • 4.1.14                                ...           a year ago
  • 4.1.13                                ...           a year ago
  • 4.1.12                                ...           a year ago
  • 4.0.60                                ...           a year ago
  • 4.0.59                                ...           a year ago
  • 4.0.58                                ...           a year ago
  • 4.0.57                                ...           a year ago
  • 4.0.56                                ...           a year ago
  • 4.0.55                                ...           a year ago
  • 4.0.54                                ...           a year ago
  • 4.0.53                                ...           a year ago
  • 4.0.52                                ...           a year ago
  • 4.0.51                                ...           a year ago
  • 4.0.5                                ...           a year ago
  • 4.0.4                                ...           a year ago
  • 4.0.33                                ...           a year ago
  • 4.0.32                                ...           a year ago
  • 4.0.21                                ...           a year ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 3.2.14                                ...           a year ago
  • 3.2.13                                ...           a year ago
  • 3.2.12                                ...           a year ago
  • 3.2.11                                ...           a year ago
  • 3.1.50                                ...           a year ago
  • 3.1.49                                ...           a year ago
  • 3.1.48                                ...           a year ago
  • 3.1.47                                ...           a year ago
  • 3.1.46                                ...           a year ago
  • 3.1.45                                ...           a year ago
  • 3.1.44                                ...           a year ago
  • 3.1.43                                ...           a year ago
  • 3.1.42                                ...           a year ago
  • 3.1.41                                ...           a year ago
  • 3.1.40                                ...           a year ago
  • 3.1.39                                ...           a year ago
  • 3.1.38                                ...           a year ago
  • 3.1.37                                ...           a year ago
  • 3.1.36                                ...           a year ago
  • 3.1.35                                ...           a year ago
  • 3.1.34                                ...           a year ago
  • 3.1.33                                ...           a year ago
  • 3.1.32                                ...           a year ago
  • 3.1.31                                ...           a year ago
  • 3.1.30                                ...           a year ago
  • 3.1.29                                ...           a year ago
  • 3.1.28                                ...           a year ago
  • 3.1.27                                ...           a year ago
  • 3.1.26                                ...           a year ago
  • 3.1.25                                ...           a year ago
  • 3.1.24                                ...           a year ago
  • 3.1.23                                ...           a year ago
  • 3.1.22                                ...           a year ago
  • 3.1.21                                ...           a year ago
  • 3.1.20                                ...           a year ago
  • 3.1.13                                ...           a year ago
  • 3.1.12                                ...           a year ago
  • 3.1.1                                ...           a year ago
  • 3.0.18                                ...           a year ago
  • 3.0.17                                ...           a year ago
  • 3.0.16                                ...           a year ago
  • 3.0.15                                ...           a year ago
  • 3.0.14                                ...           a year ago
  • 3.0.13                                ...           a year ago
  • 3.0.12                                ...           a year ago
  • 3.0.11                                ...           a year ago
  • 3.0.10                                ...           a year ago
  • 3.0.9                                ...           a year ago
  • 3.0.8                                ...           a year ago
  • 3.0.7                                ...           a year ago
  • 3.0.6                                ...           a year ago
  • 3.0.5                                ...           a year ago
  • 3.0.4                                ...           a year ago
  • 3.0.3                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 2.0.501                                ...           a year ago
  • 2.0.500                                ...           a year ago
  • 2.0.499                                ...           a year ago
  • 2.0.498                                ...           a year ago
  • 2.0.497                                ...           a year ago
  • 2.0.496                                ...           a year ago
  • 2.0.495                                ...           a year ago
  • 2.0.494                                ...           a year ago
  • 2.0.493                                ...           a year ago
  • 2.0.492                                ...           a year ago
  • 2.0.49                                ...           a year ago
  • 2.0.48                                ...           a year ago
  • 2.0.47                                ...           a year ago
  • 2.0.46                                ...           a year ago
  • 2.0.442                                ...           a year ago
  • 2.0.441                                ...           a year ago
  • 2.0.44                                ...           a year ago
  • 2.0.43                                ...           a year ago
  • 2.0.42                                ...           a year ago
  • 2.0.4                                ...           a year ago
  • 2.0.3                                ...           a year ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 0.4.16                                ...           2 years ago
  • 0.4.15                                ...           2 years ago
  • 0.4.14                                ...           2 years ago
  • 0.4.13                                ...           2 years ago
  • 0.4.12                                ...           2 years ago
  • 0.4.11                                ...           2 years ago
  • 0.3.43                                ...           2 years ago
  • 0.3.42                                ...           2 years ago
  • 0.3.41                                ...           2 years ago
  • 0.3.40                                ...           2 years ago
  • 0.3.39                                ...           2 years ago
  • 0.3.38                                ...           2 years ago
  • 0.3.37                                ...           2 years ago
  • 0.3.36                                ...           2 years ago
  • 0.3.35                                ...           2 years ago
  • 0.3.34                                ...           2 years ago
  • 0.3.33                                ...           2 years ago
  • 0.3.32                                ...           2 years ago
  • 0.3.31                                ...           2 years ago
  • 0.3.3                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.2.86                                ...           2 years ago
  • 0.2.85                                ...           2 years ago
  • 0.2.84                                ...           2 years ago
  • 0.2.83                                ...           2 years ago
  • 0.2.82                                ...           2 years ago
  • 0.2.81                                ...           2 years ago
  • 0.2.80                                ...           2 years ago
  • 0.2.79                                ...           2 years ago
  • 0.2.78                                ...           2 years ago
  • 0.2.77                                ...           2 years ago
  • 0.2.75                                ...           2 years ago
  • 0.2.74                                ...           2 years ago
  • 0.2.73                                ...           2 years ago
  • 0.2.72                                ...           2 years ago
  • 0.2.71                                ...           2 years ago
  • 0.2.7                                ...           2 years ago
  • 0.2.5                                ...           2 years ago
  • 0.2.4                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.1.913                                ...           2 years ago
  • 0.1.912                                ...           2 years ago
  • 0.1.911                                ...           2 years ago
  • 0.1.910                                ...           2 years ago
  • 0.1.908                                ...           2 years ago
  • 0.1.907                                ...           2 years ago
  • 0.1.906                                ...           2 years ago
  • 0.1.905                                ...           2 years ago
  • 0.1.904                                ...           2 years ago
  • 0.1.903                                ...           2 years ago
  • 0.1.902                                ...           2 years ago
  • 0.1.901                                ...           2 years ago
  • 0.1.842                                ...           2 years ago
  • 0.1.841                                ...           2 years ago
  • 0.1.840                                ...           2 years ago
  • 0.1.839                                ...           2 years ago
  • 0.1.838                                ...           2 years ago
  • 0.1.837                                ...           2 years ago
  • 0.1.836                                ...           2 years ago
  • 0.1.835                                ...           2 years ago
  • 0.1.834                                ...           2 years ago
  • 0.1.833                                ...           2 years ago
  • 0.1.832                                ...           2 years ago
  • 0.1.831                                ...           2 years ago
  • 0.1.830                                ...           2 years ago
  • 0.1.829                                ...           2 years ago
  • 0.1.828                                ...           2 years ago
  • 0.1.827                                ...           2 years ago
  • 0.1.826                                ...           2 years ago
  • 0.1.825                                ...           2 years ago
  • 0.1.824                                ...           2 years ago
  • 0.1.823                                ...           2 years ago
  • 0.1.822                                ...           2 years ago
  • 0.1.821                                ...           2 years ago
  • 0.1.820                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.0.101                                ...           2 years ago
  • 0.0.100                                ...           2 years ago
  • 0.0.99                                ...           2 years ago
  • 0.0.98                                ...           2 years ago
  • 0.0.97                                ...           2 years ago
  • 0.0.94                                ...           2 years ago
  • 0.0.86                                ...           2 years ago
  • 0.0.85                                ...           2 years ago
  • 0.0.84                                ...           2 years ago
  • 0.0.83                                ...           2 years ago
  • 0.0.82                                ...           2 years ago
  • 0.0.81                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.71                                ...           2 years ago
  • 0.0.64                                ...           2 years ago
  • 0.0.63                                ...           2 years ago
  • 0.0.62                                ...           2 years ago
  • 0.0.61                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.53                                ...           2 years ago
  • 0.0.52                                ...           2 years ago
  • 0.0.51                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 2
Last Day 0
Last Week 1
Last Month 1
Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |