来自数据库的多个wfs;更改网址

时间:2015-12-10 15:58:52

标签: php openlayers-3

我需要在地图中显示多个wfs功能。请求的网址为http://localhost/pdan/map.php?id=150这就是我所做的:

var id = <?php echo $_REQUEST['id']; ?>;
function getVector(obj) {
    var url = "";
    var geojsonFormat = new ol.format.GeoJSON();
    var vectorSource = new ol.source.Vector({
        loader: function(extent, resolution, projection) {
            var url = 'http:192.168.0.101:8082/geoserver/pdan/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=pdan:' + obj.data_set_name + '&' +
                'outputFormat=text/javascript&format_options=callback:loadFeatures' +
                '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';
            $.ajax({url: url, dataType: 'jsonp', jsonp: false, cache:false});
        },
        strategy: ol.loadingstrategy.bbox
    });
    window.loadFeatures = function(response) {
        vectorSource.addFeatures(geojsonFormat.readFeatures(response));
    };
    return 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
            })
        })
    });
}

function getObject(id) {
    var result;
    $.ajax({
        url: "dbQueries.php",
        async: false,
        cache: false,
        dataType: "JSON",
        data: {'query': 110, 'id': id},
        success: function (data) {
            result = data;
        }
    });
    return result;
}
var vector = [];
var rowObject = getObject(id);
var size = Object.size(rowObject);
//Prepare vector Layer
if (size != 0) {
    for (var i = 0; i < size; i++) {
        vector[i] = getVector(rowObject[i]);
    }
}

//Now Initialise map
var map = createMap();
var graticule = getGraticule();
graticule.setMap(map);

//Add vector to the map
if (size != 0) {
    for (var i=0; i<size; i++) {
        map.addLayer(vector[i]);
    }

}

对我来说一切似乎都很好但是网址被更改了,在控制台中我得到错误:

GET 
http://localhost/pdan/192.168.0.101:8082/geoserver/pdan/ows [HTTP/1.1 403 Forbidden 3ms]

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

问题出在我要求的网址上。它应该是

var url = 'http://192.168.0.101:8082/geoserver/pdan/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=pdan:' + obj.data_set_name + '&' +
                'outputFormat=text/javascript&format_options=callback:loadFeatures' +
                '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';

而不是

var url = 'http:192.168.0.101:8082/geoserver/pdan/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=pdan:' + obj.data_set_name + '&' +
                'outputFormat=text/javascript&format_options=callback:loadFeatures' +
                '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';