Skip to content

Instantly share code, notes, and snippets.

@meholden
Last active July 20, 2017 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meholden/a953f7f6f34efb78bb60577a6770f65b to your computer and use it in GitHub Desktop.
Save meholden/a953f7f6f34efb78bb60577a6770f65b to your computer and use it in GitHub Desktop.
geojson leaflet stuff
<!DOCTYPE html>
<html>
<head>
<title>meh</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" integrity="sha512-07I2e+7D8p6he1SIM+1twR5TIrhUQn9+I6yjqD53JQjFiMf8EtC93ty0/5vJTZGF8aAocvHYNEDJajGdNx1IsQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js" integrity="sha512-A7vV8IFfih/D732iSSKi20u/ooOfj/AGehOKq0f4vLT1Zr2Y+RX7C+w8A1gaSasGtRUZpF/NZgzSAu4/Gc41Lg==" crossorigin=""></script>
</head>
<body>
<div id="mapid" style="width: 600px; height: 400px;"></div>
<script>
var mymap = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.satellite'
}).addTo(mymap);
var data = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "pt A",
"temp": "75.12",
"speed": "1.0"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.06,
51.5
]
}
},
{
"type": "Feature",
"properties": {
"name": "Pt B",
"temp": "63.43",
"speed": "1.2"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.08,
51.5
]
}
},
{
"type": "Feature",
"properties": {
"name": "Pt C",
"temp": "67.43",
"speed": "1.3"
},
"geometry": {
"type": "Point",
"coordinates": [
-0.10,
51.5
]
}
}
]
}
L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindTooltip("Name:"+feature.properties.name + "<br>T:"+feature.properties.temp,
{noHide: true,permanent: true,opacity: 0.8, direction: 'top'});
}
}).addTo(mymap);
</script>
<div id="dodo" style="width: 600px; height: 400px;"></div>
<script>
document.getElementById("dodo").innerHTML = "<br>Here is the geojson text: <br><pre>" + JSON.stringify(data) + "</pre";
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment