Skip to content

Instantly share code, notes, and snippets.

@capooti
Created November 25, 2015 15:56
Show Gist options
  • Save capooti/2e7fb9ed265ccf352185 to your computer and use it in GitHub Desktop.
Save capooti/2e7fb9ed265ccf352185 to your computer and use it in GitHub Desktop.
WorldMap sample jsonp request
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px;"></div>
<script type="text/javascript">
var map = new L.Map('map', {
zoom: 1,
center: new L.latLng([0,0]),
layers: L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
});
var owsrootUrl = 'http://worldmap.harvard.edu/geoserver/ows';
var defaultParameters = {
service: 'WFS',
version: '2.0',
request: 'GetFeature',
typeName: 'geonode:hotspots_jgm',
maxFeatures: 200,
outputFormat: 'text/javascript',
format_options: 'callback: getJson'
//srs: 'EPSG:4326'
};
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(
feature.properties.OBJECTID, popupOptions);
}
}).addTo(map);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment