hal/resource/web/map.tmpl

55 lines
1.7 KiB
Cheetah
Raw Normal View History

2016-06-23 22:04:54 +02:00
<svg id="map" width="100%" width="500" viewBox="0 0 1000 500">
<!-- Background Map -->
<image x="0" y="0" width="100%" height="100%" xlink:href="/img/floorplan.jpg" />
2016-06-23 22:04:54 +02:00
<!-- debug stuff -->
<rect width="100%" height="100%" style="fill-opacity:0;stroke-width:5;stroke:rgb(0,0,0)" />
2016-06-23 22:04:54 +02:00
<!-- Sensor devices-->
2016-06-29 17:14:05 +02:00
{{#sensors}}
<image id="sensor{{.getId()}}" class="draggable sensor" x="0" y="0" width="46" height="46" xlink:href="/img/temperature.png" />
{{/sensors}}
2016-06-23 22:04:54 +02:00
<!-- Event devices -->
2016-06-29 17:14:05 +02:00
{{#events}}
<image id="event{{.getId()}}" class="draggable event" x="0" y="0" width="46" height="46" xlink:href="/img/lightbulb.svg" />
{{/events}}
</svg>
2016-06-23 22:04:54 +02:00
<script src="js/interact.js"></script>
<script>
var rootMatrix;
$(function(){
rootMatrix = document.getElementById("map").getScreenCTM();
interact(".draggable").draggable({
inertia: true,
restrict: {
restriction: "parent",
elementRect: { left: 0, right: 0, top: 0, bottom: 0 },
},
onmove: dragMoveListener,
onend: dragEndListener,
});
});
function dragMoveListener (event) {
var target = event.target;
// keep the dragged position in the data-x/data-y attributes
var x = (parseFloat(target.getAttribute('x')) || 0) + event.dx / rootMatrix.a;
var y = (parseFloat(target.getAttribute('y')) || 0) + event.dy / rootMatrix.d;
// update the position attributes
target.setAttribute('x', x);
target.setAttribute('y', y);
}
function dragEndListener (event) {
// Save drag
}
</script>
<center>
Icons downloaded from <a href="http://icons8.com">icons8.com</a>
</center>