-
Notifications
You must be signed in to change notification settings - Fork 4
/
leaflet-ajax.html
58 lines (51 loc) · 1.95 KB
/
leaflet-ajax.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=1024, user-scalable=no" />
<title>Leaflet AJAX</title>
<style>html{height:100%} body{height:100%; margin:0; padding:0;} #map{height:100%}</style>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<!--[if lte IE 8]> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" /> <![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="js/leaflet.ajax.js"></script>
<!-- <script src="js/leaflet.ajax.min.js"></script> -->
</head>
<body>
<div id="map"></div>
<script type="text/javascript">var m= L.map('map').setView([42.2, -71], 8);
var mapQuestAttr = 'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> — ';
var osmDataAttr = 'Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
var mopt = {
url: 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpeg',
options: {attribution:mapQuestAttr + osmDataAttr, subdomains:'1234'}
};
var osm = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:osmDataAttr});
var mq=L.tileLayer(mopt.url,mopt.options);
mq.addTo(m);
var baseMaps = {
"Map Quest": mq,
"Open Street Map":osm
};
function popUp(f,l){
var out = [];
if (f.properties){
for(key in f.properties){
out.push(key+": "+f.properties[key]);
}
l.bindPopup(out.join("<br />"));
}
}
var jsonTest = new L.GeoJSON.AJAX("test.geojson",{onEachFeature:popUp});
var jsonpTest = L.geoJson.ajax("http://kublai.ro.lt/test.geojson",{onEachFeature:popUp,dataType:"jsonp"});
jsonTest.addTo(m);
var overlays={
"json":jsonTest,
"jsonp":jsonpTest
}
var lc=L.control.layers(baseMaps,overlays);
lc.addTo(m);
</script>
</body>
</html>