2017-05-09 8 views
0

は私にGeoJSONの図である。取得にGeoJSONプロパティ

var point_layer_WGS84_dist = { 
"type": "FeatureCollection", 
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, 

"features": [ 
{ "type": "Feature", "properties": { "x": 7.6789651, "y": 48.5066953, "distCoupe": 10000, "path": "coupes_10000_14995\\PM_10000.png" }, "geometry": { "type": "Point", "coordinates": [ 7.6789651, 48.5066953 ] } }, 
{ "type": "Feature", "properties": { "x": 7.6788011, "y": 48.5063054, "distCoupe": 10045, "path": "coupes_10000_14995\\PM_10045.png" }, "geometry": { "type": "Point", "coordinates": [ 7.6788011, 48.5063054 ] } }, 

私はにGeoJSONファイルから情報を取得したい、私はHTML のようなpossibiltyがあると思っリンクされていること:

var feat = point_layer_WGS84_dist.getFeatureByPropertie("distCoupe",'10000') 
var imageLocation = feat.path 
は、

リーフレットにアクセスするにはどうしたらいいですか?

+0

を普通のJSオブジェクトと同じようにアクセスします。ドット表記法または角カッコ表記のいずれかを使用します。 – evolutionxbox

答えて

0

あなたはArray.prototype.filterを使用してgetFeaturesByPropertyを定義することができます。

var point_layer_WGS84_dist = { 
 
    "type": "FeatureCollection", 
 
    "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}}, 
 

 
    "features": [ 
 
    { 
 
     "type": "Feature", 
 
     "properties": {"x": 7.6789651, "y": 48.5066953, "distCoupe": 10000, "path": "coupes_10000_14995\\PM_10000.png"}, 
 
     "geometry": {"type": "Point", "coordinates": [7.6789651, 48.5066953]} 
 
    }, 
 
    { 
 
     "type": "Feature", 
 
     "properties": {"x": 7.6788011, "y": 48.5063054, "distCoupe": 10045, "path": "coupes_10000_14995\\PM_10045.png"}, 
 
     "geometry": {"type": "Point", "coordinates": [7.6788011, 48.5063054]} 
 
    }] 
 
}; 
 

 
point_layer_WGS84_dist.getFeaturesByProperty = function(key, value) { 
 
    return this.features.filter(function(feature){ 
 
    if (feature.properties[key] === value) { 
 
     return true; 
 
    } else { 
 
     return false; 
 
    } 
 
    }); 
 
}; 
 

 
var feats = point_layer_WGS84_dist.getFeaturesByProperty('distCoupe', 10000); 
 

 
console.log(feats);

+0

、GeoJSON変数がHTMLのおかげでリンクされた他のファイルにある場合、どうすれば使用できますか? – NanBlanc

+0

@NanBlanc 'point_layer_WGS84_dist'オブジェクトが別の.jsファイルにあることを意味しますか?もしそうなら、その.jsファイルを最初にインポートし、そのデータをグローバル変数(例えば、point_layer_WGS84_dist)に割り当て、上記のコードスニペットをインポートします( 'point_layer_WGS84_dist'初期化部分を削除します)。 – shaochuancs

+0

気にしないで、私はそれを得ました:)私はindex.jsの前にpoint_layer_WGS84_dist.jsを呼び出さなければなりませんでした。 //他の質問:オブジェクトフィーチャの特定のプロパティを抽出するにはどうすればできますか?私はfeats.properties.distCoupeを試しましたが、エラーが発生しました。 "未定義のプロパティ 'distCoupe'を読み取ることができません。 – NanBlanc

関連する問題