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
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"ATT1": "azerty",
"ATT2": "qsdf"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.0940704345703125,
51.505750806437845
]
}
},
{
"type": "Feature",
"properties": {
"ATT1": "uiop",
"ATT2": "ghjk"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.08591651916503906,
51.50532341149335
]
}
},
{
"type": "Feature",
"properties": {
"ATT1": "lmwx",
"ATT2": "cvbn"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.07570266723632812,
51.502224678255644
]
}
},
{
"type": "Feature",
"properties": {
"ATT1": "apsjvs",
"ATT2": "sjdpyaspet"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.07407188415527344,
51.5006752326173
]
}
},
{
"type": "Feature",
"properties": {
"ATT1": "gdtskqw",
"ATT2": "pxhzng"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.08213996887207031,
51.503293230761045
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment