2016-07-06 22:52:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ffhb')
|
2016-07-09 10:15:03 +02:00
|
|
|
.controller('NodeCtrl',function($stateParams,$scope,store,config,leafletData){
|
2016-07-13 11:43:27 +02:00
|
|
|
$scope.nodeid = $stateParams.nodeid.toLowerCase();
|
2016-07-12 18:29:02 +02:00
|
|
|
$scope.loadingGPS = false;
|
2016-07-06 22:52:31 +02:00
|
|
|
$scope.node = {};
|
2016-07-09 10:15:03 +02:00
|
|
|
angular.extend($scope, {
|
|
|
|
center: config.map.view,
|
|
|
|
markers: {node:{
|
|
|
|
lat: config.map.view.lat,
|
|
|
|
lng: config.map.view.lng,
|
|
|
|
focus: true,
|
|
|
|
title: 'Marker',
|
|
|
|
draggable: true,
|
|
|
|
label: {
|
2016-07-13 11:43:27 +02:00
|
|
|
message: 'Node:'+$scope.nodeid,
|
2016-07-09 10:15:03 +02:00
|
|
|
options: {
|
|
|
|
noHide: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}},
|
|
|
|
events:{}
|
|
|
|
});
|
2016-07-06 22:52:31 +02:00
|
|
|
store.getGeojson.then(function(data){
|
2016-07-09 10:15:03 +02:00
|
|
|
leafletData.getMap().then(function(map) {
|
|
|
|
L.geoJson(data,config.map.geojson).addTo(map);
|
|
|
|
});
|
2016-07-06 22:52:31 +02:00
|
|
|
});
|
|
|
|
function render(prom){
|
|
|
|
prom.then(function(data){
|
2016-07-13 11:43:27 +02:00
|
|
|
$scope.node = data.merged[$scope.nodeid];
|
2016-07-11 10:06:12 +02:00
|
|
|
if($scope.node !== undefined && $scope.node.nodeinfo !== undefined){
|
|
|
|
$scope.markers.node.lat = $scope.node.nodeinfo.location.latitude;
|
|
|
|
$scope.markers.node.lng = $scope.node.nodeinfo.location.longitude;
|
|
|
|
}
|
2016-07-06 22:52:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
render(store.getData);
|
|
|
|
$scope.$on('store', function(ev, prom) {
|
|
|
|
render(prom);
|
|
|
|
});
|
|
|
|
|
2016-07-09 10:15:03 +02:00
|
|
|
$scope.$on('leafletDirectiveMarker.dragend', function(event, args){
|
2016-07-11 10:06:12 +02:00
|
|
|
if($scope.node !== undefined && $scope.node.nodeinfo !== undefined){
|
|
|
|
$scope.node.nodeinfo.location = {
|
|
|
|
'latitude': args.model.lat,
|
|
|
|
'longitude': args.model.lng
|
|
|
|
};
|
2016-07-13 11:43:27 +02:00
|
|
|
store.saveNode($scope.nodeid);
|
2016-07-09 10:15:03 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
var setToGps = function(position){
|
2016-07-12 18:29:02 +02:00
|
|
|
$scope.loadingGPS = false;
|
2016-07-09 10:15:03 +02:00
|
|
|
var pos = [position.coords.latitude,position.coords.longitude];
|
2016-07-11 10:06:12 +02:00
|
|
|
if($scope.node !== undefined && $scope.node.nodeinfo !== undefined){
|
|
|
|
$scope.node.nodeinfo.location = {
|
|
|
|
'latitude': position.coords.latitude,
|
|
|
|
'longitude': position.coords.longitude
|
|
|
|
};
|
2016-07-09 10:15:03 +02:00
|
|
|
leafletData.getMap().then(function(map) {
|
|
|
|
map.setView(pos);
|
|
|
|
});
|
2016-07-13 11:43:27 +02:00
|
|
|
store.saveNode($scope.nodeid);
|
2016-07-11 10:06:12 +02:00
|
|
|
$scope.markers.node.lat = position.coords.latitude;
|
|
|
|
$scope.markers.node.lng = position.coords.longitude;
|
2016-07-09 10:15:03 +02:00
|
|
|
}
|
|
|
|
};
|
2016-07-06 22:52:31 +02:00
|
|
|
$scope.gps = function() {
|
2016-07-09 10:15:03 +02:00
|
|
|
if (navigator.geolocation) {
|
|
|
|
navigator.geolocation.getCurrentPosition(setToGps);
|
2016-07-12 18:29:02 +02:00
|
|
|
$scope.loadingGPS = true;
|
2016-07-09 10:15:03 +02:00
|
|
|
}else{
|
|
|
|
window.alert('No Permission for location');
|
|
|
|
}
|
2016-07-06 22:52:31 +02:00
|
|
|
};
|
|
|
|
$scope.save = function() {
|
|
|
|
store.saveNode($stateParams.nodeid);
|
|
|
|
};
|
|
|
|
});
|