We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<!DOCTYPE html> <html> <head> <title>Draw and Modify Features</title> <link rel="stylesheet" href="http://localhost:42000/assets/js/map/ol.css" type="text/css"> <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> <script src="http://localhost:42000/assets/js/map/ol.js"></script> </head> <body> <div id="map" class="map"></div> <script> var raster = new ol.layer.Tile({ source: new ol.source.OSM() }); var map = new ol.Map({ layers: [raster], target: 'map', view: new ol.View({ center: [-11000000, 4600000], zoom: 4 }) }); var MapController = function (map, callback) { var drawkSettings = { fill: new ol.style.Fill({ color: 'rgba(255, 255, 255, 0.2)' }), stroke: new ol.style.Stroke({ color: '#ffcc33', width: 2 }), image: new ol.style.Circle({ radius: 7, fill: new ol.style.Fill({ color: '#ffcc33' }) }) } var features = new ol.Collection(); var featureOverlay = new ol.layer.Vector({ source: new ol.source.Vector({ features: features }), style: new ol.style.Style(drawkSettings) }); featureOverlay.setMap(map); // propties // 创建修改交互控件 var modify = new ol.interaction.Modify({ features: features, change: changed, deleteCondition: function (event) { changed(); return ol.events.condition.shiftKeyOnly(event) && ol.events.condition.singleClick(event); } }); function changed() { // 修改之后触发 if (callback) callback(); } // 创建绘制交互控件 var draw = new ol.interaction.Draw({ features: features, type: 'Point', change: changed }); // methods this.startModify = function () { this.stopModify(); map.addInteraction(modify); } this.startDraw = function (type) { this.stopDraw(); draw = new ol.interaction.Draw({ features: features, type: type || 'Point' }); map.addInteraction(draw); } this.stopModify = function () { map.removeInteraction(modify); } this.stopDraw = function () { map.removeInteraction(draw); } this.addPoint = function (x, y) { features.push(new ol.Feature(new ol.geom.Point([x, y]))); changed(); } this.getPoints = function () { return features; } } // code var myMapController = new MapController(map, function () { console.log(myMapController.getPoints().getArray()[0].getGeometry().getCoordinates()); }); myMapController.addPoint(0, 0); </script> </body> </html>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: