在JS / JQuery上过滤大型Json文件

时间:2014-03-15 09:36:00

标签: javascript jquery json leaflet

我有大型的json文件,我正在努力将其绘制在地图上。我无法加载文件,这就是我每次放大或移动地图时都要请求数据的原因

文件是

 var data3d = {
        "type": "FeatureCollection",
        "features": [{
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[
                    [13.37356, 52.52064],
                    [13.37350, 52.51971],
                    [13.37664, 52.51973],
                    [13.37594, 52.52062],
                    [13.37356, 52.52064]
                ]]
            },
            "properties": {
                "wallColor": "rgb(255,0,0)",
                "height": 500
            }
        },{
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [[
                    [13.37356, 52.52064],
                    [13.37350, 52.51971],
                    [13.37664, 52.51973],
                    [13.37594, 52.52062],
                    [13.37356, 52.52064]
                ]]
            },
            "properties": {
                "wallColor": "rgb(255,0,0)",
                "height": 500
            }
        }]
    };

我想构建一个过滤我需要绘制数据的函数

function onMapMove(e) { requestData(); }

然后我应该以这种方式构建一个函数。

function requestData() {
  var bounds=map.getBounds(); // I get these values from the browser
  var minLongitudeLat=bounds.getSouthWest(); //minimum Longitude Latitude
  var maxLongitudeLat=bounds.getNorthEast(); //maximum Longitude Latitude

// Here what I should to select data between 
['+minLongitudeLat.lat+','+minLongitudeLat.lng+'],['+maxLongitudeLat.lat+','+maxLongitudeLat.lng+'];

}

我应该编写JQuery PostJson函数。

    jQuery.postJSON(link,
   function(data){
     return //
        });

更新:(答案评论) 我正在尝试构建ajax调用, thisFile.json是包含上述数据3内容的文件

    $.ajax({
            url: 'thisFile.json',
            data: 'GET',
            dataType: 'json',

            success: function(data){
                filteredData=[]
                 for (var i = data.features.length - 1; i >= 0; i--) {     
                if((data.features[i].["geometry"]["coordinates"][0][0]>minLongitudeLat.lat && 
                   data.features[i].["geometry"]["coordinates"][0][1] <minLongitudeLat.lng ) &&
                   (data.features[i].["geometry"]["coordinates"][0][0] > maxLongitudeLat.lat &&
                   data.features[i].["geometry"]["coordinates"][0][1]< maxLongitudeLat.lng)) {filteredData.append(filteredData) }
return filteredData;
          }; 
            },
        });

或者我应该编写python脚本来进行过滤

PythonScript.py,但是如何获取和发布数据?

import json
print "Content-type: application/json"
// Should I read here the whole data 

// local_file = open("/tmp/download_file.json", "w") 

// How to pass parameters to filter json file ?

print json.dumps()


 $.getJSON("/PythonScript.py ", function(data) {
        // Here we get data
    });

0 个答案:

没有答案