[OpenLayers-Users] Clip WMS layers
Christopher Schmidt
crschmidt at metacarta.com
Fri Feb 12 11:44:01 EST 2010
On Fri, Feb 12, 2010 at 05:27:53PM +0100, Polet Guillaume wrote:
> 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.
All of these are correct statements; the singleTile layer does not
respect maxExtent (though it probably would be relatively simple to make
it do so), and the tiles in a WMS layer aren't clipped (adding this
would be possible, but harder). I can't imagine a way to fix either
of these situations simply.
> 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
>
Content-Description: wms-test demis3.html
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <link rel="stylesheet" href="OpenLayers-2.8/theme/default/style.css" type="text/css" />
> <link rel="stylesheet" href="style.css" type="text/css" />
> <!--<script src="http://www.openlayers.org/api/OpenLayers.js"></script>-->
> <script src="OpenLayers-2.8/lib/OpenLayers.js"></script>
> </head>
> <body>
> <div>
> <div id="map"></div>
> </div>
> <script>
> var zoom = 2;
> var map, layer;
> var mp = new OpenLayers.Control.MousePosition();
> function init() {
>
> 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() );
> }
> init();
>
> </script>
> </body>
> </html>
>
>
>
>
--
Christopher Schmidt
MetaCarta
More information about the Users
mailing list