为什么这个WMS层没有出现在openlayers中?

时间:2021-01-13 04:10:14

I am trying to show a WMS layer from a published ArcGIS Map Service and all I am getting is pink tiles. Can anyone help correct me on what is wrong with my code? When I pan over to the US, all I am getting are "broken image pink tiles"... There is no WMS layer that appears whatsoever.

我正在尝试展示一个发布的ArcGIS地图服务的WMS层,我得到的只是粉红色的瓷砖。有人能帮我纠正我的代码出了什么问题吗?当我去美国的时候,我得到的只是“破碎的图像粉色瓷砖”……没有出现任何WMS层。

<html>
<head>
    <title>Karta</title>
    <link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script  type="text/javascript">
    function inicializacija(){
        var options = {
            projection: new OpenLayers.Projection("EPSG:4326"),
            units: "m",
            numZoomLevels: 18,
            maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
            };
         var map = new OpenLayers.Map("map-id", options);
         //var osm = new OpenLayers.Layer.OSM("Open Street Map");
         //var wms = new OpenLayers.Layer.MapServer( "World Map", "http://localhost/cgi-bin/mapserv.exe", {layers: 'countries',map: '/ms4w/Apache/htdocs/MapFile06_wms.map', srs: 'EPSG:4326'} );

        //map.addLayers([osm,wms]);

        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?request=GetCapabilities&service=WMS", {layers: "States"} );
        map.addLayer(layer);

        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.addControl(new OpenLayers.Control.MousePosition());


        map.zoomToExtent(new OpenLayers.Bounds(1490000, 5600000,1850000, 5900000));
    }
</script>
    <style>
        #map-id {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body onload= 'inicializacija()'>
    <h1>Primer prekrivanja slojev in izbire podlag</h1>
    <div id="map-id"></div>
</body>
</html>

1 个解决方案

#1


6  

The images show up red because the request didn't result in a valid map image.

图像显示为红色,因为请求没有生成有效的地图图像。

This is how you debug such a problem:

这就是调试这样一个问题的方法:

  • Open the page in FireFox or Chrome.
  • 在FireFox或Chrome中打开页面。
  • Then save one of the red images to disk.
  • 然后将其中一个红色图像保存到磁盘。
  • Open the saved file in a text editor.
  • 在文本编辑器中打开保存的文件。

Now, it looks like you are not requesting images, but you are requesting the capabilities of the server.

现在,看起来您不是在请求映像,而是在请求服务器的功能。

You've probably pasted the server URL into your code, but you've pasted the URL that requests what the server can do, and what it supports.

您可能已经将服务器URL粘贴到代码中,但是您已经粘贴了请求服务器可以做什么以及它支持什么的URL。

So, just remove this part from the URL: request=GetCapabilities

因此,只需从URL: request= getcapability中删除这一部分

So that it becomes: http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?service=WMS

因此它变成:http://sampleserver1. arcgisonline.com/arcgis/services/specialty/esri_statescitiesrivers_usa/mapserver/wmsserver?

Save the HTML, and refresh.

保存HTML并刷新。

Ok, we're now actually requesting images, but you're still not getting anything.

我们现在实际上是在请求图像,但是你仍然得不到任何东西。

So, do the same. Save one of the red images, and see what's inside.

所以,做同样的事情。保存一个红色图像,看看里面是什么。

This time there's an error message inside:

这一次里面有一个错误信息:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd">
<ServiceExceptionReport version="1.1.1">
  <ServiceException code="LayerNotDefined">
Parameter 'layer(s)' contains unacceptable value: States
  </ServiceException>
</ServiceExceptionReport>

Looks like you're requesting a layer called States, but that layer does not exist.

看起来您正在请求一个称为状态的层,但是这个层不存在。

Just provide a valid layer and you should be done. It looks like there are 2 layers on the server, called "1" and "2". When you set that as the layer, the red images are gone, but they don't seem to contain anything interesting, but that's yet another problem that i cannot help you with, unless I get more information.

只要提供一个有效的层就可以了。看起来服务器上有两个层,分别叫做“1”和“2”。当你将它设置为图层时,红色的图像就消失了,但是它们似乎没有包含任何有趣的东西,但是这是另一个我无法帮助你的问题,除非我得到更多的信息。

#1


6  

The images show up red because the request didn't result in a valid map image.

图像显示为红色,因为请求没有生成有效的地图图像。

This is how you debug such a problem:

这就是调试这样一个问题的方法:

  • Open the page in FireFox or Chrome.
  • 在FireFox或Chrome中打开页面。
  • Then save one of the red images to disk.
  • 然后将其中一个红色图像保存到磁盘。
  • Open the saved file in a text editor.
  • 在文本编辑器中打开保存的文件。

Now, it looks like you are not requesting images, but you are requesting the capabilities of the server.

现在,看起来您不是在请求映像,而是在请求服务器的功能。

You've probably pasted the server URL into your code, but you've pasted the URL that requests what the server can do, and what it supports.

您可能已经将服务器URL粘贴到代码中,但是您已经粘贴了请求服务器可以做什么以及它支持什么的URL。

So, just remove this part from the URL: request=GetCapabilities

因此,只需从URL: request= getcapability中删除这一部分

So that it becomes: http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?service=WMS

因此它变成:http://sampleserver1. arcgisonline.com/arcgis/services/specialty/esri_statescitiesrivers_usa/mapserver/wmsserver?

Save the HTML, and refresh.

保存HTML并刷新。

Ok, we're now actually requesting images, but you're still not getting anything.

我们现在实际上是在请求图像,但是你仍然得不到任何东西。

So, do the same. Save one of the red images, and see what's inside.

所以,做同样的事情。保存一个红色图像,看看里面是什么。

This time there's an error message inside:

这一次里面有一个错误信息:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd">
<ServiceExceptionReport version="1.1.1">
  <ServiceException code="LayerNotDefined">
Parameter 'layer(s)' contains unacceptable value: States
  </ServiceException>
</ServiceExceptionReport>

Looks like you're requesting a layer called States, but that layer does not exist.

看起来您正在请求一个称为状态的层,但是这个层不存在。

Just provide a valid layer and you should be done. It looks like there are 2 layers on the server, called "1" and "2". When you set that as the layer, the red images are gone, but they don't seem to contain anything interesting, but that's yet another problem that i cannot help you with, unless I get more information.

只要提供一个有效的层就可以了。看起来服务器上有两个层,分别叫做“1”和“2”。当你将它设置为图层时,红色的图像就消失了,但是它们似乎没有包含任何有趣的东西,但是这是另一个我无法帮助你的问题,除非我得到更多的信息。