-
Notifications
You must be signed in to change notification settings - Fork 29
/
demo.html
48 lines (41 loc) · 1.25 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Demo: Leaflet.CountrySelect</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="Leaflet.CountrySelect.js"></script>
</head>
<style>
html, body, #map {
padding:0px;
margin:0px;
height:100%;
width:100%;
}
</style>
<script>
function init(){
var baseLayer = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{attribution: 'Tiles © CartoDB'});
var map = L.map("map",{layers: [baseLayer], center: [-23.88, -62.75], zoom: 4});
var select = L.countrySelect({exclude:"French Southern and Antarctic Lands"});
select.addTo(map);
select.on('change', function(e){
if (e.feature === undefined){ //Do nothing on title
return;
}
var country = L.geoJson(e.feature);
if (this.previousCountry != null){
map.removeLayer(this.previousCountry);
}
this.previousCountry = country;
map.addLayer(country);
map.fitBounds(country.getBounds());
});
}
</script>
<body onload="init()">
<div id="map"></div>
</body>
</html>