-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.html
561 lines (480 loc) · 15.5 KB
/
view.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<style type="text/css">
html, body, #content {
margin: 0;
padding: 0;
border: 0 none;
height: 100%;
min-height: 100%;
overflow: hidden;
}
#header {
height: 40px;
width: 100%;
background-color: #b1fbfc;
}
#footer {
z-index: 2;
height: 50px;
width: 100%;
border: 2px solid black;
padding: 1px;
font-family: Arial, Verdana, Sans-serif;
font-size: 12px;
}
#tac {
position: absolute;
display: block;
top: 4px;
left: 4px;
padding: 2px;
font-family: Arial, Verdana, Sans-serif;
font-size: 14px;
font-weight: bold;
white-space: nowrap;
}
#title {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 6px;
width: 25%;
font-family: Arial, Verdana, Sans-serif;
font-size: 24px;
font-weight: bold;
text-align: center;
white-space: nowrap;
}
#cpbutton {
position: absolute;
z-index: 2;
top: 47px;
right: 116px;
width: 40px;
height: 18px;
background-color: #FFFFFF;
border: 1px solid grey;
border-radius: 1px;
padding: 0px 0px 0px 0px;
font-family: Arial, Verdana, Sans-serif;
font-size: 14px;
font-weight: normal;
text-align: center;
}
#cpbutton:hover {
background-color: #F0F0F0;
}
.close {
display: block;
position: absolute;
top: 10px;
right: 10px;
font-weight: bold;
}
#cpclose:hover {
color: red;
cursor: pointer;
}
#cpanel {
position: absolute;
z-index: 2;
top: 96px;
right: 10px;
width: 200px;
height: 250px;
background-color: #FFFFFF;
border: 2px solid black;
border-radius: 5px;
padding: 10px;
font-family: Arial, Verdana, Sans-serif;
font-size: 14px;
}
.cpattribute {
width: 160px;
margin: 4px;
border: 1px solid #c0c0c0;
font-size: 12px;
}
#errorMessage {
position: absolute;
display: none;
z-index: 2;
top: 200px;
right: 250px;
width: 400px;
height: 200px;
background-color: #FFFFFF;
border: 2px solid black;
border-radius: 5px;
padding: 10px;
font-family: Arial, Verdana, Sans-serif;
font-size: 14px;
}
#mapCanvas {
z-index: 1;
margin: 2px 2px 2px 2px;
padding: 0;
height: 100%;
}
.mapPopup {
position: absolute;
display: none;
background-color: #FFFFFF;
border: 2px solid #004C92;
border-radius: 5px;
padding: 10px;
font-family: Arial, Verdana, Sans-serif;
font-size: 11px;
}
.mapPopup .popupClose {
color: blue;
float: right;
font-weight: bold;
font-family: Arial, Verdana, Sans-serif;
font-size: 11px;
cursor: pointer;
border: 1px solid black;
border-radius: 2px;
padding: 1px 3px 0px 3px;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
var model = {
title: 'EA Impoundment Licence Applications',
jsonURL: 'https://api.scraperwiki.com/api/1.0/datastore/sqlite',
schemas: [ 'ea_impoundment_licence_applications' ],
query: 'select * from `licence_applications` a, `licence_locations` l WHERE a.appid = l.appid ORDER BY l.appid ASC, l.locid DESC',
dataFormat: 'jsondict',
dataSets: new Array(),
images: new Array(),
colours: [ "FE7569", "4D90FE", "FF0000", "00FF00", "0000FF", "FFFFFF" ],
mapOptions: {
zoom: 8,
center: new google.maps.LatLng(51.500000, -1.000000),
mapTypeId: google.maps.MapTypeId.ROADMAP
},
gMap: null,
gMarkers: null,
};
$(document).ready(function() {
//$('#scraperwikipane').css('top', '6px')
// .css('right', '140px');
document.title = model.title;
$('#title').text(model.title);
$('#cpanel').hide();
$('#cpbutton').click(function() {
$('#cpanel').slideDown();
});
$('.close').click(function() {
$(this).parent().slideUp();
});
$('.cpattribute img').attr('width', 12)
.attr('height', 20);
$('#cpapptype_other').prev().attr('src', getIcon(0).url);
$('#cpapptype_hydro').prev().attr('src', getIcon(1).url);
$('#cpapptype_other').click(refreshMapMarkers);
$('#cpapptype_hydro').click(refreshMapMarkers);
$('#cp_refresh').click(loadData);
createMap();
loadData();
} );
function loadData() {
clearMapMarkers();
model.dataSets = new Array();
for (var r=0; r<model.schemas.length; r++) {
var schema = model.schemas[r];
$.ajax( {
url: model.jsonURL,
dataType: 'jsonp',
data: {
name: schema,
query: model.query,
format: model.dataFormat
},
success: function(data){
model.dataSets.push(data);
addMarkers(data);
},
error: function(object, status) {
var msg = 'Failed to retrieve data for '+schema+' ('+status+'), try again';
errorMsg(msg);
}
} );
}
}
// Create map (first time through)
function createMap() {
if (!model.gMap)
model.gMap = new google.maps.Map($('#mapCanvas')[0], model.mapOptions);
}
// Clear existing markers, if any
function clearMapMarkers() {
if (model.gMarkers) {
for (var i=0; i<model.gMarkers.length; i++) {
model.gMarkers[i].setMap(null);
}
}
model.gMarkers = new Array();
}
function refreshMapMarkers() {
clearMapMarkers();
for (var i=0; i<model.dataSets.length; i++) {
var dataSet = model.dataSets[i];
addMarkers(dataSet);
}
}
function addMarkers(dataSet) {
for (var j=0; j<dataSet.length; j++) {
if (showDataPoint(dataSet[j])) {
addMarker(model.gMap, dataSet[j]);
}
}
}
function showDataPoint(point) {
if (!point|| !point.lat || !point.lng)
return false;
var form = document.forms['controls'];
if (point.hydroelectric && !form.th.checked)
return false;
if (!point.hydroelectric && !form.to.checked)
return false;
return true;
}
function addMarker(map, point) {
var icon;
if (point.hydroelectric)
icon = getIcon( point.locid );
else
icon = getIcon( 0 );
var markerPos = new google.maps.LatLng(point.lat, point.lng);
var markerOptions = {
position: markerPos,
map: map,
title: point.site_name,
icon: icon
};
var marker = new google.maps.Marker(markerOptions);
model.gMarkers.push(marker);
addDetailPopup(map, marker, point);
}
function addDetailPopup(map, marker, point) {
var text = "<div>"+
"<a target='EA_APPS' href='"+point.url+"'>"+point.site_name+"</a>"+
"<br/>Grid ref: "+point.location+
"<br/>Applicant: "+point.applicant+
"<br/>Closing date: "+point.closing_date+
"<br/>Data fetched: "+point.scrape_date+
"</div>"+
(point.hydroelectric ? "<div style='text-align:right;'><b>HYDROPOWER</b></div>" : "");
google.maps.event.addListener(marker, 'click', function() {
$('.mapPopup').remove();
var infoBox = new InfoBox({content: text, latlng: marker.getPosition(), map: map});
});
}
function getIcon( n ) {
n = (n % model.colours.length);
if (model.images[n])
return model.images[n];
var pinColour = model.colours[n];
var pinImage = new google.maps.MarkerImage(
"http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColour,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
model.images[n] = pinImage;
return pinImage;
}
function errorMsg(message) {
$('#errorMessage').append("<br/>"+message)
.show();
}
/* InfoBox extends GOverlay class from the Google Maps API */
InfoBox.prototype = new google.maps.OverlayView();
/* An InfoBox is like an info window, but it displays
* under the marker, opens quicker, and has flexible styling.
* @param {GLatLng} latlng Point to place bar at
* @param {Map} map The map on which to display this InfoBox.
* @param {Object} opts Passes configuration options - content,
* offsetVertical, offsetHorizontal, className, height, width
*/
function InfoBox(opts) {
google.maps.OverlayView.call(this);
this.latlng_ = opts.latlng;
this.map_ = opts.map;
this.content_ = opts.content;
this.offsetVertical_ = -100;
this.offsetHorizontal_ = 25;
this.width_ = 244;
var me = this;
this.boundsChangedListener_ =
google.maps.event.addListener(this.map_, "bounds_changed", function() {
return me.panMap.apply(me);
});
// Once the properties of this OverlayView are initialized, set its map so
// that we can display it. This will trigger calls to panes_changed and
// draw.
this.setMap(this.map_);
};
// Removes the DIV representing this InfoBox
InfoBox.prototype.remove = function() {
if (this.div_ && this.div_.parentNode) {
this.div_.parentNode.removeChild(this.div_);
this.div_ = null;
}
};
// Redraw the Bar based on the current projection and zoom level
InfoBox.prototype.draw = function() {
// Creates the element if it doesn't exist already.
this.createElement();
if (!this.div_) return;
// Calculate the DIV coordinates of two opposite corners of our bounds to
// get the size and position of our Bar
var pixPosition = this.getProjection().fromLatLngToDivPixel(this.latlng_);
if (!pixPosition) return;
// Now position our DIV based on the DIV coordinates of our bounds
this.div_.style.width = this.width_ + "px";
this.div_.style.left = (pixPosition.x + this.offsetHorizontal_) + "px";
this.div_.style.top = (pixPosition.y + this.offsetVertical_) + "px";
this.div_.style.display = 'block';
};
/* Creates the DIV representing this InfoBox in the floatPane. If the panes
* object, retrieved by calling getPanes, is null, remove the element from the
* DOM. If the div exists, but its parent is not the floatPane, move the div
* to the new pane.
* Called from within draw. Alternatively, this can be called specifically on
* a panes_changed event.
*/
InfoBox.prototype.createElement = function() {
var panes = this.getPanes();
var div = this.div_;
if (!div) {
// This does not handle changing panes. You can set the map to be null and
// then reset the map to move the div.
div = this.div_ = document.createElement("div");
div.style.width = this.width_ + "px";
div.className = "mapPopup";
var contentDiv = document.createElement("div");
contentDiv.innerHTML = this.content_;
var topDiv = document.createElement("div");
topDiv.className = "popupClose";
topDiv.innerHTML = "X";
function removeInfoBox(ib) {
return function() {
ib.setMap(null);
};
}
google.maps.event.addDomListener(topDiv, 'click', removeInfoBox(this));
div.appendChild(topDiv);
div.appendChild(contentDiv);
div.style.display = 'none';
panes.floatPane.appendChild(div);
this.panMap();
} else if (div.parentNode && (div.parentNode != panes.floatPane)) {
// The panes have changed. Move the div.
div.parentNode.removeChild(div);
panes.floatPane.appendChild(div);
} else {
// The panes have not changed, so no need to create or move the div.
}
}
// Pan the map to fit the InfoBox.
InfoBox.prototype.panMap = function() {
// if we go beyond map, pan map
var map = this.map_;
var bounds = map.getBounds();
if (!bounds) return;
// The position of the infowindow
var position = this.latlng_;
// The dimension of the infowindow
var iwWidth = this.width_;
var iwHeight = this.height_;
// The offset position of the infowindow
var iwOffsetX = this.offsetHorizontal_;
var iwOffsetY = this.offsetVertical_;
// Padding on the infowindow
var padX = 0;
var padY = 0;
// The degrees per pixel
var mapDiv = map.getDiv();
var mapWidth = mapDiv.offsetWidth;
var mapHeight = mapDiv.offsetHeight;
var boundsSpan = bounds.toSpan();
var longSpan = boundsSpan.lng();
var latSpan = boundsSpan.lat();
var degPixelX = longSpan / mapWidth;
var degPixelY = latSpan / mapHeight;
// The bounds of the map
var mapWestLng = bounds.getSouthWest().lng();
var mapEastLng = bounds.getNorthEast().lng();
var mapNorthLat = bounds.getNorthEast().lat();
var mapSouthLat = bounds.getSouthWest().lat();
// The bounds of the infowindow
var iwWestLng = position.lng() + (iwOffsetX - padX) * degPixelX;
var iwEastLng = position.lng() + (iwOffsetX + iwWidth + padX) * degPixelX;
var iwNorthLat = position.lat() - (iwOffsetY - padY) * degPixelY;
var iwSouthLat = position.lat() - (iwOffsetY + iwHeight + padY) * degPixelY;
// calculate center shift
var shiftLng =
(iwWestLng < mapWestLng ? mapWestLng - iwWestLng : 0) +
(iwEastLng > mapEastLng ? mapEastLng - iwEastLng : 0);
var shiftLat =
(iwNorthLat > mapNorthLat ? mapNorthLat - iwNorthLat : 0) +
(iwSouthLat < mapSouthLat ? mapSouthLat - iwSouthLat : 0);
// The center of the map
var center = map.getCenter();
// The new map center
var centerX = center.lng() - shiftLng;
var centerY = center.lat() - shiftLat;
// center the map to the new shifted center
map.setCenter(new google.maps.LatLng(centerY, centerX));
// Remove the listener after panning is complete.
google.maps.event.removeListener(this.boundsChangedListener_);
this.boundsChangedListener_ = null;
};
</script>
</head>
<body>
<div id="content">
<div id="header">
<div id="tac"><a href="http://www.rivertac.org/">TAC</a></div>
<div id="title"></div>
</div>
<div id="mapCanvas"></div>
<div id="cpbutton">Key</div>
<div id="cpanel">
<div id="cpclose" class="close">[X]</div>
Key
<form name="controls">
<table class="cpattribute">
<tr><td>Application type</td></tr>
<tr><td><img/><input id="cpapptype_hydro" type="checkbox" name="th" checked="yes">
<label for="type_hydro">Hydropower</label></td></tr>
<tr><td><img/><input id="cpapptype_other" type="checkbox" name="to" checked="yes">
<label for="type_other">Other</label></td></tr>
</table>
<table class="cpattribute">
<tr><td>Application status</td></tr>
<tr><td><img/><input id="cpappstate_open" type="checkbox" name="so" checked="yes">
<label for="state_open">Open for comments</label></td></tr>
<tr><td><img/><input id="cpappstate_approved" type="checkbox" name="sa">
<label for="state_approved">Approved</label></td></tr>
<tr><td><img/><input id="cpappstate_rejected" type="checkbox" name="sr">
<label for="state_rejected">Rejected</label></td></tr>
</table>
<input id="cp_refresh" type="button" value="Refresh"/>
</form>
<div id="errorMessage">
<div id="emclose" class="close">[X]</div>
Error messages
</div>
</div>
</div>
</body>
<html>