【问题标题】:How to add style to a feature如何为功能添加样式
【发布时间】:2021-12-08 15:24:30
【问题描述】:

我使用 vue3-openlayers 并想将多边形添加到矢量源。

这是带有向量层和源向量的模板的一部分。

<ol-vector-layer>
    <ol-source-vector ref="source"></ol-source-vector>
</ol-vector-layer>

脚本部分:

Feature = inject("ol-feature");
Geom = inject("ol-geom");
source = ref(null);

mounted() {
    const coords = [[11.5647931, 47.2522687], [11.5649255, 47.2522687], [11.5649254, 47.2521789]];
    const geometry = new this.Geom.Polygon([coords]);
    const feature = new this.Feature({
        geometry: geometry,
    });
    this.source.source.addFeature(feature);
}

如何为特征添加描边宽度和填充颜色?

【问题讨论】:

    标签: javascript openlayers vuejs3 vue3-openlayers


    【解决方案1】:

    创建要素后,您可以在要素上设置样式。 例如:

      const coords = [[11.5647931, 47.2522687], [11.5649255, 47.2522687], [11.5649254, 47.2521789]];
        const geometry = new this.Geom.Polygon([coords]);
        const feature = new this.Feature({
            geometry: geometry,
        });
        feature.setStyle(myNewStyle); // This can be a single style object, an array of styles, or a functio
        this.source.source.addFeature(feature);
    

    您可以在此处阅读更多相关信息: https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html#setStyle

    【讨论】:

      猜你喜欢
      • 2021-08-12
      • 2019-11-14
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 2022-01-27
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多