1

我正在 WMS 上的普通 Openlayes 上进行地图项目。本地服务器是 Oracle Virtual Box 上的 Debian_x64,地图服务器是芬兰国家土地调查局。请求和投票示例可在此处获得http://www.maanmittauslaitos.fi/aineistot-palvelut/rajapintapalvelut/rasteriaineistojen-palvelurajapinta-wms/kayttoonotto/kyselyt-es。我已成功完成 GetCapabilities 请求并获得 XML 响应。基于该 XML 响应,我尝试使用 GetMap 获取地图图层。Map 参数是根据我现在得到的 XML 响应分配的,我遇到的问题是

  1. BoundingBox 上有参数“resx 和 resy”,我是否需要将它们用于我正在做的事情,如果需要,如何使用?
  2. 我在 Chrome 开发人员工具上监控了控制台,它响应以下错误:

Failed to load resource: the server responded with a status of 401 (Unauthorized) https://ws.nls.fi/rasteriaineistot/image?LAYERS=yleiskartta_12m&VERSION=1.1.1&FORMAT=image%2Fpng&REQUEST=GetMap&TRANSPARENT=FALSE&STYLES=light&SERVICE=WMS&SRS=EPSG%3A4326&BBOX=0,45,45,90&WIDTH=256&HEIGHT=256

...同时粉红色的瓷砖正在加载。我已经使用 Php cURL 代理“proxy.php”使用用户名和密码进行 HTTPS 基本身份验证,它与 Openlayers.js、style.css 和 index.php 位于同一文件夹中。现在我分配的代理是否可能无法正常工作?或者可能有一些相同的原产地政策问题?我的用户名和密码有效。我该如何解决这个问题?如果有人提供代码示例,那将非常有帮助。

我的 proxy.php 文件如下:

$string = $_GET['url'];
$urli = urldecode($string);
$url = $urli;

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD,"user:pass");
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
$type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);

$im = imagecreatefromstring($data);

if ($type == "image/jpeg") {
    header('Content-Type: image/jpeg');
    imagejpeg($im);
} else if ($type == "image/png") {
    header('Content-Type: image/png');
    imagepng($im);
} else if ($type == "image/gif") {
    header('Content-Type: image/gif');
    imagegif($im);
} else if ($type == "text/xml") {
    header('Content-Type: text/xml');
    print_r($data);
}

imagedestroy($im);
curl_close($ch);
exit;

and the index.php is as following
  function init() {
                    var map = new OpenLayers.Map('map',options)

                    var request = OpenLayers.Request.GET({
                                        url:"https://ws.nls.fi/rasteriaineistot/image?",

                                        params: {service:"WMS",
                                                 version:"1.1.1",
                                             format:"text/xml",
                                             request:"GetCapabilities"},
                                                 proxy: "queryboth.php?url=",
                                                 async: false,
                                                 callback: handler

                    } );


                    function handler(request) {
                                console.log(request);

                           // alert(request.responseText);
                           // alert(request.status);
                           // alert(request.getAllResponseHeaders());
                                         }

// Here I set my ProxyHost could it be some mistake here    
                 OpenLayers.ProxyHost = "proxy.php?url=";

                 var layer = new OpenLayers.Layer.WMS("yleiskartta",

                            "https://ws.nls.fi/rasteriaineistot/image?",
                            {
                                layers: "yleiskartta_12m",
                                version:"1.1.1",
                                format: "image/png",
                                request: "GetMap",
                                transparent: false,
                                styles:"light"  


                            },

                            {

                               isBaseLayer: true,
                               opacity: 1 

                            }

                    );

                      var options = { 
                      sphericalMercator: true,
                      projection: new OpenLayers.Projection("EPSG:3067"),
                      maxExtent: new OpenLayers.Bounds(-380688,6247443,1347312,8227443),
                                          minScale: 2121.32, 
                          maxScale: 8485.28,  
                      units: "m",
                                          numZoomLevels: 6

                      };


                  map.addLayers([layer]);
                  map.zoomToMaxExtent();
                                  map.addControl( new OpenLayers.Control.LayerSwitcher() );

            }

xml中一层的响应如下(对不起,我删除了标签):

Layer opaque="1"
Name:yleiskartta_12m
Title : Yleiskarttarasteri 1:12 milj
LatLonBoundingBox minx="1.21" miny="55.57" maxx="51.93" maxy="71.79"
BoundingBox SRS="EPSG:3067" minx="-380688" miny="6247443" maxx="1347312" maxy="8227443" resx="1500.0" resy="1500.0"
BoundingBox SRS="EPSG:2393" minx="2619125.63" miny="6250068.42" maxx="4347827.2" maxy="8147483.65" resx="1500.0" resy="1500.0" 
ScaleHint min="2121.32" max="8485.28"
</Layer>

</pre>
4

0 回答 0