Skip to content

Instantly share code, notes, and snippets.

@gpiffault
Created July 4, 2014 16:16
Show Gist options
  • Save gpiffault/cf11593f664a5b9e7a0b to your computer and use it in GitHub Desktop.
Save gpiffault/cf11593f664a5b9e7a0b to your computer and use it in GitHub Desktop.
Map drawing
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style type="text/css">
html, body, #map {
margin: 0;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
<script type="text/javascript">
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var _dragged = null;
map.on('click', function (e) {
L.circleMarker(e.latlng)
.on('mouseover', function () {
this.setRadius(15);
})
.on('mouseout', function () {
this.setRadius(10);
})
.on('mousedown', function (e) {
L.DomEvent.stopPropagation(e);
_dragged = this;
})
.addTo(map);
});
map.on('mousemove', function (e) {
if (_dragged) _dragged.setLatLng(e.latlng);
});
map.on('mouseup', function (e) {
if (_dragged) _dragged = null;
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment