Posted by altrugon on October 18, 2010 at 10:14pm
I apologize in advance for duplication but I also posted this over here: http://drupal.org/node/945446
I have a GMap with several nodes that come from a view and when the user click the node title inside the marker's bubble it get redirected to the actual node. However if the user goes back to the map these values are reset to the initial values and I need to present the map as s/he left it.
Right now I'm saving the latitude, longitude, and zoom in a cookie and successfully recovering these values when the map page is presented again map for some reason the map is not getting centered.
Can somebody tell me what I'm doing wrong?
Here is my code:
Drupal.behaviors.gmapsavepos = function(context) {
Drupal.gmap.addHandler('gmap', function(elem) {
var obj = this;
/
setTimeout(
function() {
var m = obj;
var pos = $.cookie('gmapsavedpos');
if (pos != null) {
//var m = Drupal.gmap.getMap(elem.id);
//m.map.setCenter(pos);
var posJSON = JSON.parse(pos);
console.log('saved pos');
console.log(JSON.stringify(posJSON));
m.vars.latitude = posJSON.latitude;
m.vars.longitude = posJSON.latitude;
m.vars.zoom = posJSON.zoom;
//m.change('move',-1);
m.map.setCenter(new GLatLng(posJSON.latitude, posJSON.latitude), posJSON.zoom);
}
},
200
);
*/
obj.bind('ready', function() {
var pos = $.cookie('gmapsavedpos');
if (pos != null) {
var map = obj.map;
var posJSON = JSON.parse(pos);
console.log('read >> ' + JSON.stringify(posJSON));
console.log(map);
/map.vars.latitude = posJSON.latitude;
map.vars.longitude = posJSON.latitude;
map.vars.zoom = posJSON.zoom;*/
map.setCenter(new GLatLng(posJSON.latitude, posJSON.longitude), posJSON.zoom);
//m.change('move',-1);
//obj.map.setCenter(new GLatLng(posJSON.latitude, posJSON.latitude), posJSON.zoom);
}
});
obj.bind('move', function() {
var centerJSON = {
'latitude': obj.vars.latitude,
'longitude': obj.vars.longitude,
'zoom': obj.vars.zoom
};
console.log('write >>' + JSON.stringify(centerJSON));
$.cookie('chfbc_gmapsavedpos', JSON.stringify(centerJSON), {expire: 1});
});
});
};As you can see I have tried several approaches :(
Comments
Problem solved.
Please find solution at http://drupal.org/node/945446