来自USGS geojson数据的jqGrid [英] jqGrid from USGS geojson data
问题描述
我正在尝试在jqGrid中读取和发布从USGS存储库提取的一组地震GeoJSON数据. 该请求已被接受,但是在可能满足标头元数据的情况下显示"Uncaught SyntaxError:Unexpected token".
I'm trying to read and post in a jqGrid a set of earthquakes GeoJSON data extracted from USGS repository. The request is accepted, but displays "Uncaught SyntaxError: Unexpected token" when probably meets the header metadata.
$(function () {
'use strict';
$.extend($.jgrid.search, {multipleSearch: true, multipleGroup: true, overlay: 0});
$('#grid').jqGrid({
url: 'http://earthquake.usgs.gov/earthquakes/feed/geojson/2.5/week?callback=?',
datatype: 'json',
colModel: [
{name: 'mag', label: 'MAGNITUDO', width: 150, jsonmap: 'properties.mag', sorttype: 'number',
formatter: 'number', formatoptions: {decimalPlaces: 2}},
{name: 'place', label: 'LOCALITA', width: 150, jsonmap: 'properties.place'},
{name: 'url', label: 'URL', width: 150, jsonmap: 'properties.url'}
],
toppager: true,
gridview: true,
rowList: [10, 20, 50, 10000],
rowNum: 10,
jsonReader: {
root: 'features',
repeatitems: false
},
loadonce: true,
ignoreCase: true,
height: 'auto'
}).jqGrid('navGrid', '#grid_toppager', {add: false, edit: false, del: false})
.jqGrid('filterToolbar', {stringResult: true, defaultSearch: 'cn', searchOnEnter: false});
$("#grid_toppager option[value=10000]").text('All');
});
您有什么解决方案吗? 预先感谢.
Do you have any solution? Thanks in advance.
推荐答案
我查看了geojson的文档,并认为找到了问题的原因.似乎GeoJSON(P)使用eqfeed_callback
作为回调名称(请参见此处).因此,我修复了您以前使用过的jqGrid的一些选项:
I looked in the documentation of geojson and I think I found the reason of the problem. It seems that GeoJSON(P) uses eqfeed_callback
as callback name (see here). So I fixed some options of jqGrid which you used to the following:
url: 'http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week',
datatype: 'jsonp',
postData: '',
ajaxGridOptions: { jsonp: false, jsonpCallback: 'eqfeed_callback', cache: true},
修改后的演示现在可以正常工作并显示如下结果
The modified demo works now and display the results like below
更新:修改后的演示使用GeoJSON的新URL和免费jqGrid 的新版本(4.14.1).
UPDATE: The modified demo uses new URLs of GeoJSON and new version (4.14.1) of free jqGrid.
这篇关于来自USGS geojson数据的jqGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!