WFS 图层不显示
WFS Layer Not Display
我从 GeoServer 创建了 WFS GeoJson 层,我得到了这个 url'http://localhost:8080/geoserver/trail/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=trail:sbi_branch_data&maxFeatures=50&outputFormat=application%2Fjson',我从 OL3 示例中得到了示例代码,我在 OpenLayer3 中尝试了一些代码,但给出了一些 error.please 帮帮我。谢谢。
<!DOCTYPE html>
<html>
<head>
<title>WFS</title>
<!-- <link rel="stylesheet" href="https://openlayers.org/en/v4.1.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<!-- <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.1.0/build/ol.js"></script>-->
<link rel="stylesheet" href="css/ol.css" type="text/css" />
<link rel="stylesheet" href="css/sample.css" type="text/css" />
</head>
<body>
<div id="map" class="map"></div>
<script src="js/ol.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:8080/geoserver/trail/ows?service=WFS&'+
'version=1.0.0&request=GetFeature&typeName=trail:sbi_branch_data&'+
'maxFeatures=50&outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var raster = new ol.layer.Tile({
// source: new ol.source.BingMaps({
// imagerySet: 'Aerial',
// key: 'Your Bing Maps Key from http://www.bingmapsportal.com/ here'
// })
});
var map = new ol.Map({
layers: [raster, vector],
target: document.getElementById('map'),
view: new ol.View({
center: [20.5937, 78.9629],
maxZoom: 19,
zoom: 12
})
});
</script>
</body>
</html>
错误:
"XMLHttpRequest cannot load http://localhost:8080/geoserver/trail/ows?service=WFS&version=1.0.0&request…644126996,-13297.517049905844,22569.517044127,13455.442849905845,EPSG:4326. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."
我得到了解决方案,首先我安装了 Apache 然后修改 httpd.config file.I 只是把
ProxyRequests Off
ProxyPreserveHost On
<Proxy /geoserver>
Require all granted
</Proxy>
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver
此代码位于文件末尾 httpd.config 中。
然后从 httpd.config
启用它
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
然后我存储在 Apache 的 ht-docs 中的所有 html 文件,然后运行所有 wfs 文件。
我从 GeoServer 创建了 WFS GeoJson 层,我得到了这个 url'http://localhost:8080/geoserver/trail/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=trail:sbi_branch_data&maxFeatures=50&outputFormat=application%2Fjson',我从 OL3 示例中得到了示例代码,我在 OpenLayer3 中尝试了一些代码,但给出了一些 error.please 帮帮我。谢谢。
<!DOCTYPE html>
<html>
<head>
<title>WFS</title>
<!-- <link rel="stylesheet" href="https://openlayers.org/en/v4.1.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<!-- <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.1.0/build/ol.js"></script>-->
<link rel="stylesheet" href="css/ol.css" type="text/css" />
<link rel="stylesheet" href="css/sample.css" type="text/css" />
</head>
<body>
<div id="map" class="map"></div>
<script src="js/ol.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:8080/geoserver/trail/ows?service=WFS&'+
'version=1.0.0&request=GetFeature&typeName=trail:sbi_branch_data&'+
'maxFeatures=50&outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var raster = new ol.layer.Tile({
// source: new ol.source.BingMaps({
// imagerySet: 'Aerial',
// key: 'Your Bing Maps Key from http://www.bingmapsportal.com/ here'
// })
});
var map = new ol.Map({
layers: [raster, vector],
target: document.getElementById('map'),
view: new ol.View({
center: [20.5937, 78.9629],
maxZoom: 19,
zoom: 12
})
});
</script>
</body>
</html>
错误: "XMLHttpRequest cannot load http://localhost:8080/geoserver/trail/ows?service=WFS&version=1.0.0&request…644126996,-13297.517049905844,22569.517044127,13455.442849905845,EPSG:4326. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."
我得到了解决方案,首先我安装了 Apache 然后修改 httpd.config file.I 只是把
ProxyRequests Off
ProxyPreserveHost On
<Proxy /geoserver>
Require all granted
</Proxy>
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver
ProxyPass /geoserver http://localhost:8080/geoserver
ProxyPassReverse /geoserver http://localhost:8080/geoserver
此代码位于文件末尾 httpd.config 中。 然后从 httpd.config
启用它LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
然后我存储在 Apache 的 ht-docs 中的所有 html 文件,然后运行所有 wfs 文件。