以下是我的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 有可能像:
var feat = point_layer_WGS84_dist.getFeatureByPropertie("distCoupe",'10000')
var imageLocation = feat.path
传单能够访问它,我怎么能这样做?
答案 0 :(得分:1)
您可以使用getFeaturesByProperty
:
Array.prototype.filter
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);