rle

react-leaflet-enhanced-marker

This library will help render dynamic react components as markers on leaflet maps easily

Showing:

Popularity

Downloads/wk

637

GitHub Stars

31

Maintenance

Last Commit

2mos ago

Contributors

4

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Leaflet

react-leaflet-enhanced-marker

This library will help render dynamic markers on Leaflet Map. The marker can be :-

  • A simple String
  • A React Component
  • An Image

It works with any stable version of react-leaflet 1.x.x and 2.x.x.

How to use :

Using react-leaflet-enhanced-marker to render Marker using plain text

import React, { Component } from "react";
import ReactDOM from "react-dom";
import { Map, TileLayer } from "react-leaflet";
import Marker from 'react-leaflet-enhanced-marker'


class MarkerExample extends Component {
  state = {
    center: [32, -97],
    zoom: 6,
  };

  render() {
    return (
      <div>
        <Map center={this.state.center} zoom={this.state.zoom}>
          <TileLayer
            attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
          />
          <Marker 
            icon={'Test Marker Here'}
            position={this.state.center}
          />
        </Map>
      </div>
    );
  }
}

Using react-leaflet-enhanced-marker to render Marker using static React Component

class ReactComponent extends Component {
  render() {
    const markerStyle = {
      backgroundColor: "blue",
      color: "white",
      display: "flex",
      justifyContent: "center",
      width: "50px",
      height: "50px",
      borderRadius: "50px",
      alignItems: "center"
    };
    return <div style={markerStyle}>Marker</div>;
  }
}

class MapExample extends Component {
  state = {
    center: [32, -97],
    zoom: 6
  };

  render() {
    return (
      <div>
        <Map center={this.state.center} zoom={this.state.zoom}>
          <TileLayer
            attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
          />
          <Marker icon={<ReactComponent/>} position={this.state.center} />
        </Map>
      </div>
    );
  }
}

Using react-leaflet-enhanced-marker to render Image markers

import img from './imagePath'

class MapExample extends Component {
  state = {
    center: [32, -97],
    zoom: 6
  };

  render() {
    return (
      <div>
        <Map center={this.state.center} zoom={this.state.zoom}>
          <TileLayer
            attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
          />
          <Marker icon={<img src={img} style={{width:'100'}} />} position={this.state.center} />
        </Map>
      </div>
    );
  }
}

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100