TransWikia.com

WFS Leaflet script not working

Geographic Information Systems Asked on July 5, 2021

This opens just fine in the browser and the server seems to respond positively to the WFS request, but nothing loads. Can someone help me out here?

<html>
<head><title>LeafletTest</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-
0.7.3/leaflet.css"/>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js">
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<meta http-equiv="Access-Control-Allow-Origin" content="*">
</head>
<body>
<div id="map" style="width: 1000px; height: 700px"></div>
<script>
var map = L.map('map').setView([64.10418, -20.62987],7);

var owsrootUrl = 'http://130.239.124.215:8080/geoserver/geonode/ows';

var defaultParameters = {
    service : 'WFS',
    version : '1.0',
    request : 'GetFeature',
    typeName : 'geonode:Isleif2015-1>',
    outputFormat : 'text/javascript',
    format_options : 'callback:getJson',
    SrsName : 'EPSG:3057'
};

var parameters = L.Util.extend(defaultParameters);
var URL = owsrootUrl + L.Util.getParamString(parameters);

var WFSLayer = null;
var ajax = $.ajax({
    url : URL,
    dataType : 'jsonp',
    jsonpCallback : 'getJson',
    success : function (response) {
        WFSLayer = L.geoJson(response, {
            style: function (feature) {
                return {
                    stroke: true,
                    fillColor: '#FF0000',
                    fillOpacity: 0
                };
            },
            onEachFeature: function (feature, layer) {
                popupOptions = {maxWidth: 200};
                layer.bindPopup("Popup text, access attributes with feature.properties.ATTRIBUTE_NAME"
                    ,popupOptions);
            }
        }).addTo(map);
    }
});

var mywms = L.tileLayer.wms("http://gis.lmi.is/geoserver/LMI_raster/wms", {
    layers: 'LMI_raster:atlas',
    format: 'image/png',
    transparent: true,
    version: '1.1.0',
    attribution: "<a href='http://gatt.lmi.is'>LMI</a>"
});
mywms.addTo(map);

var overlays = {
    "Isleif2015-1": points,

    };
var layerControl = L.control.layers(null, overlays);
map.addControl(layerControl);

</script>
</body>
</html>

One Answer

If you have a look at the GetCapabilities-Response of your Geoserver you will recognize that there is no layer listet. So either you have no layers published or you don't advertise them to the Capabilities-document and the Layer-Preview:

http://130.239.124.215:8080/geoserver/geonode/ows?Service=WFS&Request=GetCapabilities

http://130.239.124.215:8080/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.demo.MapPreviewPage

So it's hard to say if this layer "geonode:Isleif2015-1>" really exists. As in your other question (WFS request works in Geoserver but server returns error) here also seems to be an unneccessary character ">" in the layername.

Having a look at the Geoserver instance of your other question I saw that there exists a Layer "Isleif2015-1", so perhaps you mixed up your Geoservers?

This one works:

var owsrootUrl = 'http://130.239.57.16:8080/geoserver/ows';

var defaultParameters = {
    service : 'WFS',
    version : '1.0',
    request : 'GetFeature',
    typeName : 'Survey:Isleif2015-1',
    outputFormat : 'text/javascript',
    format_options : 'callback:getJson',
    SrsName : 'EPSG:4326',
    MaxFeatures: 200
};

http://jsfiddle.net/fss5x8sa/

Correct answer by Thomas B on July 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP