Make requests to create stairs
This commit is contained in:
parent
e893e53151
commit
e1fe06a1b1
3 changed files with 51 additions and 16 deletions
|
@ -501,6 +501,10 @@ editor = {
|
||||||
// listener for form submits in the sidebar.
|
// listener for form submits in the sidebar.
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (editor._loading_geometry || $(this).is('.creation-lock') || $(this).is('.scan-lock')) return;
|
if (editor._loading_geometry || $(this).is('.creation-lock') || $(this).is('.scan-lock')) return;
|
||||||
|
if (editor._staircase_layer) {
|
||||||
|
editor._staircase_submit($(this))
|
||||||
|
return
|
||||||
|
}
|
||||||
var data = $(this).serialize();
|
var data = $(this).serialize();
|
||||||
var btn = $(this).data('btn');
|
var btn = $(this).data('btn');
|
||||||
if (btn !== undefined && btn !== null) {
|
if (btn !== undefined && btn !== null) {
|
||||||
|
@ -1906,12 +1910,12 @@ editor = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_destroy_staircase_editing: function() {
|
_destroy_staircase_editing: function() {
|
||||||
if (editor._staircase_layer !== null) {
|
if (editor._staircase_layer) {
|
||||||
editor.map.removeLayer(editor._staircase_layer)
|
editor.map.removeLayer(editor._staircase_layer)
|
||||||
editor._staircase_layer = null
|
editor._staircase_layer = null
|
||||||
}
|
}
|
||||||
editor.map.off('editable:editing', editor._update_staircase_preview)
|
editor.map.off('editable:editing', editor._update_staircase_preview)
|
||||||
if (editor._current_editing_shape !== null) {
|
if (editor._current_editing_shape && editor._current_editing_shape.editor) {
|
||||||
editor._current_editing_shape.editor.cancelDrawing()
|
editor._current_editing_shape.editor.cancelDrawing()
|
||||||
editor._current_editing_shape.remove()
|
editor._current_editing_shape.remove()
|
||||||
editor._current_editing_shape = null
|
editor._current_editing_shape = null
|
||||||
|
@ -1989,29 +1993,59 @@ editor = {
|
||||||
return lines
|
return lines
|
||||||
},
|
},
|
||||||
|
|
||||||
_update_staircase_preview: function(e = null) {
|
_get_staircase_lines: function() {
|
||||||
if (editor._current_editing_shape === null) {
|
if (!editor._current_editing_shape || !editor._current_editing_shape._parts) {
|
||||||
return
|
return []
|
||||||
}
|
}
|
||||||
points = editor._current_editing_shape._parts[0] || []
|
points = editor._current_editing_shape._parts[0] || []
|
||||||
editor._staircase_layer.clearLayers()
|
|
||||||
//console.log(points)
|
|
||||||
if (points.length < 3) {
|
if (points.length < 3) {
|
||||||
return
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
xs = points.map(p => p.x)
|
xs = points.map(p => p.x)
|
||||||
ys = points.map(p => p.y)
|
ys = points.map(p => p.y)
|
||||||
lines = editor._transform_for_staircase(xs, ys, editor._staircase_steps_count)
|
lines = editor._transform_for_staircase(xs, ys, editor._staircase_steps_count)
|
||||||
|
lines = lines.map(l => [
|
||||||
|
editor.map.layerPointToLatLng([l.p1.x, l.p1.y]),
|
||||||
|
editor.map.layerPointToLatLng([l.p2.x, l.p2.y]),
|
||||||
|
])
|
||||||
|
return lines
|
||||||
|
},
|
||||||
|
|
||||||
|
_update_staircase_preview: function(e = null) {
|
||||||
|
if (editor._staircase_layer) {
|
||||||
|
editor._staircase_layer.clearLayers()
|
||||||
|
}
|
||||||
|
lines = editor._get_staircase_lines()
|
||||||
lines.forEach(l => {
|
lines.forEach(l => {
|
||||||
L.polyline(
|
L.polyline(l, {color: "red"}).addTo(editor._staircase_layer);
|
||||||
[
|
})
|
||||||
editor.map.layerPointToLatLng([l.p1.x, l.p1.y]),
|
},
|
||||||
editor.map.layerPointToLatLng([l.p2.x, l.p2.y]),
|
|
||||||
],
|
_staircase_submit: function(form) {
|
||||||
{color: "red"}
|
csrfmiddlewaretoken = form.find('input[name=csrfmiddlewaretoken]').attr('value')
|
||||||
).addTo(editor._staircase_layer);
|
import_tag = form.find('input[name=import_tag]').val()
|
||||||
|
space = form.attr('space')
|
||||||
|
lines = editor._get_staircase_lines()
|
||||||
|
|
||||||
|
console.log("hereeeeeee", csrfmiddlewaretoken, import_tag, space, lines)
|
||||||
|
Promise.all(lines.map(l =>
|
||||||
|
fetch("/editor/spaces/" + space + "/stairs/create", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
},
|
||||||
|
body: "csrfmiddlewaretoken=" + encodeURIComponent(csrfmiddlewaretoken) +
|
||||||
|
"&geometry=" + encodeURIComponent(JSON.stringify({
|
||||||
|
type: "LineString",
|
||||||
|
coordinates: [[l[0]["lng"], l[0]["lat"]], [l[1]["lng"], l[1]["lat"]]]
|
||||||
|
})) +
|
||||||
|
"&import_tag=" + encodeURIComponent(import_tag)
|
||||||
|
})
|
||||||
|
)).then(() => {
|
||||||
|
form.remove()
|
||||||
|
window.location.href = "/editor/spaces/" + space + "/stairs"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
{% bootstrap_messages %}
|
{% bootstrap_messages %}
|
||||||
|
|
||||||
<form {% if nozoom %}data-nozoom {% endif %}data-onbeforeunload data-new="staircase" data-geomtype="polygon" {% if access_restriction_select %} data-access-restriction-select{% endif %}>
|
<form space="{{ space }}" {% if nozoom %}data-nozoom {% endif %}data-onbeforeunload data-new="staircase" data-geomtype="polygon" {% if access_restriction_select %} data-access-restriction-select{% endif %}>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
@ -412,6 +412,7 @@ def edit(request, pk=None, model=None, level=None, space=None, on_top_of=None, e
|
||||||
})
|
})
|
||||||
|
|
||||||
if request.path.endswith("staircase"):
|
if request.path.endswith("staircase"):
|
||||||
|
ctx["space"] = space_id
|
||||||
return render(request, 'editor/create_staircase.html', ctx)
|
return render(request, 'editor/create_staircase.html', ctx)
|
||||||
else:
|
else:
|
||||||
return render(request, 'editor/edit.html', ctx)
|
return render(request, 'editor/edit.html', ctx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue