|
@@ -7,6 +7,7 @@ use StatsBundle\Services\DeviceManager;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
class StatsController extends Controller
|
|
class StatsController extends Controller
|
|
{
|
|
{
|
|
@@ -109,4 +110,100 @@ class StatsController extends Controller
|
|
));
|
|
));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @Route("/admin/stats/onu/stats/map", name="onu_stats_map")
|
|
|
|
+ *
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ public function showMapAction(Request $request)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ $map = array();
|
|
|
|
+ $map['zoom'] = 12;
|
|
|
|
+ $map['lng'] = -60.065884467624294;
|
|
|
|
+ $map['lat'] = -33.902661208376706;
|
|
|
|
+
|
|
|
|
+ $em = $this->get('doctrine')->getManager();
|
|
|
|
+ $adminPool = $this->get('sonata.admin.pool');
|
|
|
|
+
|
|
|
|
+ $api = $this->get('geoserver.api');
|
|
|
|
+ $data = $api->getLayerData("deviceServer_1", "onu_stats_tenancy_1");
|
|
|
|
+
|
|
|
|
+ $setLatLng = $setZoom = false;
|
|
|
|
+
|
|
|
|
+ if(!empty($data)) {
|
|
|
|
+ if(isset($data['featureType']['latLonBoundingBox'])) {
|
|
|
|
+ $setLatLng = $setZoom = true;
|
|
|
|
+ $srs = $data['featureType']['latLonBoundingBox'];
|
|
|
|
+ } elseif(isset($data['featureType']['nativeBoundingBox'])) {
|
|
|
|
+ $setLatLng = $setZoom = true;
|
|
|
|
+ $srs = $data['featureType']['nativeBoundingBox'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($setLatLng) {
|
|
|
|
+ $lng = $srs['minx'] + ($srs['maxx'] - $srs['minx']) / 2;
|
|
|
|
+ $lat = $srs['miny'] + ($srs['maxy'] - $srs['miny']) / 2;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($setZoom) {
|
|
|
|
+ $lngDiff = $srs['maxx'] - $srs['minx'];
|
|
|
|
+ $latDiff = $srs['maxy'] - $srs['miny'];
|
|
|
|
+ $maxDiff = ($lngDiff > $latDiff) ? $lngDiff : $latDiff;
|
|
|
|
+ if ($maxDiff < 360 / pow(2, 20)) {
|
|
|
|
+ $zoom = 21;
|
|
|
|
+ } else {
|
|
|
|
+ $zoom = (-1*( (log($maxDiff)/log(2)) - (log(360)/log(2)))) + 1;
|
|
|
|
+ if ($zoom < 1) $zoom = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $map = array('lat' => $lat, 'lng' => $lng, 'zoom' => $zoom);
|
|
|
|
+
|
|
|
|
+ /* print_r("<pre>");
|
|
|
|
+ print_r($data);
|
|
|
|
+ die; */
|
|
|
|
+
|
|
|
|
+ return $this->render('StatsBundle:Stats:onu_map.html.twig', array(
|
|
|
|
+ 'base_template' => $adminPool->getTemplate('layout'),
|
|
|
|
+ 'admin_pool' => $adminPool,
|
|
|
|
+ 'admin' => $adminPool->getAdminByClass("StatsBundle\Entity\Onu"),
|
|
|
|
+ 'map' => $map
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Route("/admin/stats/onu/stats/api_feature_json", name="api_feature_json")
|
|
|
|
+ *
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ public function apiFeatureJsonAction(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $params = $request->query->all();
|
|
|
|
+ $data = explode(":",$params['LAYERS']);
|
|
|
|
+
|
|
|
|
+ $workspace = $data[0];
|
|
|
|
+
|
|
|
|
+ $api = $this->get('geoserver.api');
|
|
|
|
+ $return = $api->getFeature($workspace, $params);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $data = json_decode($return,true);
|
|
|
|
+
|
|
|
|
+ $return = array();
|
|
|
|
+
|
|
|
|
+ if(isset($data['features'])) {
|
|
|
|
+ $return = json_encode($data['features'][0]['properties']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $response = new Response(
|
|
|
|
+ $return,
|
|
|
|
+ Response::HTTP_OK,
|
|
|
|
+ array('content-type' => 'application/json')
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return $response;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|