官网demo地址:
这篇讲了如何随意移动地图上的矢量点。
先在地图上添加一个矢量点,其中anchorXUnits
和 anchorYUnits
: 指定锚点的单位。'fraction'
表示相对于图标的宽度(0到1之间),'pixels'
表示以像素为单位。
const iconFeature = new Feature({
geometry: new Point([0, 0]),
name: "Null Island",
population: 4000,
rainfall: 500,
});
const iconStyle = new Style({
image: new Icon({
anchor: [0.5, 46],
anchorXUnits: "fraction",
anchorYUnits: "pixels",
src: "https://openlayers.org/en/latest/examples/data/icon.png",