简体   繁体   English

获取GeoJSON属性

[英]Get GeoJSON properties

Here is a view of my 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 ] } },

i want to get information from a geojson file, that i linked thought the HTML is there a possibilty like : 我想从geojson文件中获取信息,我链接认为HTML存在如下可能性:

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

leaflet is able to access to it, how can i do it too ? 传单可以访问它,我也该怎么做?

You can define getFeaturesByProperty by using Array.prototype.filter : 您可以使用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); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM