如何在openlayers中向WKT几何体添加可选参数

时间:2018-01-17 14:19:05

标签: 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);

1 个答案:

答案 0 :(得分:2)

您的iconFeatureol.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.htmlhttp://openlayers.org/en/latest/apidoc/ol.format.WKT.html