[OpenLayers-Users] setCenter(), maxExtent is null error, Spherical Mercator Example documentation

Ted Spradley tspradley at snoogems.com
Tue Sep 8 12:42:40 EDT 2009


Hi,

Newbie here trying to step through the documentation for Spherical Mercator
at

http://docs.openlayers.org/library/spherical_mercator.html

The second example, 'Reprojecting Point and Bounds' calls for setting a
point in lon,lat then transforming
it into projected units.

I keep getting the js error 'maxExtent is null' from /lib/OpenLayers/Map.js
line 1778 which is the 
isValidLonLat method:

################################################################
          Method generating error
    
    /**
     * Method: isValidLonLat
     * 
     * Parameters:
     * lonlat - {<OpenLayers.LonLat>}
     * 
     * Returns:
     * {Boolean} Whether or not the lonlat passed in is non-null and within
     *           the maxExtent bounds
     */
    isValidLonLat: function(lonlat) {
        var valid = false;
        if (lonlat != null) {
           var maxExtent = this.getMaxExtent();
           valid = maxExtent.containsLonLat(lonlat);      
        }
        return valid;
    },

                       End Method
################################################################


The following were my attempts to correct the code:

1.  tried setting {isBaseLayer: true} in var layer
2.  tried setting var options= {maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
setCenter: point} in  new OpenLayers.Map('map', options)
3.  numerous other attempts including setting {isBaseLayer: true} in options
4.  searched archives 

Using the supplied code on the page my script is now:

#####################################################################
                                              begin html page

<html>
<head>
  <title>Basic OpenLayers Example - Virtual Earth, Set Center</title>
    <script
src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>
    <script src="http://snoogems.com/lib/OpenLayers.js"></script>
    </head>
    <body>
      <div style="width:100%; height:100%" id="map"></div>
      <script defer='defer' type='text/javascript'>
	      // Code goes here
      		// Ver 1.0.1 - Added Set Center	9/8/2009 9:14:17 AM

      var map = new OpenLayers.Map("map");

      var layer = new OpenLayers.Layer.VirtualEarth("Virtual Earth", 
		      {sphericalMercator: true, 
			maxExtent: new  
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
			});


      var proj = new OpenLayers.Projection("EPSG:4326");
      var point = new OpenLayers.LonLat(-95.422899,29.737651);
      map.setCenter(point.transform(proj, map.getProjectionObject()));

      map.addLayer(layer);
      map.zoomToMaxExtent();

      </script>
    </body>
</html>

                                              End html page
#######################################################################

Any obvious flaws here (besides my thick head)?

Thanks, Ted S.

-- 
View this message in context: http://n2.nabble.com/setCenter-maxExtent-is-null-error-Spherical-Mercator-Example-documentation-tp3604502p3604502.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list