Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heyman/leaflet-centermarker
Leaflet Marker that is kept fixed to the center of the map
https://github.com/heyman/leaflet-centermarker
Last synced: 1 day ago
JSON representation
Leaflet Marker that is kept fixed to the center of the map
- Host: GitHub
- URL: https://github.com/heyman/leaflet-centermarker
- Owner: heyman
- License: mit
- Created: 2020-10-17T13:48:37.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-29T11:45:54.000Z (9 months ago)
- Last Synced: 2024-01-29T14:15:04.605Z (9 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=====================
Leaflet CenterMarker
=====================CenterMarker is a small Leaflet plugin for adding a marker that will be fixed to the
center viewport of the map, when the map is panned/dragged.Features
========Works like the default Leaflet Marker class, but it's position will be fixed relative
to the viewport when the map is dragged. When the map has been dragged the CenterMarker
will fire a "newposition" event.See it in action
================Leaflet CenterMarker can be seen in action on `What is my address? `_
You can also see the `bundled examples `_.
Example Code
============**Create a center marker and add it to a map:**
.. code-block:: javascript
var map = L.map('map', {keyboard: true}).setView([59.324617, 18.071457], 4);
// the marker gets it's position from map.getCenter()
var marker = L.centerMarker(map);
marker.addTo(map);
marker.on("newposition", function(ev) {
console.log("Marker got new position:", marker.getLatLng());
});Known limitations
=================Currently, the marker is only kept center when the map is panned by drag event, and not if
it's panned by arrow keys on the keyboard or zooming.Author
======CenterMarker is developed by `Jonatan Heyman `_.
License
=======MIT License