[OpenLayers-Users] Zooming to an extend via link outside map viewport

Max Stephan x.zam at gmx.net
Mon Mar 23 09:16:03 EDT 2009


Hey Heidtmare,

my map-variable was already defined outside the body of the init-function.
But I made a stupid mistake: I overwrote the predefined variable in the body
of the init function with " var map = new OpenLayers ... ". Now that I
removed the "var"-statement it works fine ...

Thank you for the hint
Max Stephan

P.S.: Yes, I´m just a javascript-beginner coming from Java-programming
:teeth: But I think most of the paradigms are the same in javascript as in
java with the difference that Java is much more mighty. And I found a nice 
http://blog.morrisjohns.com/javascript_closures_for_dummies site about
Javascript closures . And getter-functions are also well known from Java ...
now I only have to translate them to Javascript %-O


Heidtmare wrote:
> 
> Define map globally outside init, and set its value within.
> 
> Var map;
> Function init()
> {
> 	map = new OpenLayers.......bla bla bla
> }
> 
> Now you can use map anywhere.
> 
> As you get more advanced with js you can learn about closures
> and design getter functions, but this should work for now.
> 
> 
> -----Original Message-----
> From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
> On Behalf Of Max Stephan
> Sent: Sunday, March 22, 2009 9:58 AM
> To: users at openlayers.org
> Subject: [OpenLayers-Users] Zooming to an extend via link outside map
> viewport
> 
> 
> Hey everybody,
> 
> I want to place a link outside the map which zooms to a specified extent
> (something like "javascript: map.zoomToExtent(new
> OpenLayers.Bounds(1,2,3,4))" as a link in the body). But it´s logically
> not that easy because I have to get access to the map-variable that is
> unfortunately in the init-function.
> 
> So I tried several things. For example I defined a function named "zoom"
> which contains "map.zoomToExtent(1,2,3,4);" in it´s body but that´s not
> working at all. The only way that worked was to empty the
> map-div-container via "document.getElementById('map').innerHTML="";" and
> to run the function init with the new bounds as a parameter afterwards.
> 
> Does anyone know a more elegant way than reloading the complete
> init-function?
> 
> Thx in advance
> Max Stephan
> --
> View this message in context:
> http://n2.nabble.com/Zooming-to-an-extend-via-link-outside-map-viewport-tp2517040p2517040.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Zooming-to-an-extend-via-link-outside-map-viewport-tp2517040p2521019.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list