[OpenLayers-Users] How to use bbox in long/lat with google/bing/etc... using mapserver
Greg Allensworth
gregor at greeninfo.org
Tue Jan 22 10:10:24 PST 2013
On 1/21/2013 2:44 PM, Gery . wrote:
> The bbox of OpenLayers.Control.GetFeature works in utm
> when the baselayer is 900913 ie. google/bing/etc) and
> in long/lat when the baselayer is 4326
Correct. The control will use the map's SRS when stating the bbox.
> How can I force bbox to be in long/lat when I use one of
> my layers over google for example?
Two options:
1. Don't. Your WMS should support queries in multiple SRSs. If you're
using MapServer, for example:
WEB
METADATA
"wms_title" "wms_mapfile"
"wms_onlineresource"
"http://domain.org/cgi-bin/mapserv?map=/my/wms.map&"
"wms_srs" "EPSG:3857 EPSG:900913 EPSG:4326"
END
END
2. If you do want the bbox in your chosen SRS, you would need to
subclass the GetFeatureInfo control and patch it to .transform() the
bounding box. This UNTESTED JavaScript code for
OpenLayers.Control.LatLonWMSGetFeatureInfo would would look something
like this:
OpenLayers.Control.LatLonWMSGetFeatureInfo =
OpenLayers.Class(OpenLayers.Control.WMSGetFeatureInfo, {
buildWMSOptions: function(url, layers, clickPosition, format) {
// call the parent class to get the options
var opts = OpenLayers.Control.WMSGetFeatureInfo(url, layers,
clickPosition, format);
// replace the bbox with the one from the map, coerced into
WGS84 coords
var OLD_SRS = this.map.getprojectionObject();
var SRS_LONLAT = new OpenLayers.Projection('EPSG:4326');
opts.params.bbox =
bbox:
this.map.getExtent().transform(OLD_SRS,SRS_LONLAT).toBBOX(null,firstLayer.reverseAxisOrder());
}
// hand these back, as if nothing had happened
return opts;
});
--
Greg Allensworth, Web GIS Developer
BS A+ Network+ Security+ Linux+ Server+
GreenInfo Network - Information and Mapping in the Public Interest
564 Market Street, Suite 510 San Francisco CA 94104
PH: 415-979-0343 x302 FX: 415-979-0371 email: gregor at greeninfo.org
Web: www.GreenInfo.org www.MapsPortal.org
Subscribe to MapLines, our e-newsletter, at www.GreenInfo.org
More information about the Users
mailing list