Detection whether position is within community borders.
This commit is contained in:
parent
cabc070b77
commit
43b4ad9178
31 changed files with 11960 additions and 16 deletions
app/scripts
|
@ -5,7 +5,8 @@ angular.module('ffffng', [
|
|||
'ngRoute',
|
||||
'ng',
|
||||
'leaflet-directive',
|
||||
'templates-main'
|
||||
'templates-main',
|
||||
'ui.bootstrap'
|
||||
])
|
||||
.config(function ($routeProvider) {
|
||||
$routeProvider
|
||||
|
|
29
app/scripts/dialogs/outsideOfCommunityDialog.js
Normal file
29
app/scripts/dialogs/outsideOfCommunityDialog.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng')
|
||||
.factory('OutsideOfCommunityDialog', function ($modal, config) {
|
||||
var ctrl = function ($scope, $modalInstance, action) {
|
||||
$scope.action = action;
|
||||
$scope.config = config;
|
||||
|
||||
$scope.proceed = function () {
|
||||
$modalInstance.close();
|
||||
};
|
||||
|
||||
$scope.cancel = function () {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
open: function (action) {
|
||||
return $modal.open({
|
||||
controller: ctrl,
|
||||
templateUrl: 'views/dialogs/outsideOfCommunityDialog.html',
|
||||
resolve: {
|
||||
action: function () { return action; }
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -2,7 +2,17 @@
|
|||
|
||||
angular.module('ffffng')
|
||||
.directive('fNodeForm', function () {
|
||||
var ctrl = function ($scope, $timeout, Constraints, $element, _, config, $window) {
|
||||
var ctrl = function (
|
||||
$scope,
|
||||
$timeout,
|
||||
Constraints,
|
||||
$element,
|
||||
_,
|
||||
config,
|
||||
$window,
|
||||
geolib,
|
||||
OutsideOfCommunityDialog
|
||||
) {
|
||||
$scope.config = config;
|
||||
angular.extend($scope, {
|
||||
center: {
|
||||
|
@ -29,6 +39,29 @@ angular.module('ffffng')
|
|||
}
|
||||
});
|
||||
|
||||
if (config.otherCommunityInfo.showBorderForDebugging) {
|
||||
$scope.paths = {
|
||||
border: {
|
||||
color: '#ff0000',
|
||||
weight: 3,
|
||||
latlngs: config.otherCommunityInfo.localCommunityPolygon.concat(
|
||||
[config.otherCommunityInfo.localCommunityPolygon[0]]
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var geolibPolygon = _.map(config.otherCommunityInfo.localCommunityPolygon, function (point) {
|
||||
return {
|
||||
latitude: point.lat,
|
||||
longitude: point.lng
|
||||
};
|
||||
});
|
||||
|
||||
var inCommunityArea = function (lat, lng) {
|
||||
return geolib.isPointInside({latitude: lat, longitude: lng}, geolibPolygon);
|
||||
};
|
||||
|
||||
var updateNodePosition = function (lat, lng) {
|
||||
$scope.markers.node = {
|
||||
lat: lat,
|
||||
|
@ -45,15 +78,17 @@ angular.module('ffffng')
|
|||
$scope.node.coords = lat + ' ' + lng;
|
||||
});
|
||||
|
||||
function withValidCoords(coords, callback) {
|
||||
function withValidCoords(coords, callback, invalidCallback) {
|
||||
invalidCallback = invalidCallback || function () {};
|
||||
|
||||
coords = coords || '';
|
||||
coords = coords.trim();
|
||||
if (_.isEmpty(coords)) {
|
||||
return;
|
||||
return invalidCallback();
|
||||
}
|
||||
|
||||
if ($scope.hasError('coords')) {
|
||||
return;
|
||||
return invalidCallback();
|
||||
}
|
||||
|
||||
var parts = coords.split(/\s+/);
|
||||
|
@ -61,7 +96,7 @@ angular.module('ffffng')
|
|||
var lat = Number(parts[0]);
|
||||
var lng = Number(parts[1]);
|
||||
|
||||
callback(lat, lng);
|
||||
return callback(lat, lng);
|
||||
}
|
||||
|
||||
$scope.updateMap = function (optCoords) {
|
||||
|
@ -90,9 +125,7 @@ angular.module('ffffng')
|
|||
mac: 'Für die MAC-Adresse gibt es bereits einen Eintrag.'
|
||||
};
|
||||
|
||||
$scope.onSubmit = function (node) {
|
||||
submitted = true;
|
||||
|
||||
var doSubmit = function (node) {
|
||||
if ($scope.nodeForm.$invalid) {
|
||||
var firstInvalid = _.filter($element.find('form').find('input'), function (input) {
|
||||
return $scope.nodeForm[input.name].$invalid;
|
||||
|
@ -114,7 +147,27 @@ angular.module('ffffng')
|
|||
}
|
||||
$window.scrollTo(0, 0);
|
||||
});
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
$scope.onSubmit = function (node) {
|
||||
submitted = true;
|
||||
|
||||
withValidCoords(
|
||||
node.coords,
|
||||
function (lat, lng) {
|
||||
if (!config.otherCommunityInfo.showInfo || inCommunityArea(lat, lng)) {
|
||||
doSubmit(node);
|
||||
} else {
|
||||
OutsideOfCommunityDialog.open($scope.action).result.then(function () {
|
||||
doSubmit(node);
|
||||
});
|
||||
}
|
||||
},
|
||||
function () {
|
||||
doSubmit(node);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.updateMap($scope.node.coords);
|
||||
withValidCoords($scope.node.coords, function (lat, lng) {
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('ffffng')
|
||||
.factory('_', function () {
|
||||
return window._;
|
||||
});
|
||||
(function () {
|
||||
var module = angular.module('ffffng');
|
||||
|
||||
function lib(name, windowField) {
|
||||
if (!windowField) {
|
||||
windowField = name;
|
||||
}
|
||||
|
||||
module.factory(name, function () {
|
||||
return window[windowField];
|
||||
});
|
||||
}
|
||||
|
||||
lib('_');
|
||||
lib('geolib');
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue