当前位置: 代码迷 >> GIS >> wfs例子上的有关问题
  详细解决方案

wfs例子上的有关问题

热度:1196   发布时间:2016-05-05 06:41:39.0
wfs例子上的问题
在 http://openlayers.org/dev/examples/wfs-states.html (官网例子)中可用看到橙黄色的美国States图层覆盖在上面,我把openlayers官网里的 wfs美国领土states例子下到自己的电脑上,当然是html和js文件都下了,但是在自己的机子上却只能看见底图(http://labs.metacarta.com/wms-c/Basic.py 的basic图层)。

下面是两段源码:
wfs-states.js代码:
var map;
OpenLayers.ProxyHost = "proxy.cgi?url=";

function init() {
  map = new OpenLayers.Map("map");

  var base = new OpenLayers.Layer.WMS("OpenLayers WMS",
  "http://labs.metacarta.com/wms-c/Basic.py",
  {layers: "basic"} 
  );
  map.addLayer(base);

  var wfs = new OpenLayers.Layer.Vector("States", {
  strategies: [new OpenLayers.Strategy.BBOX()],
  protocol: new OpenLayers.Protocol.WFS({
  url: "http://demo.opengeo.org/geoserver/wfs",
  featureType: "states",
  featureNS: "http://www.openplans.org/topp"
  })
  });
  map.addLayer(wfs);

  map.zoomToExtent(new OpenLayers.Bounds(-140.4, 25.1, -44.4, 50.5));
}

wfs-states.html代码:
<html>
  <head>
  <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <title>WFS: United States (GeoServer)</title>
  <script src="../OpenLayers.js"></script>
  <script src="wfs-states.js"></script>
  </head>

  <body onload="init()">
  <h1 id="title">WFS United States (GeoServer) Example</h1>
  <div id="tags"></div>
  <p id="shortdesc">
  Shows the use of the WFS United States (GeoServer). 
  </p>
  <div id="map" class="smallmap"></div>
  <div id="docs">
  <p>

  This example shows the basic use of a vector layer with the
  WFS protocol.
  </p>
  <p>
  See the <a href="wfs-states.js" target="_blank">wfs-states.js
  source</a> to see how this is done.
  </p> 
  </div>
  </body>
</html>

文件放置的目录应该是没错的……大家有遇见这种情况的吗?
本地显示[/align]

------解决方案--------------------
javascript有cross domain security限制,你没有配置跨域访问,就无法通过js代码用wfs查询的方式访问远程服务器的地图属性信息。
  相关解决方案