openlayers 中的点和圆有什么区别?

问题描述 投票:0回答:1

我想在地图中添加圆形特征,我使用圆形几何体,但它不起作用。当我将圆更改为点时,它起作用了。

const feature = new ol.Feature(
  new ol.geom.Circle([0, 0], 100)
)

feature.setStyle(new ol.style.Style({
  image: new ol.style.Circle({
    raidus: 100,
    stroke: new ol.style.Stroke({ color: '#ff0000', width: 2 })
  })
}))

vectorLayer.getSource().addFeature(feature)

那么,什么时候可以使用圆形几何体来创建特征?

openlayers
1个回答
0
投票

圆形样式半径以显示像素为单位(与视图缩放或地球上的距离无关),通常用于设置点几何图形的样式:

const feature = new ol.Feature(
  new ol.geom.Point([0, 0])
)

feature.setStyle(new ol.style.Style({
  image: new ol.style.Circle({
    raidus: 100,
    stroke: new ol.style.Stroke({ color: '#ff0000', width: 2 })
  })
}))

vectorLayer.getSource().addFeature(feature)

圆形几何半径采用视图投影单位(米、度等),表示地面上的距离(因此可见尺寸会随着视图缩放而变化),并且应采用与多边形几何形状相同的方式设置样式:

const feature = new ol.Feature(
  new ol.geom.Circle([0, 0], 100)
)

feature.setStyle(new ol.style.Style({
  stroke: new ol.style.Stroke({ color: '#ff0000', width: 2 })
}))

vectorLayer.getSource().addFeature(feature)
© www.soinside.com 2019 - 2024. All rights reserved.