2.1.0 • Published 1 year ago

react-leaflet-marker v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 react-leaflet-marker@1.1.4 --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

NameDefaultTypeDescription
position-LatLngExpressionLat Lng coordinates
innerRef?-MutableRefObject
riseOnHover?falseboolIf 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?250numberThe z-index offset used for the riseOnHover feature.
zIndexOffset?0numberBy 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?falseboolIf set false, the marker won't respond to mouse
size?-width: number, height: numberSize marker. Required for placement
placement?centerstringOne of top, center, bottom
2.1.0

1 year ago

2.0.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3-alpha.9

2 years ago

1.0.3-alpha.8

2 years ago

1.0.3-alpha.7

2 years ago

1.0.3-alpha.6

2 years ago

1.0.3-alpha.5

2 years ago

1.0.3-alpha.4

2 years ago

1.0.3-alpha.1

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago