drawing map features and opening popups
This commit is contained in:
parent
d1ec2a65ca
commit
5c65421096
2 changed files with 99 additions and 34 deletions
|
@ -13,9 +13,12 @@
|
||||||
top:2px;
|
top:2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.leaflet-biggericon {
|
.leaflet-editbar a {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
.leaflet-editbar a.current {
|
||||||
|
background-color:#FFFFDD;
|
||||||
|
}
|
||||||
.leaflet-levels a {
|
.leaflet-levels a {
|
||||||
font-size:16px;
|
font-size:16px;
|
||||||
color:#333333;
|
color:#333333;
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
{% extends 'control/base.html' %}
|
{% extends 'control/base.html' %}
|
||||||
|
{% load static %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="mapeditor"></div>
|
<div id="mapeditor"></div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block addbottom %}
|
{% block addbottom %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
// Init Map
|
||||||
var map = L.map('mapeditor', {
|
var map = L.map('mapeditor', {
|
||||||
center: [120, 200],
|
center: [120, 200],
|
||||||
zoom: 2,
|
zoom: 2,
|
||||||
|
@ -12,8 +14,11 @@ var map = L.map('mapeditor', {
|
||||||
maxZoom: 10,
|
maxZoom: 10,
|
||||||
minZoom: 1,
|
minZoom: 1,
|
||||||
crs: L.CRS.Simple,
|
crs: L.CRS.Simple,
|
||||||
|
editable: true,
|
||||||
|
closePopupOnClick: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add Source Layers
|
||||||
{% for pkg in map.pkgs.values %}
|
{% for pkg in map.pkgs.values %}
|
||||||
L.control.layers([], {
|
L.control.layers([], {
|
||||||
{% for source in pkg.sources %}
|
{% for source in pkg.sources %}
|
||||||
|
@ -21,6 +26,7 @@ L.control.layers([], {
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
// Add Layer Control
|
||||||
L.LevelControl = L.Control.extend({
|
L.LevelControl = L.Control.extend({
|
||||||
options: {
|
options: {
|
||||||
position: 'bottomright'
|
position: 'bottomright'
|
||||||
|
@ -37,48 +43,104 @@ L.LevelControl = L.Control.extend({
|
||||||
});
|
});
|
||||||
map.addControl(new L.LevelControl());
|
map.addControl(new L.LevelControl());
|
||||||
|
|
||||||
|
// Default styles:
|
||||||
|
feature_types = {
|
||||||
|
building: {
|
||||||
|
type: 'polygon',
|
||||||
|
color: '#000000',
|
||||||
|
},
|
||||||
|
room: {
|
||||||
|
type: 'polygon',
|
||||||
|
color: '#CCCCCC',
|
||||||
|
},
|
||||||
|
obstacle: {
|
||||||
|
type: 'polygon',
|
||||||
|
color: '#999999',
|
||||||
|
},
|
||||||
|
door: {
|
||||||
|
type: 'polygon',
|
||||||
|
color: '#FF00FF',
|
||||||
|
},
|
||||||
|
step: {
|
||||||
|
type: 'polyline',
|
||||||
|
color: '#FF0000',
|
||||||
|
},
|
||||||
|
elevator: {
|
||||||
|
type: 'polygon',
|
||||||
|
color: '#99CC00',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add drawing new features
|
||||||
|
currently_drawing = null;
|
||||||
|
currently_adding = null;
|
||||||
|
function add_edit_button(map, container, type, icon, callback) {
|
||||||
|
$('<a href="#">').appendTo(container).text(icon).attr({
|
||||||
|
href: '#',
|
||||||
|
title: 'add '+name,
|
||||||
|
name: type
|
||||||
|
}).on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// If we are currently adding a feature, don't start drawing another.
|
||||||
|
if (currently_adding !== null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are currently drawing a feature, don't start drawing another.
|
||||||
|
if (currently_drawing !== null) {
|
||||||
|
// If it is a feature of the same type, cancel it.
|
||||||
|
if (currently_drawing === type) {
|
||||||
|
$('.leaflet-editbar .current').removeClass('current');
|
||||||
|
currently_drawing = null;
|
||||||
|
map.editTools.stopDrawing();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currently_drawing = type;
|
||||||
|
console.log(type);
|
||||||
|
$('.leaflet-editbar .current').removeClass('current');
|
||||||
|
$('.leaflet-editbar [name='+type+']').addClass('current');
|
||||||
|
options = feature_types[type];
|
||||||
|
if (options.type == 'polygon') {
|
||||||
|
map.editTools.startPolygon(null, options);
|
||||||
|
} else if (options.type == 'polyline') {
|
||||||
|
map.editTools.startPolyline(null, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
L.DrawControl = L.Control.extend({
|
L.DrawControl = L.Control.extend({
|
||||||
options: {
|
options: {
|
||||||
position: 'topleft'
|
position: 'topleft'
|
||||||
},
|
},
|
||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar'), link;
|
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar leaflet-editbar');
|
||||||
|
add_edit_button(map, container, 'building', '🏠');
|
||||||
link = L.DomUtil.create('a', 'leaflet-biggericon', container);
|
add_edit_button(map, container, 'room', '⬠');
|
||||||
link.href = '{% url "control.editor" level=level %}';
|
add_edit_button(map, container, 'obstacle', '⬟');
|
||||||
link.title = 'add building'
|
add_edit_button(map, container, 'door', '🚪');
|
||||||
link.innerHTML = '🏠';
|
add_edit_button(map, container, 'step', '┌┘');
|
||||||
|
add_edit_button(map, container, 'elevator', '▴▾');
|
||||||
link = L.DomUtil.create('a', 'leaflet-biggericon', container);
|
|
||||||
link.href = '{% url "control.editor" level=level %}';
|
|
||||||
link.title = 'add room/area';
|
|
||||||
link.innerHTML = '⬠';
|
|
||||||
|
|
||||||
link = L.DomUtil.create('a', 'leaflet-biggericon', container);
|
|
||||||
link.href = '{% url "control.editor" level=level %}';
|
|
||||||
link.title = 'add obstacle'
|
|
||||||
link.innerHTML = '⬟';
|
|
||||||
|
|
||||||
link = L.DomUtil.create('a', 'leaflet-biggericon', container);
|
|
||||||
link.href = '{% url "control.editor" level=level %}';
|
|
||||||
link.title = 'add door';
|
|
||||||
link.innerHTML = '🚪';
|
|
||||||
|
|
||||||
link = L.DomUtil.create('a', '', container);
|
|
||||||
link.href = '{% url "control.editor" level=level %}';
|
|
||||||
link.title = 'add steps';
|
|
||||||
link.innerHTML = '┌┘';
|
|
||||||
|
|
||||||
link = L.DomUtil.create('a', 'leaflet-biggericon', container);
|
|
||||||
link.href = '{% url "control.editor" level=level %}';
|
|
||||||
link.title = 'add elevator';
|
|
||||||
link.innerHTML = '▴▾';
|
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
map.addControl(new L.DrawControl());
|
map.addControl(new L.DrawControl());
|
||||||
|
map.on('editable:drawing:commit', function (e) {
|
||||||
|
currently_drawing = null;
|
||||||
|
currently_adding = e.layer;
|
||||||
|
$('.leaflet-editbar .current').removeClass('current');
|
||||||
|
e.layer.disableEdit();
|
||||||
|
e.layer.bindPopup('<img src="{% static "img/loader.gif" %}">', {
|
||||||
|
closeButton: false
|
||||||
|
}).openPopup();
|
||||||
|
console.log(e.layer.toGeoJSON());
|
||||||
|
}).on('editable:drawing:cancel', function (e) {
|
||||||
|
if (currently_drawing === null && currently_adding === null) {
|
||||||
|
e.layer.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
L.control.scale({imperial: false}).addTo(map);
|
L.control.scale({imperial: false}).addTo(map);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue