Skip to content

Commit 1d34e6b

Browse files
added hash urls
The configuration for the current view will be set in hash part of the url. This should make linking a specific view as easy as copying the current url. The feature is also a stepping stone for the upcoming searchbar.
1 parent 668295b commit 1d34e6b

File tree

3 files changed

+279
-106
lines changed

3 files changed

+279
-106
lines changed

js/app.js

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,148 @@ if(
1111
navigator.userAgent.match(/BlackBerry/i)
1212
) is_mobile = true;
1313

14-
// wvar detection
15-
var vfilter = "";
16-
var nyan_mode = false;
14+
// hash url
15+
var history_supported = (typeof history !== 'undefined');
16+
17+
function lhash_update(history_step) {
18+
history_step = !!history_step;
19+
20+
var url = document.location.href.split("#",1)[0];
21+
var hash = "";
22+
23+
// generate hash
24+
hash += "mt=" + map.getMapTypeId();
25+
hash += "&mz=" + map.getZoom();
26+
27+
if(!/^[a-z0-9]{32}$/ig.exec(wvar.query)) {
28+
hash += "&qm=" + wvar.mode;
29+
}
30+
31+
if(follow_vehicle === null || manual_pan) {
32+
hash += "&mc=" + map.getCenter().toString().replace(/[ )(]/g,'');
33+
}
34+
35+
if(follow_vehicle !== null) {
36+
hash += "&f=" + follow_vehicle;
37+
}
38+
39+
if(wvar.query !== "") {
40+
hash += "&q=" + wvar.query;
41+
}
1742

43+
// other vars
44+
if(wvar.nyan) {
45+
hash += "&nyan=1";
46+
}
47+
48+
hash = encodeURI(hash);
49+
// set state
50+
if(history_supported) {
51+
if(!history_step) {
52+
history.replaceState(null, null, url + "#!" + hash);
53+
} else {
54+
history.pushState(null, null, url + "#!" + hash);
55+
}
56+
} else {
57+
document.location.hash = "!" + hash;
58+
}
59+
60+
console.log("hash:", hash);
61+
}
62+
63+
// wvar detection
1864
var wvar = {
1965
enabled: false,
2066
vlist: true,
2167
graph: true,
2268
graph_exapnded: false,
2369
focus: "",
24-
docid: "",
2570
mode: (is_mobile) ? modeDefaultMobile : modeDefault,
71+
zoom: true,
72+
query: "",
73+
nyan: false,
2674
};
2775

76+
77+
function load_hash(no_refresh) {
78+
no_refresh = (no_refresh === null);
79+
console.log("hash load");
80+
var hash = window.location.hash.slice(2);
81+
82+
if(hash === "") return;
83+
84+
var parms = hash.split('&');
85+
var refresh = false;
86+
var refocus = false;
87+
88+
// defaults
89+
manual_pan = false;
90+
91+
var def = {
92+
mode: wvar.mode,
93+
zoom: true,
94+
focus: "",
95+
query: "",
96+
nyan: false,
97+
};
98+
99+
parms.forEach(function(v) {
100+
v = v.split('=');
101+
k = v[0];
102+
v = decodeURIComponent(v[1]);
103+
104+
switch(k) {
105+
case "mt":
106+
map.setMapTypeId(v);
107+
break;
108+
case "mz":
109+
map.setZoom(parseInt(v));
110+
break;
111+
case "mc":
112+
def.zoom = false;
113+
manual_pan = true;
114+
v = v.split(',');
115+
var latlng = new google.maps.LatLng(v[0], v[1]);
116+
map.setCenter(latlng);
117+
break;
118+
case "f":
119+
refocus = (follow_vehicle != v);
120+
follow_vehicle = v;
121+
def.focus = v;
122+
break;
123+
case "qm":
124+
def.mode = v;
125+
break;
126+
case "q":
127+
def.query = v;
128+
break;
129+
case "nyan":
130+
def[k] = !!parseInt(v);
131+
break;
132+
}
133+
});
134+
135+
// check if we should force refresh
136+
['mode','query','nyan'].forEach(function(k) {
137+
if(wvar[k] != def[k]) refresh = true;
138+
});
139+
140+
$.extend(true, wvar, def);
141+
142+
// force refresh
143+
if(!no_refresh) {
144+
if(refresh) clean_refresh(wvar.mode, true);
145+
else if(refocus) {
146+
$(".row.active").removeClass('active');
147+
$(".vehicle"+vehicles[wvar.focus].uuid).addClass('active');
148+
followVehicle(wvar.focus, manual_pan, true);
149+
}
150+
}
151+
152+
lhash_update();
153+
}
154+
window.onhashchange = load_hash;
155+
28156
var params = window.location.search.substring(1).split('&');
29157

30158
for(var idx in params) {
@@ -41,8 +169,8 @@ for(var idx in params) {
41169
case "hidelist": if(line[1] == "1") wvar.vlist = false; break;
42170
case "hidegraph": if(line[1] == "1") wvar.graph = false; break;
43171
case "expandgraph": if(line[1] == "1") wvar.graph_expanded = true; break;
44-
case "filter": vfilter = decodeURIComponent(line[1]); break;
45-
case "nyan": nyan_mode = true; break;
172+
case "filter": wvar.query = decodeURIComponent(line[1]); break;
173+
case "nyan": wvar.nyan = true; break;
46174
case "focus": wvar.focus = decodeURIComponent(line[1]); break;
47175
case "docid": wvar.docid = line[1]; break;
48176
case "mode": wvar.mode = decodeURIComponent(line[1]); break;

js/gmaps_extentions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ google.maps.DropDownControl = function(options) {
170170
});
171171
};
172172

173+
google.maps.DropDownControl.prototype.setVisible = function(isVisible) {
174+
isVisible = !!isVisible;
175+
this.div_.style.display = (isVisible) ? 'block' : 'none';
176+
};
177+
173178
// simple status control
174179

175180
google.maps.StatusTextControl = function(options) {

0 commit comments

Comments
 (0)