diff --git a/Layout/default/Building/Index.php b/Layout/default/Building/Index.php index b70bd4afc..76b468b26 100644 --- a/Layout/default/Building/Index.php +++ b/Layout/default/Building/Index.php @@ -90,12 +90,25 @@ ">Filter zurücksetzen + - + +
+
+ + +
+
@@ -331,8 +344,8 @@
- - + + \ No newline at end of file diff --git a/Layout/default/header.php b/Layout/default/header.php index 20ac0f942..ea2abd168 100644 --- a/Layout/default/header.php +++ b/Layout/default/header.php @@ -18,12 +18,13 @@ - + - - + + + diff --git a/application/Building/BuildingController.php b/application/Building/BuildingController.php index fdef97106..414d6b54f 100644 --- a/application/Building/BuildingController.php +++ b/application/Building/BuildingController.php @@ -341,4 +341,44 @@ class BuildingController extends mfBaseController { } + protected function apiAction() { + if(!$this->me->is(["Admin","netowner","pipeplanner"])) { + $this->redirect("Dashboard"); + } + $do = $this->request->do; + $data = []; + + switch($do) { + case "findBuildings": + $return = $this->findBuildingsApi(); + break; + default: + $return = false; + } + + if(!is_array($return) || !count($return)) { + $data = ["status" => "error"]; + $this->returnJson($data); + } + $data['status'] = "OK"; + $data['result'] = $return; + $this->returnJson($data); + } + + private function findBuildingsApi() { + $buildings = []; + $filter = $this->request->filter; + + + $results = BuildingModel::search($filter); + + foreach($results as $building) { + $data = $building->data; + $data->id = $building->id; + $buildings[] = $data; + } + + return ["buildings" => $buildings]; + } + } diff --git a/public/assets/js/geo/geo.js b/public/assets/js/geo/geo.js new file mode 100644 index 000000000..634aec4aa --- /dev/null +++ b/public/assets/js/geo/geo.js @@ -0,0 +1,90 @@ +function rad2degr(rad) { return rad * 180 / Math.PI; } +function degr2rad(degr) { return degr * Math.PI / 180; } + +/** + * @param latLngInDeg array of arrays with latitude and longtitude + * pairs in degrees. e.g. [[latitude1, longtitude1], [latitude2 + * [longtitude2] ...] + * + * @return array with the center latitude longtitude pairs in + * degrees. + */ +function getLatLngCenter(latLngInDegr) { + var LATIDX = 0; + var LNGIDX = 1; + var sumX = 0; + var sumY = 0; + var sumZ = 0; + + for (var i=0; i array(45.849382, 76.322333), + * 1 = > array(45.843543, 75.324143), + * 2 = > array(45.765744, 76.543223), + * 3 = > array(45.784234, 74.542335) + * ); +*/ +function GetCenterFromDegrees(data) +{ + if (!(data.length > 0)){ + return false; + } + + var num_coords = data.length; + + var X = 0.0; + var Y = 0.0; + var Z = 0.0; + + for(i = 0; i < data.length; i++){ + var lat = data[i][0] * Math.PI / 180; + var lon = data[i][1] * Math.PI / 180; + + var a = Math.cos(lat) * Math.cos(lon); + var b = Math.cos(lat) * Math.sin(lon); + var c = Math.sin(lat); + + X += a; + Y += b; + Z += c; + } + + X /= num_coords; + Y /= num_coords; + Z /= num_coords; + + var lon = Math.atan2(Y, X); + var hyp = Math.sqrt(X * X + Y * Y); + var lat = Math.atan2(Z, hyp); + + var newX = (lat * 180 / Math.PI); + var newY = (lon * 180 / Math.PI); + + return new Array(newX, newY); +} \ No newline at end of file