javascript - 如何在 ol.js 中修改 2 个多边形
问题描述
如何在地图上的对象处于修改模式时使用ol.js修改对象的墙壁,这样如果一侧移动,另一个对象的这面墙上的另一面墙会随之移动??
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import {Circle as CircleStyle, Fill, Stroke, Style} from 'ol/style';
import {Draw, Modify, Snap} from 'ol/interaction';
import {OSM, Vector as VectorSource} from 'ol/source';
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
var raster = new TileLayer({
source: new OSM(),
});
var source = new VectorSource();
var vector = new VectorLayer({
source: source,
style: new Style({
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)',
}),
stroke: new Stroke({
color: '#ffcc33',
width: 2,
}),
image: new CircleStyle({
radius: 7,
fill: new Fill({
color: '#ffcc33',
}),
}),
}),
});
var map = new Map({
layers: [raster, vector],
target: 'map',
view: new View({
center: [-11000000, 4600000],
zoom: 4,
}),
});
var modify = new Modify({source: source});
map.addInteraction(modify);
var draw, snap; // global so we can remove them later
var typeSelect = document.getElementById('type');
function addInteractions() {
draw = new Draw({
source: source,
type: typeSelect.value,
});
map.addInteraction(draw);
snap = new Snap({source: source});
map.addInteraction(snap);
}
/**
* Handle change event.
*/
typeSelect.onchange = function () {
map.removeInteraction(draw);
map.removeInteraction(snap);
addInteractions();
};
addInteractions();
在图像中,如果 2 个多边形在同一连接边上连接在一起,则当移动这些公共边之一时,两边都会移动。我在哪里可以检查此代码中的更改,或者我在哪里有问题?
解决方案
推荐阅读
- flask - 使用 Flask-sqlalchemy 过滤今天的日期数据(从 YYYY-MM-DD-HH: MM: SS 格式转换为 YYYY-MM-DD 没有小时、分钟和秒)
- c# - 使用 Dynamic Linq 选择一个简单的 List
来自所选字段为动态的模型列表 - python - kivyMD 如何从构建器调用函数?
- python - 有没有办法避免在遗传算法中选择两个相同的父母?
- javascript - 当元素为(显示:无)时如何显示选中的收音机元素
- reactjs - 使用选择和选项时状态不更新
- java - Android studio Material design:自动完成不会自动选择项目下拉列表
- sql - 在获取每个日期的最近值的同时获取每个日期的值总和?
- r - 如何使用 R 根据另一个条件将变量添加到数据框中
- client-server - 客户端架构设置