[OpenLayers-Users] zoom to different WMS layers

Alexandre Dube adube at mapgears.com
Mon Aug 24 10:05:05 EDT 2009


You're not using the setCenter method properly.  See its documentation :
http://dev.openlayers.org/releases/OpenLayers-2.5/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.setCenter

I noticed you use OpenLayers 2.5.  Just keep in mind that it's an old 
version and that some cool new functionalities are added with new 
releases.  Current version is 2.8.

Regards,

Alexandre

Paul Curran wrote:
>
> Hi,
>
>  
>
> I wish to have a map of the UK with different layers being displayed 
> depending on how close I am zoomed into the map.
>
>  
>
> Currently I can view a map of the UK which displays fine via 
> OpenLayers. However I can only view the first layer of my map (  a 
> 1:50000 scaled image of the UK). I wish to zoom in to the next layer 
> of the UK (a 1:250 000 scaled image of the UK)
>
>  
>
> Is this possible with Openlayers?
>
>  
>
> Any help greatly appreciated
>
>  
>
> My code is below
>
>  
>
> Cheers
>
>  
>
> <script type="text/javascript">
>
>  
>
>       var zoom = 10;
>
>       var bounds = new OpenLayers.Bounds(0, 0, 660046, 1229782);
>
>       var map, layer;
>
>      
>
>      
>
>       function init(){
>
>           map = new OpenLayers.Map('map', { maxExtent: bounds, 
> maxResolution: 156543, units: 'meters',
>
>           projection: "EPSG:4326", numZoomlevels: 10 });
>
>       map.addControl(new OpenLayers.Control.PanZoomBar());
>
>       map.addControl(new OpenLayers.Control.OverviewMap());
>
>       map.addControl(new OpenLayers.Control.MousePosition());
>
>       layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>
>       "http://127.0.0.1/cgi-bin/mapserv.exe?", { layers: 'uk', map: 
> '/ms4w/apps/openlayers-2.5/data/uk2.map' },
>
>       { gutter: 15 });      
>
>       map.addLayer(layer);
>
>       map.zoomToExtent(bounds);
>
>       map.setCenter(bounds);  
>
>            
>
>       }
>
>      
>
>     </script>
>
>  
>
> MAP
>
>    
>
>     NAME UK1
>
>             PROJECTION
>
>     'proj=longlat'
>
>     'ellps=WGS84'
>
>     'datum=WGS84'
>
>     'no_defs'
>
>     ''
>
>     END 
>
>     SIZE 1600 1200
>
>     IMAGECOLOR  153 204 255
>
>     IMAGETYPE JPEG
>
>     SHAPEPATH "http://localhost/openlayers/data/"
>
>     #QGIS
>
>     #EXTENT  -837824 -111116 1677552 1232884
>
>     #Port Talbot
>
>     #EXTENT 272000 187000 278000 193000
>
>     #UK
>
>     EXTENT  0 0 660046 1229782
>
>     UNITS METERS
>
>    
>
>            
>
>             WEB
>
>               TEMPLATE "http://localhost/openlayers/examples/uktest.html"
>
>               LOG "\ms4w\tmp\ms_tmp\log.txt"
>
>       IMAGEPATH "\ms4w\tmp\ms_tmp\"
>
>       IMAGEURL "/ms_tmp/"
>
>       METADATA
>
>                         'wms_title' "map"
>
>         'wms_onlineresource'  
> "http://127.0.0.1./cgi-bin/mapserv?map=uk2.map"
>
>       END
>
>  
>
>             END
>
>  
>
>   LAYER
>
>  
>
>                NAME "UK"
>
>                METADATA
>
>                  'wms_title' "wms_demo"
>
>                END
>
>                STATUS DEFAULT
>
>                TYPE raster
>
>                TILEINDEX "map"
>
>                TILEITEM "Location"
>
>                PROJECTION
>
>                         'proj=longlat'
>
>                         'ellps=WGS84'
>
>                         'datum=WGS84'
>
>                         'no_defs'
>
>                         ''
>
>                END
>
>                CLASS
>
>                  STYLE
>
>                   COLOR 0 0 0
>
>                  END
>
>                  LABEL
>
>                   COLOR 0 0 0
>
>                   SIZE SMALL
>
>                  END
>
>                   
>
>                END
>
>               
>
>  
>
>   END
>
>  
>
>   LAYER
>
>  
>
>                NAME "250"
>
>                METADATA
>
>                  'wms_title' "wms_demo"
>
>                END
>
>                STATUS DEFAULT
>
>                TYPE raster
>
>                TILEINDEX "250K"
>
>                TILEITEM "Location"
>
>                PROJECTION
>
>                         'proj=longlat'
>
>                         'ellps=WGS84'
>
>                         'datum=WGS84'
>
>                         'no_defs'
>
>                         ''
>
>                END
>
>                CLASS
>
>                  STYLE
>
>                   COLOR 0 0 0
>
>                  END
>
>                  LABEL
>
>                   COLOR 0 0 0
>
>                   SIZE SMALL
>
>                  END
>
>                   
>
>                END
>
>               
>
>  
>
>   END
>
>  
>
>  
>
>  
>
> END
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list