[OpenLayers-Users] centerLayerContainer is setting pixel center to 0, 0

Eric Mckenna emckenna at phase2technology.com
Fri Aug 7 20:02:16 EDT 2009


I've been through this for two days now and can't get this figured out.  I can see why it's happening, but everything I see online about calling Gmap.checkResize() doesn't fix this particular problem. 

This bug happens about 90% of the time, the other 10% the map renders correctly and gets the correct center.  

For my popup, I'm using the JS Tools overlay.

What my popup and map look like.
http://skitch.com/emackn/b4ue9/offcentermap

Here's my debug output.
http://skitch.com/emackn/b4ues/centerlayercontainer-debug


Here's how I call centerLayerContainer:
===============================================
function hotspotsLaunchDetails(anchor) {
  $.getJSON($(anchor).attr("href"), 
    function(data) {
      $('#hotspot-overlay-map').html('');
      hotspotsRenderDetailMap("hotspot-overlay-map", data.hotspot);

      var map = Drupal.hotspotsMap['hotspot-overlay-map'];
          
      var lat = Number(data.hotspot.latitude);
      var lon = Number(data.hotspot.longitude);
      var hotspot = new OpenLayers.LonLat(lon, lat);
      debugger;

      // I added this here since the map should always be available after rendering.
      map.centerLayerContainer(hotspot);
      //map.updateSize();
      
    }
  );
  Drupal.hotspotOverlay.load();
  return false;
}

and where I set up my map.
===============================================
function hotspotsRenderDetailMap(id, config) {
  var lat = Number(config.latitude);
  var lon = Number(config.longitude);
  var zoom = Number(config.zoom);
  var image = config.marker;
  var hotspot = new OpenLayers.LonLat(lon, lat);

  OpenLayers.ImgPath = config.imgpath;
  
  var map = new OpenLayers.Map(id, {
      controls: [
          new OpenLayers.Control.Navigation(),
          new OpenLayers.Control.PanZoomBar(),
          new OpenLayers.Control.ScaleLine(),
          new OpenLayers.Control.LayerSwitcher()
      ],
  });
  
  // In case something needs to get at this later
  if (!Drupal.hotspotsMap) {
    Drupal.hotspotsMap = [];
  } 
  
  Drupal.hotspotsMap[id] = map;

  var google = new OpenLayers.Layer.Google(
    "Google Hybrid",
    { type: G_HYBRID_MAP, 
      numZoomLevels: 18,
    }
  );
  
  map.addLayer(google);
  //google.setMapObjectCenter(hotspot, zoom);
  
  if (!map.getCenter()) {
    
    //var epsg4326 = new OpenLayers.Projection("EPSG:4326");
    var epsg3785 = new OpenLayers.Projection("EPSG:3785");
    //hotspot.transform(epsg4326, map.getProjectionObject());
    hotspot.transform(epsg3785, map.getProjectionObject());
    map.setCenter(hotspot, zoom);
    //google.setMapObjectCenter(hotspot, zoom);
  } 
  
  // MARKERS AND KML

  ...

  map.setLayerIndex(markers, 100);
  map.centerLayerContainer(hotspot);
  map.updateSize();
}

-- 
Eric Mckenna
Software Engineer
Phase2 Technology
direct:   703.548.6050,110
emckenna at phase2technology.com

www.phase2technology.com
Web solutions that fit your business.



More information about the Users mailing list