官网demo地址:

这个示例介绍了如何在地图上自定义一个交互实现在地图上拖拽、移动要素。
首先是加载了三个要素到地图上,一个点、一个多边形、一条线。
const pointFeature = new Feature(new Point([0, 0]));
const lineFeature = new Feature(
new LineString([
[-1e7, 1e6],
[-1e6, 3e6],
])
);
const polygonFeature = new Feature(
new Polygon([
[
[-3e6, -1e6],
[-3e6, 1e6],
[-1e6, 1e6],
[-1e6, -1e6],
[-3e6, -1e6],
],
])
);
new VectorLayer({
source: new VectorSource({
features: [pointFeature, lineFeature, polygonFeature],
}),
style: {
"icon-src": "data/icon.png",
"icon-opacity": 0.95,
"icon-anchor": [0.5, 46], //设置图标锚点的位置
"icon-anchor-x-units": "fraction", //指定锚点的水平单位是比例值
"icon-anchor-y-units": "pixels", //指定锚点的垂直单位是像素值
"stroke-width": 3,
"stroke-color": [255, 0, 0, 1],
"fill-color": [0, 0, 255, 0.6],
},
}),
然后创建了一个类继承原本的PointerInteraction,将四个事件作为参数传递给PointerInteraction。来处理事件逻辑。
class Drag extends PointerInteraction {
constructor() {
super({
handleDownEvent: handleDownEvent, //按下事件
handleDragEvent: handleDragEvent, //拖动事件

最低0.47元/天 解锁文章
482

被折叠的 条评论
为什么被折叠?



