-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathleaflettest.html
163 lines (147 loc) · 5.53 KB
/
leaflettest.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
<head>
<title>Ottawa Riverkeeper</title>
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="js/geocoding.js"></script>
<script src="http://code.jquery.com/jquery-2.1.4.js"></script>
</script>
<!-- we encourage you to replace 'latest' with a hardcode version number (like '1.0.0-rc.7') in production applications -->
<script src="http://cdn.jsdelivr.net/leaflet.esri/latest/esri-leaflet.js"></script>
<style>
html, body {
width : 100%;
height : 100%;
}
#map {
width: 100%;
height: 600px;
}
.main-form {
}
.check-group {
display: inline-block;
}
</style>
</head>
<body>
<form action="" class="main-form">
<input id="postal-code"
type="text"
name="postalcode"
onkeypress="">
</input>
<br/>
<button id="postal-lookup" type="button" onclick="lookupPostal();">
Lookup postal code
</button>
</form>
<div id="map"></div>
<script>
// global variable storing map marker
var marker = null;
// set up Topographic map
var map = L.map('map').setView([46.52, -77], 7);
// was [45.4214, -75.6919], 7); (Ottawa), now centred on water boundry
L.esri.basemapLayer("Topographic").addTo(map);
// add water boundry overlay
feature = L.esri.featureLayer("http://services3.arcgis.com/3A9PBYcAJK4G2Muz/arcgis/rest/services/Ottawa_Watershed_Boundaries/FeatureServer/0");
feature.on('click', function(e) {
var popLocation= e.latlng;
console.log(popLocation);
if (marker == null) {
marker = L.marker(popLocation).addTo(map);
}
else {
marker.setLatLng(popLocation);
}
marker.bindPopup($("#map-form").html()).openPopup();
});
feature.addTo(map);
// submit the postal code when the user presses enter
$('#postal-code').on("keyup keypress", function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
$('#postal-lookup').click();
return false;
}
});
function addRandomPopup(mark) {
var uses = [
"1.png", "2.png", "3.png"
];
var numberUses = Math.floor(Math.random() * (uses.length - 1 )) + 1;
var usesString = "";
for (i = 0; i < numberUses; i++) {
var rnd = Math.floor(Math.random() * uses.length);
usesString += "<img src=\"img/" + uses[rnd] + "\"></img>";
}
mark.bindPopup("<div>"+usesString+"</div>");
}
function populatePoints() {
var codes = ["K1S", "K1X", "K2J", "K8A", "P0J"];
for (i = 0; i < codes.length; i++) {
code = codes[i];
$.ajax({url:"http://api.zippopotam.us/ca/" + code})
.then(function(place) {
if (place == {}) {
// couldn't look up code
}
else if (place.places.length > 0) {
var location = place.places[0];
var lat = location.latitude;
var long = location.longitude;
var m = L.marker([lat, long]).addTo(map);
addRandomPopup(m);
}
});
}
var points = [
[47.03, -77.03],
[46.5, -77.2],
[46.99, -75.564],
[46.98, -78.65]
];
for (x = 0; x< points.length; x++) {
var point = points[x];
var m = L.marker(point).addTo(map);
addRandomPopup(m);
}
}
populatePoints();
</script>
<div id="map-form" style="display: none;">
<form >
<big>
<b>
Activies
</b>
</big>
<br/>
<div class="check-group">
<input type="checkbox" name="use" value="swim"> swim<br/>
<input type="checkbox" name="use" value="sail"> sail<br/>
<input type="checkbox" name="use" value="paddle"> paddle<br/>
<input type="checkbox" name="use" value="fish"> fish<br/>
<input type="checkbox" name="use" value="motorboat"> motorboat<br/>
<input type="checkbox" name="use" value="scuba"> scuba<br/>
<input type="checkbox" name="use" value="explore"> explore/wade<br/>
</div>
<div class="check-group">
<input type="checkbox" name="use" value="camping"> camping<br/>
<input type="checkbox" name="use" value="rowing"> rowing<br/>
<input type="checkbox" name="use" value="raft"> rafting<br/>
<input type="checkbox" name="use" value="bike"> biking<br/>
<input type="checkbox" name="use" value="walk"> walk/run<br/>
<input type="checkbox" name="use" value="birding"> birding<br/>
<input type="checkbox" name="use" value="canoe"> enjoy scenery<br/>
</div>
<br/>
<b>Other</b><br/>
<input type="text" name="other" ></input>
</form>
</div>
</body>
</html>