如何在 openlayers 中向 WKT 几何体添加可选参数
How to add optional parameters to WKT geometry in openlayers
我想为我的 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);
你的 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 and http://openlayers.org/en/latest/apidoc/ol.format.WKT.html
我想为我的 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);
你的 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 and http://openlayers.org/en/latest/apidoc/ol.format.WKT.html