[OpenLayers-Users] Re: WMS object

Duarte Carreira DCarreira at edia.pt
Tue Aug 9 04:32:13 EDT 2011


This is great! In my opinion reprojection (like this at least) should be included in the 'oficial' release... don't see the advantage of not having this option available just because sometimes it won't work well enough... maybe it could be considered? Today there are 2 worlds that are not easily mixed: wms and tile services based on web Mercator; since wms is required to support 4326 but not web Mercator, and tiles are usually only web Mercator. So to build a universal viewer you have to go into some complicated steps that usually involve server-side components, or you patch OpenLayers (like what Greg showed). Why not just have it already in OL? I can always warn users about the risks of some misalignment.


Duarte


-----Mensagem original-----
De: Greg Allensworth [mailto:gregor at greeninfo.org]
Enviada: segunda-feira, 8 de Agosto de 2011 17:01
Para: Julien Cigar
Cc: openlayers-users at lists.osgeo.org; Andreas Hocevar
Assunto: Re: [OpenLayers-Users] Re: WMS object

On 8/8/2011 4:53 AM, Julien Cigar wrote:
>> This is a common pitfall when using OpenLayers. The SRS parameter will
>> be ignored. Always. Instead, WMS layers will be requested in the SRS
>> used by your base layer.
> Thanks for this enlightenment.. which is quite logical in fact, there is
> no reasons to have overlays in another projection than the base layer ...

Actually, we had a situation at a previous project where the remote WMS
service was unwilling to add new a SRS to their list. Since we wanted to
overlay their WMS onto a Spherical Mercator map, we made a simple change
to Layer/WMS.js which adds dynamic reprojection.

I have attached the patched WMS.js file. It defines a new layer type:
OpenLayers.Layer.ReprojectingWMS The magic is that last paragraph in
getFullRequestString() It adds a check for layer.params.SRS and then
reprojects the tile's bbox to make up the WMS request parameters.


Simply add the "srs" parameter to your third argument (the WMS params)
as you would any other WMS request param.

Caveat: EPSG:23031 (a European UTM) and Google's 900913 tend to convert
very strangely UNLESS you also load proj4js. If you're reprojecting, I
highly recommend proj4js be used. That's easy, though: download the
package and add the 4 <script> tags and OpenLayers will configure itself
when it loads and detects proj4js.

Complaint: If we were to go back and clean up, we would simply assign
OpenLayers.Layer.WMS.getFullRequestString() instead of naming it a new
class. The WMSGetFeatureInfo control has hardcoded into it a list of
layer types, and ReprojectingWMS is not on the list -- so this layer is
not considered a candidate for a query. The workarounds for that aren't
too onerous though.

--
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