OpenLayers:约束地图范围并适合div

时间:2013-10-01 21:09:33

标签: html openlayers

我需要显示世界扩展名为-18,-90,180,90的地图。 我希望初始视图上的地图适合div。 我尝试按比例定义div与地图范围,但它不起作用:地图在lon = -180°之前和lon = 180°之后显示矢量。

我尝试在地图中定义maxExtent和restrictedExtent,但它不起作用(见图)。如何强制地图适应restrictedExtent和div(或者什么是正确的div维度)? The map extent is larger than restrictedExtent

源代码:

<!DOCTYPE html>
<html>
   <head>
     <title></title>
     <link rel="stylesheet" href="http://myip/geoserver/openlayers/theme/default/style.css" type="text/css">
      <style>
     #map-id {width: 800px;
              height: 400px;}
   </style>

   <script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
<body>

  <div id="map-id"></div>

    <script>
      var extent = new OpenLayers.Bounds(-180,-90,180,90);
      var options = {restrictedExtent:extent, maxExtent:extent};

      var map = new OpenLayers.Map("map-id", options);
      var imagery = new OpenLayers.Layer.WMS(
          "Global Imagery",
          "http://maps.opengeo.org/geowebcache/service/wms",
           {layers: "bluemarble", isBaseLayer:false},
           {maxExtent:extent, mapResolution:'auto'}
            );

       var lmes=new OpenLayers.Layer.WMS(
            "LMEs",
            "http://myip/geoserver/ocean/wms",
            {layers:'ocean:LME66', transparent:true, styles:'LMES_colors'},
            {isBaseLayer:false, opacity:1, singleTile:true, visibility:true, maxExtent:extent, mapResolution:'auto'}
        );
        map.addLayers([lmes, imagery]);
        map.zoomToMaxExtent();       
        map.addControl(info);

        </script>

0 个答案:

没有答案