我想在我的WKT点添加一些参数,比如'name','population'和'rainfall'。
我的地图中缺少其他功能。
// basic map
.
.
.
// add wkt point
const wkt = 'POINT (8 50)';
const format = new ol.format.WKT();
const iconFeature = format.readFeature(wkt, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857',
name: 'Aachen',
population: 220000,
rainfall: 500
});
console.log(iconFeature);
map.addFeature(iconFeature);
答案 0 :(得分:2)
您的iconFeature
是ol.Feature
,您可以设置所需的任何属性:
const iconFeature = format.readFeature(wkt, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
iconFeature.set('name', 'Aachen');
iconFeature.set('population', '220000');
iconFeature.set('rainfall', '500');
请参阅http://openlayers.org/en/latest/apidoc/ol.Feature.html和http://openlayers.org/en/latest/apidoc/ol.format.WKT.html