Javascript 获取GeoJSON属性

Javascript 获取GeoJSON属性,javascript,html,geojson,Javascript,Html,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, "di

以下是我的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

传单可以访问它,我如何也可以访问它?

您可以使用
数组.prototype.filter
定义
getFeaturesByProperty

var point\u layer\u WGS84\u dist={
“类型”:“FeatureCollection”,
“crs”:{“类型”:“名称”,“属性”:{“名称”:“urn:ogc:def:crs:ogc:1.3:CRS84”},
“特点”:[
{
“类型”:“功能”,
“属性”:{“x”:7.6789651,“y”:48.5066953,“distCoupe”:10000,“path”:“coupes_10000_14995\\PM_10000.png”,
“几何学”:{“类型”:“点”,“坐标”:[7.6789651,48.5066953]}
},
{
“类型”:“功能”,
“属性”:{“x”:7.6788011,“y”:48.5063054,“distCoupe”:10045,“路径”:“coupes_10000_14995\\PM_10045.png”,
“几何学”:{“类型”:“点”,“坐标”:[7.6788011,48.5063054]}
}]
};
point_layer_WGS84_dist.getFeaturesByProperty=函数(键,值){
返回此.features.filter(函数(功能){
if(feature.properties[键]==值){
返回true;
}否则{
返回false;
}
});
};
var feats=点\图层\ WGS84 \距离getFeaturesByProperty('distCoupe',10000);

控制台日志(专长)只需像普通JS对象一样访问它。使用点表示法或方括号表示法。如果我的GeoJSON变量位于我通过HTML链接的另一个文件中,我该如何使用它?@NanBlanc你是说
point\u layer\u WGS84\u dist
对象来自另一个.js文件吗?如果是,您可以首先导入该.js文件,将数据分配给一个全局变量(例如
point\u layer\u WGS84\u dist
),然后导入上面的代码片段(当然,删除
point\u layer\u WGS84\u dist
初始化部分)。没关系,我得到了它:)我只需在index.js之前调用point\u layer\u WGS84\u dist.js即可另一个问题:如何提取对象专长的特定属性,现在我提取了它?我尝试了feats.properties.distCoupe,但出现了一个错误“无法读取未定义的属性'distCoupe'”,我单独找到了答案:console.log(feats[0].properties.z);再次感谢你的帮助!!!