Forum Moderators: open
layer.setMap("custom"); layer.setMap(google.maps.MapTypeId.SATELLITE); function getCookie(name){
var cookies = document.cookie;
if (cookies.indexOf(name) != -1){
var startpos = cookies.indexOf(name)+name.length+1;
var endpos = cookies.indexOf(";",startpos)-1;
if (endpos == -2) endpos = cookies.length;
return unescape(cookies.substring(startpos,endpos));}
else return "";}
var defaultmap = (getCookie("defaultmap") == null) ? "custom" : getCookie("defaultmap");
layer.setMap(defaultmap); how do I make the variables not return an error if they haven't been defined yet
but I think google.maps.MapTypeId.SATELLITE is coming in as "google.maps.MapTypeId.SATELLITE" and being read as a string and not a variable
var defaultmap = (getCookie("defaultmap") == null) ? "custom" : getCookie("defaultmap");
var defaultMap = getCookie('defaultmap');
//in the event getCookie happened to actually return a value,
//but is not what we expected (tampered with or something),
//or did not return a useable value
if (!defaultMap || !google.maps.MapTypeId.hasOwnProperty(defaultMap)) {
layer.setMap('custom');
} else { //a google.maps.MapTypeId property name was found by getCookie
layer.setMap(google.maps.MapTypeId[defaultMap]); //using string property name access[]
}