Using GeoServer(2.13) and Leaflet with jQuery, I’ve tried countless variations for the following code snippet:
function getJson(data) {
console.log(data)
geojsonLayer.addData(data);
}
$.ajax({
url : “http://geoserver.capecodgis.com/geoserver/capecodgis/ows? service=WFS&version=1.0.0&request=GetFeature&typeName=capecodgis:tracts_2010_4326&maxFeatures=2&outputFormat=json&format_options=callback:getJson”,
dataType : ‘jsonp’
//jsonp: false,
//jsonp : “format_options”,
//jsonpCallback : “callback:loadThis”,
//type : “GET”,
});
here is the error I recieve: ReferenceError: getJson is not defined
http://geoserver.capecodgis.com/geoserver/capecodgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=capecodgis:tracts_2010_4326&maxFeatures=2&outputFormat=json&format_options=callback:getJson&callback=jQuery183028543826857255483_1358619277402&_=1358619277746
Line 1
but it seems unable to send the data to the function getJson(). The json I request shows up when viewed in Firebug. I’ve read the GeoServer docs and a few examples on gis.stackexchange but I just can’t get any further. Any help would be greatly appreciated. Here is the live site I’m working with http://leaflettest.capecodgis.com/
thanks in advance,
Michael
Have you hidden your ‘getJson’ function from global scope, by defining it inside of another function?
···
On Sat, Jan 19, 2013 at 1:27 PM, Michael Savarese <geomajor56@anonymised.com> wrote:
Using GeoServer(2.13) and Leaflet with jQuery, I’ve tried countless variations for the following code snippet:
function getJson(data) {
console.log(data)
geojsonLayer.addData(data);
}
$.ajax({
url : “http://geoserver.capecodgis.com/geoserver/capecodgis/ows? service=WFS&version=1.0.0&request=GetFeature&typeName=capecodgis:tracts_2010_4326&maxFeatures=2&outputFormat=json&format_options=callback:getJson”,
dataType : ‘jsonp’
//jsonp: false,
//jsonp : “format_options”,
//jsonpCallback : “callback:loadThis”,
//type : “GET”,
});
here is the error I recieve: ReferenceError: getJson is not defined
http://geoserver.capecodgis.com/geoserver/capecodgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=capecodgis:tracts_2010_4326&maxFeatures=2&outputFormat=json&format_options=callback:getJson&callback=jQuery183028543826857255483_1358619277402&_=1358619277746
Line 1
but it seems unable to send the data to the function getJson(). The json I request shows up when viewed in Firebug. I’ve read the GeoServer docs and a few examples on gis.stackexchange but I just can’t get any further. Any help would be greatly appreciated. Here is the live site I’m working with http://leaflettest.capecodgis.com/
thanks in advance,
Michael
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only – learn more at:
http://p.sf.net/sfu/learnmore_122912
Geoserver-users mailing list
Geoserver-users@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users
David, thanks for the reply, I guess you could say it was hidden. I posted this question on gis.stackexchange and received a working solution. The .ajax() call used the “success:” setting to call on the needed function. I’m obviously new to JavaScript, especially anything ajax. I’ve got it working but my method of creating the url seems a bit crude. Is there a more efficient method than the following:
rootUrl = “http://geoserver.capecodgis.com/geoserver/capecodgis/ows?service=WFS&version=1.0.0&request=GetFeature&
typeName=capecodgis:cape_parcels_4326”;
thisBbox = ‘&bbox=’ + map.getBounds().toBBoxString();
maxFeatures = “&maxFeatures=300”
theRest = “&outputFormat=json&format_options=callback:getJson”
thisUrl = rootUrl + thisBbox + maxFeatures + theRest
$.ajax({
url : thisUrl,
dataType : ‘jsonp’,
jsonpCallback : ‘getJson’,
success : handleJson,
});
···
On Sat, Jan 19, 2013 at 1:27 PM, Michael Savarese <geomajor56@anonymised.com> wrote:
Using GeoServer(2.13) and Leaflet with jQuery, I’ve tried countless variations for the following code snippet:
function getJson(data) {
console.log(data)
geojsonLayer.addData(data);
}
$.ajax({
url : “http://geoserver.capecodgis.com/geoserver/capecodgis/ows? service=WFS&version=1.0.0&request=GetFeature&typeName=capecodgis:tracts_2010_4326&maxFeatures=2&outputFormat=json&format_options=callback:getJson”,
dataType : ‘jsonp’
//jsonp: false,
//jsonp : “format_options”,
//jsonpCallback : “callback:loadThis”,
//type : “GET”,
});
here is the error I recieve: ReferenceError: getJson is not defined
http://geoserver.capecodgis.com/geoserver/capecodgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=capecodgis:tracts_2010_4326&maxFeatures=2&outputFormat=json&format_options=callback:getJson&callback=jQuery183028543826857255483_1358619277402&_=1358619277746
Line 1
but it seems unable to send the data to the function getJson(). The json I request shows up when viewed in Firebug. I’ve read the GeoServer docs and a few examples on gis.stackexchange but I just can’t get any further. Any help would be greatly appreciated. Here is the live site I’m working with http://leaflettest.capecodgis.com/
thanks in advance,
Michael
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only – learn more at:
http://p.sf.net/sfu/learnmore_122912
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users