使用来自OpenLayers 3站点的WFS示例作为基础,无法加载另一个WFS

时间:2016-02-15 12:33:28

标签: javascript openlayers-3

我是OpenLayers3的首发,我是这个网站的新手,所以这是我的第一个问题,希望我在这里正确删除它。对我来说不起作用的是在OpenLayers3中打开一个(不是平铺的?)WFS图层。我使用开放图层站点的WFS示例作为基础(也因为它似乎是一个相对简单的代码)。我试图在我的教科书OpenLayers3中找到解决方案,在开放图层的网站上,谷歌和在这个网站上但没有成功。 在我用OpenLayers的例子做的代码之下,但是现在又用于另一个WFS,因为我认为它应该是打开这个WFS。我做错了什么?

 // working example from: http://openlayers.org/en/v3.13.1/examples/vector-wfs.html

  var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: function(extent) {
      return 'http://demo.boundlessgeo.com/geoserver/wfs?service=WFS&' +
          'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
          'outputFormat=application/json&srsname=EPSG:3857&' +
          'bbox=' + extent.join(',') + ',EPSG:3857'; 
        },
    strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
      maxZoom: 19
    }))
  });  


  var vector1 = new ol.layer.Vector({
    source: vectorSource,
    style: new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: 'rgba(0, 255, 255, 1.0)',
        width: 2
      })
    })
  });  

//基于上面示例代码的无效代码

var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: function(extent) {
      return 'https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?service=WFS&' +
          'version=1.1.0&request=GetFeature&typename=bestuurlijkegrenzen:gemeenten&' +
          'outputFormat=application/json&srsname=EPSG:28992&' +
          'bbox=' + extent.join(',') + ',EPSG:28992'; 

             },
    strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
      maxZoom: 19
    }))
  });


  var vector = new ol.layer.Vector({
    source: vectorSource,
    style: new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: 'rgba(0, 255, 255, 1.0)',
        width: 2
      })
    })
  });

1 个答案:

答案 0 :(得分:1)

除非您提供完整的代码,否则我只能做一些猜测。 你的两层有不同的投影。我猜您使用epsg:3857进行视图投影,因此使用此范围内的坐标将返回0个要素。首先要尝试的是使用视图的投影从地理服务器请求您的图层。

var vectorSource = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    url: function(extent) {
      return 'https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs?service=WFS&' +
          'version=1.1.0&request=GetFeature&typename=bestuurlijkegrenzen:gemeenten&' +
          'outputFormat=application/json&srsname=EPSG:3857&' +
          'bbox=' + extent.join(',') + ',EPSG:3857'; 

             },
    strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
      maxZoom: 19
    }))
  });

这将强制geoserver在服务器端进行重新投影。 我建议首先尝试以上内容,以确保这是你的情况。然后,您必须确定是否要在客户端或服务器端进行重新注入。