GeoJSON文件制作传单API使网站速度变慢

时间:2018-12-03 18:38:20

标签: javascript jquery ajax leaflet geojson

我正在尝试使用传单API来显示有关全球珊瑚礁位置的数据。我最初下载了shapefile(.shp),然后使用QGIS将其转换为GeoJSON。我将数据放在项目文件夹中,但是当我尝试通过Ajax请求在传单上显示此数据时,浏览器花费了很长时间加载并最终返回了无响应的消息。但是,我可以看到标记会出现在地图上,尽管速度很慢。是否可以创建较小的文件或更有效地加载数据,从而不会使整个站点无法使用?

我的Ajax请求看起来像这样:

$.ajax({
        type: 'GET',
        url: './coldwater.geojson',
        dataType: 'json',
        data: data,
        success: function (data) {
            L.geoJSON(data).addTo(mymap);
        }, error: function(){
            console.log('Couldn\'t load data');
        }
    });

这是geoJSON的代码段

{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -75.116700000304718, 18.283300000094982 ], [ -75.116699858211859, 18.283301156623111 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -34.850000000399632, 9.01670000040474 ], [ -34.849996660317572, 9.016695959750791 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -34.850000000399632, 9.01670000040474 ], [ -34.849996660317572, 9.016695959750791 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -81.166699999905006, 23.983300000394763 ], [ -81.166699953140267, 23.983303104854429 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -79.549997733808311, 26.649999766076405 ], [ -79.416700222836994, 27.166696245435446 ], [ -79.416700222836994, 27.283302340130945 ], [ -79.416699999805132, 27.283300000094982 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -78.683303107752181, 27.416698775628049 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -79.216699996607531, 24.099999131754601 ], [ -78.850001440414133, 26.516702255105031 ], [ -78.39999868309269, 26.583297050818317 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -77.083301298815854, 25.166702977260627 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -79.233301481578053, 27.216698550297906 ], [ -79.216699996607531, 27.300002749627254 ] ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPoint", "coordinates": [ [ -79.549997733808311, 26.649999766076405 ], [ -79.416700222836994, 27.166696245435446 ], [ -79.416699999805132, 27.166700000104981 ], [ -79.366697917974477, 27.533295877103114 ] ] } },

使用Google Maps API会更好吗? 还是有更好的方法将shapefile插入传单地图中?

ps:如果这不合适或不在主题之列,请告诉我。我是刚开始在stackoverflow上发帖的人

0 个答案:

没有答案