Skip to content

Instantly share code, notes, and snippets.

@tilmanb
Created February 5, 2015 15:59
Show Gist options
  • Select an option

  • Save tilmanb/1010ea89f1e5ae1c2907 to your computer and use it in GitHub Desktop.

Select an option

Save tilmanb/1010ea89f1e5ae1c2907 to your computer and use it in GitHub Desktop.
leaflet marker example
<html>
<head>
<link href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script language="javascript">
var map;
function init() {
map = new L.Map('map');
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
maxZoom: 18
}).addTo(map);
map.attributionControl.setPrefix(''); // Don't show the 'Powered by Leaflet' text.
var london = new L.LatLng(51.5, 0);
map.setView(london, 10);
}
function popupMitText(pos, txt) {
var popupMitText = L.popup()
.setLatLng(pos)
.setContent(txt)
.openOn(map);
map.panTo(new L.LatLng(pos[0],pos[1]));
}
function markerMitText(pos,txt) {
var markerMitText = L.marker(pos)
.addTo(map);
markerMitText.bindPopup(txt);
markerMitText.openPopup();
map.panTo(new L.LatLng(pos[0],pos[1]));
}
$(document).ready(function() { init() } );
</script>
</head>
<body>
<h1>Test</h1>
<div id="map" style="height: 250px"></div>
Popup:
<ul>
<li><a href="#" onclick="popupMitText([52.4,13.4], 'Ich bin irgendwo in Berlin')">Popup in Berlin</a></li>
<li><a href="#" onclick="popupMitText([48.1,11.6], 'Ich bin irgendwo in München')">Popup in München</a></li>
</ul>
Marker:
<ul>
<li><a href="#" onclick="markerMitText([52.4,13.4], 'Ich bin irgendwo in Berlin')">Marker in Berlin</a></li>
<li><a href="#" onclick="markerMitText([48.1,11.6], 'Ich bin irgendwo in München')">Marker in München</a></li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment