Hi Matt, Hi Leaflet community
Thanks for the link to the code. I tried, but the gejson does not load. I get a 404 error, when I check the url in the java script console of chrome.
Maybe you or sombody else can give me a hint? The WFS is working, a get capabilites request answers delivering the geojson objects:
http://81.20.139.28:8080/geoserver/Potsdam/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Potsdam:BV_web&maxFeatures=50&outputFormat=application/jsonHere you can check the url:
http://www.schernthanner.de/wfs_leaflet_test.htmlAny help is appreciated!!! Thanks!
This is my code:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Layers Control Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="http://schernthanner.de/leaflet-0.7.2/leaflet.css" />
<style>
#map {
width: 800px;
height: 500px;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
.legend {
text-align: left;
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="http://schernthanner.de/leaflet-0.7.2/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
var map = L.map('map').setView([52.41, 13.077], 15);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-20v6611k'
}).addTo(map);
var owsrootUrl = 'http://81.20.139.28:8080/geoserver/web/ows';
var defaultParameters = {
service : 'WFS',
version : '1.0.0',
request : 'GetFeature',
typeName : '<Potsdam:BV_web>',
outputFormat : 'text/javascript',
format_options : 'callback:getJson',
SrsName : 'EPSG:3857'
};
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: false,
fillColor: 'FFFFFF',
fillOpacity: 0
};
},
onEachFeature: function (feature, layer) {
popupOptions = {maxWidth: 200};
layer.bindPopup("Popup text, access attributes with feature.properties.ATTRIBUTE_NAME"
,popupOptions);
}
}).addTo(map);
}
});
</script>
</body>
</html>