[OpenLayers-Users] ZoomToMaxExtent Control

Scott Davis scott at davisworld.org
Fri Jun 1 17:30:03 EDT 2007


Hey,

Congrats on the 2.4 release.

As I'm digging into the API, it appears that the ZoomToMaxExtent  
control is broken as shipped. (Please correct me if I'm wrong.) It  
seems to be missing the click handler and the associated CSS to get  
it to appear. I did the following to get it working. Am I on the  
right track?

========
<html>
<head>
<style type="text/css" media="screen">
.olControlZoomToMaxExtent {
   background-image: url("http://www.openlayers.org/api/img/zoom- 
world-mini.png");
   background-repeat: no-repeat;	
   width:  24px;
   height: 24px;
   float:right;
   position: relative;
   top:1em;
   right:1em;
}	
</style>	
	
<script src="http://www.openlayers.org/api/OpenLayers.js" type="text/ 
javascript"></script>
<script type="text/javascript">
	function init(){
		var map = new OpenLayers.Map('map')
		var ol_wms = new OpenLayers.Layer.WMS( "World Map",
		              "http://labs.metacarta.com/wms-c/Basic.py?",
		              {layers: 'basic', format: 'image/png' } );
		map.addLayer(ol_wms)
		map.zoomToMaxExtent()
		
		var ztme = new OpenLayers.Control.ZoomToMaxExtent()
		map.addControl(ztme);
		OpenLayers.Event.observe(ztme.div, "click",  
ztme.trigger.bindAsEventListener(ztme));
	}
</script>
</head>

<body onload="init()">
     <div id="map"></div>
</body>

</html>
=========


To make this fix permanent, the CSS probably belongs in theme/default/ 
style.css. The Event.Observe probably belongs in an initialize  
function, and a corresponding Event.stopObservingElement belongs in  
destroy, yes?


=========
initialize: function() {
   OpenLayers.Event.observe(this.div, "click",  
this.trigger.bindAsEventListener(this));
}

destroy: function() {
   OpenLayers.Event.stopObservingElement(this.div);
}
=========


I just want to make sure that this is idiomatic OpenLayers as I start  
writing my own controls.

Cheers,
s

Scott Davis
scott at davisworld.org






More information about the Users mailing list