0

在我的应用程序中,我使用常规标记。一个标记应该不同。

使用 OL5,如何添加带有特定图标/图像的不同标记?

看着(旧的?)例子我看到了这个?但这将在 OL5 中失败。

const marker = new Feature({
    geometry: new Point(fromLonLat([0 + mylongitude, 0 + (mylatitude)]))
});
marker.setStyles(new Style({
    image: new Icon(({
        crossOrigin: 'anonymous',
        src: 'assets/images/guestimate_red_hair.png'
    }))
}));
this.vectorLayer.getSource().addFeature(marker);
4

1 回答 1

1

您可以为此使用图标样式。

    var iconStyle = new ol.style.Style({
      image: new ol.style.Icon(({
        anchor: [0.5, 0.5],
        scale:0.15,
        opacity: 0.75,
        src: 'assets/images/guestimate_red_hair.png'
      }))
    });
marker.setStyle(iconStyle)

看看这个https://openlayers.org/en/latest/apidoc/module-ol_style_Image-ImageStyle.html

确保图片网址正确。

于 2019-08-28T12:38:14.400 回答