Hi, zzolo,
I'm trying to setCenter on a map, but I can't find the instance to call the function on. I am in my own JS code, called from a user action; that code calculates certain lat/lon values and is supposed to center the map around these values.
I have a map-id as -- say "openlayers-map-12345678" -- from Drupal.settings.openlayers.maps
and I find the containing div with $('openlayers-map-12345678').
In some of the code examples I also see $('#openlayers-map-12345678') and $('#openlayers-map-12345678').data(...) but that first expressions returns NULL for me.
So I tried to dig into the Drupal.openlayers data tree, but no luck; following the construction of the map object also didn't enlighten me. Any help appreciated!
Thanks for your support!
-Karsten
PS: You guessed it, I am writing my own "enter your address here and the map will center around it" function because I could not find any support (yet) for that; did I overlook something?
Comments
Comment #1
kmadel commentedThe following works for me:
Comment #2
nod_You can't use the map ID to select it in JS, it changes all the time. You should do it like kmadel described.
I'll have to implement the 'enter you address and i'll center the map' too there should be a patch in the comming weeks to take care of it.
I'm closing unless you need more help with that.
Comment #4
gc23 commentedSorry to dig up this thread, but I too am experiencing this same problem and the code posted didn't help.
Basically, I am using openlayers using a view, and don't know if this could cause an issue.
I have a single map showing on the page and used firebug to execute JS.
var ol = $('.openlayers-map').data('openlayers');Does not work, it cannot find the cmap and returns null, so instead I used the full id of the div like so:
var ol = $('openlayers-map-99401a36').data('openlayers');Which then generates the following:
TypeError: $("openlayers-map-99401a36").data is not a function
Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
[error] return jQuery(contentView).hasClass('popupWindow');
PS. I am using 7.x-2.0-beta1.
Thanks
Comment #5
gc23 commentedComment #6
nod_Well,
$()is not registered anymore. You should usejQuery()from the command line.Comment #7
gc23 commentedAh yes indeed. Thank you. All works fine now.