Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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