Giter VIP home page Giter VIP logo

react-leaflet-marker's Introduction

react-leaflet-marker

Custom markers for react-leaflet maps.

You can use any react component with version of react-leaflet 3.x.x || 4.x.x

npm types GitHub Actions CI License

Support zoom animation

animation

Demo

Install

React 18 react-leaflet 4

npm i react-leaflet-marker --save

React 17 react-leaflet 3

npm i [email protected] --save

Get started

import React from "react";
import { MapContainer } from "react-leaflet";
import { MarkerLayer, Marker } from "react-leaflet-marker";

const ReactMarker = () => (
    <MapContainer
        {/* ...MapContainerProps react-leaflet */}
        center={[55.796391, 49.108891]}
        zoom={10}
    >
        <MarkerLayer>
            <Marker
                position={[55.796391, 49.108891]}
            >
                <div>Hi, i'm a react element</div>
            </Marker>
        </MarkerLayer>
    </MapContainer>
);

export default ReactMarker;

Examples

Simple marker with flexible size

Markers without size can't take placement props.

simple

<MarkerLayer>
    <Marker
        position={[55.796391, 49.108891]}
    >
        <div style={{
            background: 'red'
        }}>
            simple{'\u00A0'}marker
        </div>
    </Marker>
</MarkerLayer>

Marker with fixed size

Just add size props. It is the best practice the most cases.

placement

<MarkerLayer>
    <Marker
        position={[55.796391, 49.108891]}
        size={[80, 20]} // required for placement
        // you can use optional `placement`
        placement="center" // "top", "bottom"
    >
        <div style={{
            background: 'red',
            textAlign: 'center'
        }}>
            center
        </div>
    </Marker>
</MarkerLayer>

Rise on hover

The marker will get on top of others when you hover the mouse over it.

rise on hover

<MarkerLayer>
    <Marker
        position={[55.796391, 49.108891]}
        size={[80, 40]}
        interactive // required for riseOnHover
        riseOnHover
    >
        <div style={{
            background: 'red',
            textAlign: 'center'
        }}>
            First marker
        </div>
    </Marker>
</MarkerLayer>

Use any react component as marker

For example, I used antd dropdown and custom icons

cover

Props

Name Default Type Description
position - LatLngExpression Lat Lng coordinates
innerRef? - MutableRefObject
riseOnHover? false bool If true, the marker will get on top of others when you hover the mouse over it.If true, the marker will get on top of others when you hover the mouse over it.
riseOffset? 250 number The z-index offset used for the riseOnHover feature.
zIndexOffset? 0 number By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to put the marker on top of all others (or below), specifying a high value like 1000 (or high negative value, respectively).
interactive? false bool If set false, the marker won't respond to mouse
size? - [width: number, height: number] Size marker. Required for placement
placement? center string One of top, center, bottom

react-leaflet-marker's People

Contributors

vkruglikov avatar xxblackbulletxx avatar felipedeboni avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.