Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active March 9, 2024 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/61fa02b35abf4b971390 to your computer and use it in GitHub Desktop.
Save ThomasG77/61fa02b35abf4b971390 to your computer and use it in GitHub Desktop.
Leaflet simple marker
<!doctype html>
<html>
<head>
<title>Exemple de Leaflet sans Browserify</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<style type="text/css">
#map { height: 380px; }
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
</head>
<body>
<div id="map"></div>
<script>
var my_json;
var map = L.map('map').setView([51.505, -0.09], 14);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
var smallIcon = new L.Icon({
iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-icon.png',
iconRetinaUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-icon-2x.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
shadowSize: [41, 41]
});
function onEachFeature(feature, layer) {
console.log(feature);
layer.bindPopup(feature.properties.ATT1);
}
$.getJSON('sample.json', function(data) {
console.log(data);
L.geoJson(data, {
pointToLayer: function(feature, latlng) {
console.log(latlng, feature);
return L.marker(latlng, {
icon: smallIcon
});
},
onEachFeature: onEachFeature
}).addTo(map);
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment