在我的網頁上,用戶可以繪制一個多邊形,然后對其進行修改。但是,我只允許用戶拖放繪制的角,而不是在修改多邊形時將新點添加到多邊形中。在下面的示例中,我創建了一個具有四個角的多邊形,并希望在修改過程中保持四個角(僅拖動角)。我認為我們應該condition在modify函數中使用,但不確定如何找出單擊多邊形的角或邊之間的區別。<!DOCTYPE html><html> <head> <title>Draw Features</title> <link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" type="text/css"> <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script> </head> <body> <div id="map" class="map"></div> <script> var raster = new ol.layer.Tile({ source: new ol.source.OSM() }); var source = new ol.source.Vector({wrapX: false}); var offset = 1000000; var ply = new ol.geom.Polygon([[ [-11000000 - offset, 4600000 - offset], [-11000000 + offset, 4600000 - offset], [-11000000 + offset, 4600000 + offset], [-11000000 - offset, 4600000 + offset]]]); var feature = new ol.Feature(ply); source.addFeatures([feature]); var vector = new ol.layer.Vector({ source: source }); var map = new ol.Map({ layers: [raster, vector], target: 'map', view: new ol.View({ center: [-11000000, 4600000], zoom: 4 }) }); var modify = new ol.interaction.Modify({source: source}) map.addInteraction(modify); </script> </body></html>
停止在帶有openlayers 5.3.0的多邊形中添加點
慕絲7291255
2021-04-07 13:10:55