Open Layers – Zoom to extent (WMS)


Всего-то три часа заняло. Прогресс.

This method initializes layer.maxExtent, so 'zoom to layer' operations work properly. In latest open layers distro method getDataExtent() is not implemented for WFS and WMS layers. This method is a poor man's replacement. It's easy to generalize for WFS layers, if you like. I just needed to jury rig something fast.

var fixWMSLayerExtent = function(layer)
{
var readr = new Ext.data.XmlReader(
{ record: 'Layer'},
[
{name: 'name', mapping: 'Name'}
,{name: 'minx', mapping: 'LatLonBoundingBox > @minx'}
,{name: 'miny', mapping: 'LatLonBoundingBox > @miny'}
,{name: 'maxx', mapping: 'LatLonBoundingBox > @maxx'}
,{name: 'maxy', mapping: 'LatLonBoundingBox > @maxy'}
]);

var myStore = new Ext.data.Store({
url : "/MapProxy?url=" + layer.url +'&request=GetCapabilities' ,
reader : readr
});
myStore.load({'layer' : layer, callback: function(r, options, success)
{
var rindex = this.find('name', options.layer.name, 0, true, true);
var rec = this.getAt(rindex);
layer.maxExtent = new OpenLayers.Bounds(rec.data.minx, rec.data.miny, rec.data.maxx, rec.data.maxy);
} });
};

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree