您可以以 json 格式定义您的功能
var geoSource = new ol.source.GeoJSON({
/* @type {olx.source.GeoJSONOptions} */
"projection": "EPSG:3857" //us
, "object": {
"type": "FeatureCollection"
, "crs": { "type": "name", "properties": { "name": "EPSG:4326" } }//'EPSG:3857'//euro 'urn:ogc:def:crs:EPSG::4326'//'urn:ogc:def:crs:OGC:1.3:CRS84'
, "features": [
{
"type": "Feature", "id": "01"
, "geometry": { "type": "Point", "coordinates": [-80.0874386, 26.7816928] }
, "properties": { "myproperty": "West Palm Beach" }
}
, {
"type": "Feature", "id": "02"
, "geometry": { "type": "Point", "coordinates": [-82.0838700, 26.9262480] }
, "properties": { "myproperty": "Punta Gonda" }
}
]
}
});
然后您通过以下方式访问该功能
var ff = geoSource.getFeatureById('02');
alert(ff.getProperties()['myproperty']);
或者如果您需要分析所有特征,您可以
geoSource.getFeatures().forEach(function (ff) {
alert(ff.getProperties()['myproperty']);
})
它有帮助吗?祝你好运。