Wednesday, December 10, 2008

WebGIS.MapPanel

In version 1.2.0 the WebGIS.Map class was removed. This was because I tried to extend the OpenLayers.Map in a way that was unnecessary.

However, there are cases when coupling OpenLayers.Map to a Ext.Panel can be a bit tricky, like when using complex layouts that renders dynamically into the DOM.

Tricky things can be knowing when to initialize the map instance and consequently when and how to execute code after initialization has been done. I've been battling with those kind of things lately and created a generic class, WebGIS.MapPanel, for solving these problems more easily. It has a event which when fired guarantees that the map instance is rendered and ready for usage and it also resizes the map when needed. Example code:

var mapPanel = WebGIS.MapPanel({mapOptions: mapOptions});

mapPanel.on('afterMapRender', function() { mapPanel.map.zoomToMaxExtent(); });

Note that the mapOptions parameter is passed to the standard OpenLayers.Map constructor parameter options.

For more proper example usage, the class is used in the debug.js application example code in the project repository.

No comments: