]> git.openstreetmap.org Git - rails.git/commitdiff
Avoid a JS error on (e.g.) ?way=nnnnn
authorJohn Firebaugh <john.firebaugh@gmail.com>
Tue, 2 Oct 2012 02:21:37 +0000 (19:21 -0700)
committerTom Hughes <tom@compton.nu>
Tue, 2 Oct 2012 17:22:17 +0000 (18:22 +0100)
When showing an object, the map location is not set
until the vector layer has finished loading. Thus
map.getCenter() returns null.

Registering the events earlier avoids the need to call
updateLocation manually at all.

app/assets/javascripts/index.js

index 0ceb015a74380a8199fbf4c6c24befab8139dc6c..9a05ae1ddf0accf67dbd83e1272336ad7cbf1383 100644 (file)
@@ -7,6 +7,9 @@ $(document).ready(function () {
   var params = OSM.mapParams();
   var map = createMap("map");
 
+  map.events.register("moveend", map, updateLocation);
+  map.events.register("changelayer", map, updateLocation);
+
   if (!params.object_zoom) {
     if (params.bbox) {
       var bbox = new OpenLayers.Bounds(params.minlon, params.minlat, params.maxlon, params.maxlat);
@@ -39,10 +42,6 @@ $(document).ready(function () {
     $(window).load(function() { addObjectToMap(url, params.object_zoom) });
   }
 
-  map.events.register("moveend", map, updateLocation);
-  map.events.register("changelayer", map, updateLocation);
-
-  updateLocation();
   handleResize();
 
   $("#show_data").click(function (e) {