D
deepweb
Hi there,
I am creating a site that has a Google regional map that is selected
via a
drop down.
It is displayed on the same page using the regionid passed as a
variable in the url
I have some javascript code that I have got to save the state of the
map, so the visitor can return to the map, however, if they choose
another region, they go back to the original one as that is what has
been saved in the cookie.
How can I save and read a cookie to handle this.
Do I have as many cookies set as regions visited? Or can I have each
region stored in the same cookie?
Here is the load / save code
-------------------------------------
<script language="JavaScript" type="text/JavaScript">
function Save()
{
var mapzoom=map.getZoom();
var mapcenter=map.getCenter();
var maplat=mapcenter.lat();
var maplng=mapcenter.lng();
var cookiestring=maplat+"_"+maplng+"_"+mapzoom;
var exp = new Date(); //set new date object
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30)); //set it 30
days ahead
setCookie("DaftLogicGMRLL",cookiestring, exp);
}
function Load()
{
var loadedstring=getCookie("DaftLogicGMRLL");
var splitstr = loadedstring.split("_");
map.setCenter(new GLatLng(parseFloat(splitstr[0]), parseFloat(splitstr
[1])), parseFloat(splitstr[2]));
}
function setCookie(name, value, expires)
{
document.cookie = name + "=" + escape(value) + "; path=/" + ((expires
== null) ? "" : "; expires=" + expires.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring
(c_start,c_end));
}
}
return "";
}
</script>
Thanks in advance
Cheers
Steven
I am creating a site that has a Google regional map that is selected
via a
drop down.
It is displayed on the same page using the regionid passed as a
variable in the url
I have some javascript code that I have got to save the state of the
map, so the visitor can return to the map, however, if they choose
another region, they go back to the original one as that is what has
been saved in the cookie.
How can I save and read a cookie to handle this.
Do I have as many cookies set as regions visited? Or can I have each
region stored in the same cookie?
Here is the load / save code
-------------------------------------
<script language="JavaScript" type="text/JavaScript">
function Save()
{
var mapzoom=map.getZoom();
var mapcenter=map.getCenter();
var maplat=mapcenter.lat();
var maplng=mapcenter.lng();
var cookiestring=maplat+"_"+maplng+"_"+mapzoom;
var exp = new Date(); //set new date object
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30)); //set it 30
days ahead
setCookie("DaftLogicGMRLL",cookiestring, exp);
}
function Load()
{
var loadedstring=getCookie("DaftLogicGMRLL");
var splitstr = loadedstring.split("_");
map.setCenter(new GLatLng(parseFloat(splitstr[0]), parseFloat(splitstr
[1])), parseFloat(splitstr[2]));
}
function setCookie(name, value, expires)
{
document.cookie = name + "=" + escape(value) + "; path=/" + ((expires
== null) ? "" : "; expires=" + expires.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring
(c_start,c_end));
}
}
return "";
}
</script>
Thanks in advance
Cheers
Steven