7.0.10 • Published 8 months ago

leaflet-custom-div-overlay v7.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

leaflet-custom-div-overlay

A leaflet plugin that supports custom divs.

install

$ npm i leaflet-custom-div-overlay

or

$ yarn add leaflet-custom-div-overlay

or

$ pnpm add leaflet-custom-div-overlay

usage

  • bounds: LatLngExpression[]
  • options: CustomDivOverlayOptions
    • opacity: Number The default value is 1. css/opacity
    • interactive: Boolean The default value is false. If true, the div overlay will emit mouse events when clicked or hovered.
    • zIndex: Number The default value is 1. The explicit zIndex of the overlay layer.
    • className: String The default value is ''. A custom class name to assign to the div. Empty by default.
    • pane: String The default value is 'markerPane'. more
    • attribution: String The default value is null. String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

es

For example.

import L, { type LatLngExpression } from 'leaflet';
import { CustomDivOverlay, customDivOverlay } from 'leaflet-custom-div-overlay';

const bounds: LatLngExpression[] = [
  [51.75, 19.46667],
  [51.75001, 19.46668],
];
const options: CustomDivOverlayOptions = {
  zIndex: 460,
  interactive: true,
  className: 'my-custom-div-overlay',
  content: `<div>lorem</div>`,
  attribution: 'leaflet-custom-div-overlay',
};

const customDiv = customDivOverlay(bounds, options);
// or
// const customDiv = new CustomDivOverlay(bounds, options);

customDiv.addTo(map);

browser

Introduce external dependencies

<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/leaflet-src.js"></script>

Introduce this plugin.

<script src="https://unpkg.com/leaflet-custom-div-overlay@latest"></script>
<!-- or -->
<!-- <script src="https://unpkg.com/leaflet-custom-div-overlay@1.0.0/dist/leaflet-custom-div-overlay.global.js"></script> -->

You can also download this plugin locally and then import it.

<script src="/path/leaflet-custom-div-overlay/umd/index.js"></script>

Create a dom container to load the map

<div id="map" style="height: 300px;"></div>

Use it.

const map = L.map('map', {});

map.setView(new L.LatLng(51.75, 19.46667), 12);

const customDiv = L.customDivOverlay(
  [
    [51.75, 19.46667],
    [51.75001, 19.46668],
  ],
  {
    zIndex: 460,
    interactive: true,
    className: 'my-custom-div-overlay',
    content: `<div>lorem</div>`,
    attribution: 'leaflet-custom-div-overlay',
  },
);

customDiv.on('click', (event) => {
  console.log(event);
});

customDiv.addTo(map);

api

Methodargumentsreturnsdescription
bringToFront-thisBrings this overlay in front of other overlays (in the same map pane).
bringToBack-thisBrings this overlay to the back of other overlays (in the same map pane).
setBounds(<L.LatLngBounds> bounds)thisUpdate the bounds that this overlay covers
setZIndex(<Number> value)thisChanges the zIndex of the div overlay.
getBounds-L.LatLngBoundsGet the bounds that this customDivOverlay covers
getElement-HTMLDivElementReturns the instance of HTMLDivElement used by this overlay.
setContentFunction or string or HTMLElementthis- Function If it is a Function type, execute the function and add the result of the function to the overlay as a DOMString. - string If it is a string type, it is added to the overlay as DOMString. - HTMLElement If it is a HTMLElement type, it is added to the overlay as DOMString.
getCenter-L.LatLngReturns the center of the overlay.
addTo(group: Map | LayerGroup)thisAdds the layer to the given map or layer group.
remove-thisRemoves the layer from the map it is currently active on.
removeFrom(group: Map | LayerGroup)thisRemoves the layer from the given LayerGroup
getAttribution-StringUsed by the attribution control, returns the attribution option.
6.1.0

11 months ago

6.0.1

11 months ago

6.2.1

10 months ago

6.1.1

11 months ago

6.0.2

11 months ago

6.2.2

10 months ago

7.0.0

9 months ago

7.0.4

8 months ago

7.0.3

9 months ago

7.0.2

9 months ago

7.0.1

9 months ago

7.0.6

8 months ago

7.0.9

8 months ago

7.0.10

8 months ago

6.0.0

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

4.1.0

1 year ago

4.0.1

1 year ago

4.0.3

1 year ago

4.0.0

1 year ago

3.0.11

1 year ago

3.0.10

1 year ago

3.0.8

1 year ago

3.0.9

1 year ago

3.0.7

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.1.1

2 years ago

0.0.5

2 years ago

1.1.2

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago