-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleMapGeoJSON.html
69 lines (69 loc) · 2.4 KB
/
simpleMapGeoJSON.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html>
<head>
<!-- the following links add the CSS and Javascript required for the Leaflet Map -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-
wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw=="
crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-
mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA==
"
crossorigin=""></script>
<link rel="stylesheet" href="ionicons.min.css">
<link rel="stylesheet" href="leaflet.awesome-markers.css">
<script src="leaflet.awesome-markers.js"></script>
<!-- the following CSS is used to set the size of the Map -->
<style type="text/css">#mapid { height: 180px; }
</style>
</head>
<body>
<!-- the mapid div will hold the map -->
<div id="mapid" style="width: 600px; height: 400px;"></div>
<!-- the following script will load the map and set the default view and zoom, as well as loading the
basemap tiles -->
<script>
// load the map
var mymap = L.map('mapid').setView([51.505, -0.09], 13);
// load the tiles
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data ©<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.streets'
}).addTo(mymap);
// creating a custom icon
var testMarkerPink = L.AwesomeMarkers.icon({
icon: 'play',
markerColor: 'pink'
});
// create a geoJSON feature -
var geojsonFeature = {
"type": "Feature",
"properties": {
"name": "London",
"popupContent": "This is where UCL is based"
},
"geometry": {
"type": "Point",
"coordinates": [-0.133628, 51.524511]
}
};
// and add it to the map
L.geoJSON(geojsonFeature, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon:testMarkerPink});
}
}).addTo(mymap).bindPopup("<b>"+geojsonFeature.properties.name+""+geojsonFeature.properties.popupContent+"<b>");
// movable marker
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(mymap);
}
mymap.on('click', onMapClick);
</script>
</body>
</html>