diff --git a/src/c3nav/editor/static/editor/js/editor.js b/src/c3nav/editor/static/editor/js/editor.js index 3665ffe8..ccb4be9b 100644 --- a/src/c3nav/editor/static/editor/js/editor.js +++ b/src/c3nav/editor/static/editor/js/editor.js @@ -560,8 +560,11 @@ editor = { _graph_edges_to: {}, _arrow_colors: [], _last_vertex: null, + _num_vertices: 0, _orig_vertex_pos: null, _max_bounds: null, + _creating_type: null, + _shift_pressed: false, init_geometries: function () { // init geometries and edit listeners editor._highlight_layer = L.layerGroup().addTo(editor.map); @@ -578,9 +581,32 @@ editor = { }); editor.map.on('editable:drawing:start editable:drawing:end', function() { editor._last_vertex = null; + editor._num_vertices = 0; }); editor.map.on('editable:vertex:new', function(e) { + if (editor._shift_pressed && editor._creating && editor._creating_type === 'polygon' && editor._num_vertices === 1) { + var firstPoint = new L.Point(editor._last_vertex.latlng.lng, editor._last_vertex.latlng.lat), + secondPoint = new L.Point(e.vertex.latlng.lng, e.vertex.latlng.lat), + center = new L.Point((firstPoint.x+secondPoint.x)/2, (firstPoint.y+secondPoint.y)/2), + radius = firstPoint.distanceTo(secondPoint)/2, + options = e.layer.options, + points = Math.min(32, 8+Math.floor(radius*5)*2), + vertices = []; + for (var i=0;i