-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
195 lines (183 loc) · 5.06 KB
/
index.js
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
$(function(){
draw();
function center(){
if(!window.map || !window.map.map || !window.map.map.center)
return [52.20531805547327, 0.10361167127326709];
return [map.map.center.$a, map.map.center.ab];
}
function draw(){
var c = center();
window.map = new GMaps({
div: '#map',
lat: c[0],
lng: c[1],
maxZoom: 21,
zoom:17,
click:click,
dragend:updateBounds
});
$("#map")[0].style.height = "";
$("#map")[0].style.width = "";
}
var bottomright = [52.202589349841794, 0.11149736577705127];
var topright = [52.2087632179324, 0.11328908139899951];
var top = 52.208;
var bottom = 52.202;
function updateBounds(){
/*var c = center();
var bounds = map.map.getBounds();
bounds = {left:bounds.ca.b, right:bounds.ca.j, top:bounds.ea.b, bottom:bounds.ea.j};
var correctBounds = {
left: 52.204732877295214,
right: 52.20576515270808,
top:0.10181995565130819,
bottom:0.10566087896063436
};
if(bounds.right < correctBounds.left){
map.setCenter(c[0] + (correctBounds.left - bounds.right), c[1]);
}
*/
var c = center();
if(c[0] > 52.208){
map.setCenter(52.208,c[1]);
}
if(c[0] < 52.203){
map.setCenter(52.203,c[1]);
}
if(c[1] > 0.110){
map.setCenter(c[0],0.110);
}
if(c[1] < 0.096){
map.setCenter(c[0],0.096);
}
}
console.warn = function(){};
function click(e){
console.log([e.latLng.$a, e.latLng.ab]);
$("#rooms-descriptions").val($("#rooms-descriptions").val() +
"\n" + JSON.stringify([e.latLng.$a, e.latLng.ab]));
inputChanged();
}
var infoWindow = new google.maps.InfoWindow({});
function room(path, obj){
var p = [], latlng, i;
for(i in path){
latlng = new google.maps.LatLng(path[i][0], path[i][1]);
p.push(latlng);
}
var center = (function(){
var p = [0,0]
path.forEach(function(v){
p[0] += (v[0]);
p[1] += (v[1]);
})
var lat = p[0]/path.length;
var lon = p[1]/path.length;
return new google.maps.LatLng(lat, lon);
}());
function click(e){
infoWindow.setContent('<a href="http://www.rcsa.co.uk/rooms#'+obj.id+'">'
+obj.name+'</a>');
infoWindow.setPosition(e.latLng);
infoWindow.open(map.map);
}
function poly(stroke, fill){
return map.drawPolygon({
paths: p,
strokeColor: stroke,
strokeOpacity: 1,
strokeWeight: 3,
fillColor: fill,
fillOpacity: 0.6,
click:click
});
}
var available = poly('#BBD8E9', '#BBD8E9');
var unavailable = poly(/*'#6E6E6E'*/'#BBD8E9','#A4A4A4');
var availability;
obj.update = function(a){
availability = a;
available.setVisible(availability);
unavailable.setVisible(!availability);
};
obj.update(Math.random()>0.5);
obj.remove = function(){
obj.update = function(){};
available.setVisible(false);
unavailable.setVisible(false);
};
return obj;
}
function commonRoom(path, name){
}
var rooms = [];
setInterval(function(){
for(var i = 0; i<rooms.length; i++){
rooms[i].update(Math.random()>0.5);
}
},1000);
var timeout;
$("#rooms-descriptions").keyup(inputChanged);
$(inputChanged);
function inputChanged(){
if(timeout) clearTimeout(timeout);
timeout = setTimeout(process, 500);
}
var hidables = [];
function process(){
while(hidables.length){
hidables.pop()();
}
var text = $("#rooms-descriptions").val().split(/\n\r?/g);
var input = [];
var allclear = true;
for(var i = 0; i<text.length; i++){
if(text[i].length > 0 && text[i].substr(0,1) !== "#"){
try{
input.push(JSON.parse(text[i]));
} catch (ex) {
hidables.push(error("Line "+ (i+1) + " is not a valid array"));
allclear = false;
}
}
}
if(!allclear) return;
var parsed = [];
for(var i = 0; i<input.length; i++){
if(input[i].length === 2 &&
typeof input[i][0] === "number" &&
typeof input[i][1] === "number"){
if(parsed.length === 0){
return error("You must give the room id & name before it's path");
} else {
parsed[parsed.length-1].path.push(input[i]);
}
}else{
parsed.push({id:input[i][0], name:input[i][1], path:[]});
}
}
while(rooms.length > 0){
rooms.pop().remove();
}
for(var i = 0; i<parsed.length; i++){
rooms.push(room(parsed[i].path, parsed[i]));
}
}
var errno = 0;
function error(message){
$(".alerts").append('<div class="alert" id="err'+(++errno)+'">'
+message+
'</div>');
var no = errno;
$('#err'+no).fadeIn();
var hidden = false;
function hide(){
if(!hidden){
$('#err'+no).fadeOut(function() { $(this).remove(); });
hidden = true;
}
}
setTimeout(hide, 5000);
return hide;
}
});