[OpenLayers-Users] Clip WMS layers

Polet Guillaume guillaume.polet at trasys.be
Fri Feb 12 11:27:53 EST 2010


Yeah thanks a lot Christopher. I am now one step further. I have
rewritten the example in HTML/JS to provide a fully working example.
Indeed setting the extent through the options instead of the parameters
works a lot better.

One last thing though, the extent does not match exactly what I asked
(the north/east extent is not respected). I suppose that this is due to
the tiling which "can only" make 256x256 px tiles (I know that this can
be configured but I am guessing that setting this to 1x1 is the worst
solution, I tried 32x32 and it is a bit painful already), so I tried to
set singleTile option to true but then I am back to where I started, the
whole map is covered by the "clipped layer". Any thoughts? Anyway,
thanks a lot for the effort and time spent.

Here is the snippet without the singleTile: true option (and a fully
working example in attachement):

		      var b = new OpenLayers.Bounds(-25, -38, 52, 35);
			map = new OpenLayers.Map({
				div: "map",
				projection: "EPSG:4326"
			});
			
			map.addControl(mp);

		      var layers = new Array();
			var wms = new OpenLayers.Layer.WMS( "OpenLayers
WMS",
                          "http://labs.metacarta.com/wms/vmap0",
                          {layers: 'basic', maxExtent: new
OpenLayers.Bounds(-180.0,-90,180,90)} );
			layers.push(wms);
			
			layer = new OpenLayers.Layer.WMS("Clipped
image",
	
"http://www2.demis.nl/wms/wms.asp?wms=WorldMap", 
					{layers:
'Bathymetry,Topography,Hillshading,Builtup
areas,Cities,Borders,Coastlines,Roads,Highways,Rivers,Trails', format:
'image/png'},
					{isBaseLayer: false,maxExtent:
b, opacity: 1});
			layers.push(layer);
			
			map.addLayers(layers);
			map.setCenter(b.getCenterLonLat(), zoom);
			map.addControl( new
OpenLayers.Control.LayerSwitcher() );
        



Guillaume Polet
 

-----Original Message-----
From: Christopher Schmidt [mailto:crschmidt at metacarta.com] 
Sent: 12 February 2010 16:07
To: Polet Guillaume
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] Clip WMS layers

On Fri, Feb 12, 2010 at 03:18:33PM +0100, Polet Guillaume wrote:
> Hi Christopher,
> 
> Thanks for your quick response. I have not put my code because it is a
> GWT code (combined with GWT-openlayers library), however it is pretty
> straightforward to go from to another. The only problem is that it
> requires a much heavier environment to make it run.
> Anyway, here is a snippet of what I did, maybe somebody can
immediately
> spot my error. If not, I will try to set up a complete example.

maxExtent is an *option*, not a parameter.

-- Chris

> 		// This is the base layers that shows a basic world map
> (it goes on a simple MapServer hosted locally)
> 		WMSParams params = new WMSParams();
> 		params.setMaxExtent(new Bounds(-180, -90, 180, 90));
> 		params.setFormat("image/png");
> 		params.setLayers("world");
> 		WMS layer = new WMS("Basic",
> 	
>
"http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/mapfiles/W
> orldMap.map",
> 				params);
> 
> 		// This is the second layer I would like to clip to the
> extent of Africa
> 		WMSParams p2 = new WMSParams();
> 		Bounds extent = new Bounds(-25, -38, 52, 35);
> 		p2.setMaxExtent(extent);
> 		p2.setFormat("image/png");
> 		p2.setLayers("Bathymetry,Topography,Hillshading,Builtup
> areas,Cities,Borders,Coastlines");
> 		WMS resLayer = new WMS("Result",
> 	
> "http://www2.demis.nl/wms/wms.asp?wms=WorldMap",
> 				p2);
> 		resLayer.setIsBaseLayer(false);
> 		resLayer.setIsVisible(true); 
> 		getMap().addLayers(new Layer[]{layer, resLayer});
> 		getMap().addControl(new LayerSwitcher());
> 		getMap().addControl(new PanZoomBar());
> 		getMap().addControl(new Navigation());
> 		getMap().setCenter(new LonLat(0, 0),1);
> 
> With that code, the second layer takes the whole extent and therefore
> hides the rest of the map.
> 
> 
> Guillaume Polet
> 
> 
> 
> -----Original Message-----
> From: Christopher Schmidt [mailto:crschmidt at metacarta.com] 
> Sent: 12 February 2010 14:58
> To: Polet Guillaume
> Cc: users at openlayers.org
> Subject: Re: [OpenLayers-Users] Clip WMS layers
> 
> On Fri, Feb 12, 2010 at 11:03:47AM +0100, Polet Guillaume wrote:
> > Hi,
> >  
> > I wondered if it was possible to have a Basic WMS layer (displaying
> for
> > example the whole world) and on top of that have a non-basic layer
> > clipped to a specific extent. The purpose of this is to display the
> > results of a catalogue of images clipped to the selected area of
> > interest selected by a user.
> 
> I believe this is possible, so long as the overlaid datasource
> is not a tiled datasource with extents that are different than the
> data extent.
> 
> > I tried to use two WMS layers with different extents but this does
not
> > work (but maybe I have miscoded something).
> 
> If you tried something and it didn't work, providing that code will
> always
> help actually understand the problem.
> 
> Regards,
> -- 
> Christopher Schmidt
> MetaCarta
>  

-- 
Christopher Schmidt
MetaCarta
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100212/fcbfc7a2/wms-testdemis3.html


More information about the Users mailing list