Procházet zdrojové kódy

TableAjaxMap: use bbox filter in wfs, test strategy cluster

Piotr Labudda před 11 roky
rodič
revize
39f0771f62
1 změnil soubory, kde provedl 62 přidání a 81 odebrání
  1. 62 81
      SE/se-lib/TableAjaxMap.php

+ 62 - 81
SE/se-lib/TableAjaxMap.php

@@ -134,7 +134,7 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			priv.getCapabilities();
 
 			_layer = new OpenLayers.Layer.Vector(priv.options.layerName, {
-				strategies: [new OpenLayers.Strategy.BBOX()],
+				strategies: [new OpenLayers.Strategy.BBOX(), new OpenLayers.Strategy.Cluster({distance:30, threshold:3})],
 				projection: new OpenLayers.Projection("EPSG:4326"),
 				protocol: new OpenLayers.Protocol.WFS({
 					version: "1.1.0",
@@ -151,15 +151,17 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 							new OpenLayers.Rule({
 								symbolizer: {
 									stroke: true,
+									strokeWidth: 3,
 									fill: true,
-									fillColor: "#90EE90",
-									strokeColor: "#90EE90",
+									fillColor: "#ee9900",
+									strokeColor: "#ee9900",
 								}
 							})
 							, new OpenLayers.Rule({
 								symbolizer: {
 									stroke: true,
 									fill: true,
+									strokeWidth: 3,
 									fillColor: "#ee9900",
 									strokeColor: "#ee9900",
 								},
@@ -173,6 +175,7 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 								symbolizer: {
 									stroke: true,
 									fill: true,
+									strokeWidth: 3,
 									fillColor: "#ff0000",
 									strokeColor: "#ff0000",
 								},
@@ -186,6 +189,7 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 								symbolizer: {
 									stroke: true,
 									fill: true,
+									strokeWidth: 3,
 									fillColor: "#ff0000",
 									strokeColor: "#ff0000",
 								},
@@ -875,7 +879,7 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			$urlQuery[$parts[0]] = $parts[1];
 		}
 
-		$wpsServer = new TableAjaxMapWpsServer($this->_zasobID);
+		$wpsServer = new TableAjaxMapWpsServer($this->_acl);
 		if ('WPS' == V::get('SERVICE', '', $urlQuery)) {
 			$req = V::get('REQUEST', '', $urlQuery);
 			$methodName = "{$req}Action";
@@ -894,10 +898,12 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 
 class TableAjaxMapWfsAction {
 
+	private $_acl;
 	private $_zasobID;
 
-	public function __construct($zasobID) {
-		$this->_zasobID = $zasobID;
+	public function __construct($acl) {
+		$this->_acl = $acl;
+		$this->_zasobID = $acl->getID();
 	}
 
 	/**
@@ -959,16 +965,23 @@ class TableAjaxMapWfsAction {
 					18.614273071289062 54.33634445792519
 					18.614273071289062 54.33614429135817
 		 */
+		Lib::loadClass('Data_Source');
+		$dataSource = new Data_Source($this->_acl->getDB());
+		$dataSource->setTable($this->_acl->getName());
+		$dataSource->addCol('ID');
+		$dataSource->addCol('the_geom');
+		$dataSource->setColTypes($this->_acl->getTypes());
+
+		$params = array();
+		$params['limit'] = 1000;
+		if (!empty($args['BBOX'])) {
+			$params['f_the_geom'] = 'BBOX:' . implode(',', $args['BBOX']);
+		}
+		$items = $dataSource->getItems($params);
+
 		$buildingsGml = array();
-		$db = DB::getDB();
-		if ($this->_zasobID == 16) {// TODO: read by TableAcl from Data_Source?
-			$sql = "select b.`ID`, AsWKT(b.`the_geom`) as the_geom
-				from `BUILDINGS` as b
-				where b.`the_geom` is not null and b.`the_geom`!=''
-				limit 10;
-			";
-			$res = $db->query($sql);
-			while ($r = $db->fetch($res)) {
+		foreach ($items as $r) {
+			if (!empty($r->the_geom)) {
 				$buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
 			}
 		}
@@ -987,58 +1000,6 @@ class TableAjaxMapWfsAction {
 		echo '<?xml version="1.0" encoding="UTF-8"?>';
 		?>
 <wfs:FeatureCollection xmlns:nasa="http://nasa.gov" xmlns:topp="http://www.openplans.org/topp" xmlns:usgs="http://www.usgs.gov/" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:ne="http://naturalearthdata.com" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:osm="http://openstreemap.org" xmlns:nurc="http://www.nurc.nato.int" xmlns:og="http://opengeo.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="4" timeStamp="2014-07-16T13:22:43.307Z" xsi:schemaLocation="http://opengeo.org http://demo.opengeo.org:80/geoserver/wfs?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typeName=og%3Arestricted http://www.opengis.net/wfs http://demo.opengeo.org:80/geoserver/schemas/wfs/1.1.0/wfs.xsd">
-<!--
-<?php
-/*
- * gdańsk
-		<gml:lowerCorner>17.226562502593 53.887024366231</gml:lowerCorner>
-		<gml:upperCorner>20.039062502593 54.847089981191</gml:upperCorner>
- * chełm CI50, 58, 56 i większa część 54
-		<gml:lowerCorner>18.607629912267 54.334071453085</gml:lowerCorner>
-		<gml:upperCorner>18.618616240393 54.337824603267</gml:upperCorner>
- * chełm CI50, 58, 56 i mniejsza część 54
-		<gml:lowerCorner>18.607297318347 54.334218457914</gml:lowerCorner>
-		<gml:upperCorner>18.618283646473 54.337971594678</gml:upperCorner>
- */
-$bounds = "Polygon((17.226562502593 53.887024366231, 20.039062502593 54.847089981191))";
-
-$bounds = "POLYGON((
-	18.61292099002325 54.33645952913529,
-	18.612985363039602 54.33478310873356,
-	18.616246929201676 54.33477685330538,
-	18.61613964084169 54.336309404721554,
-	18.61292099002325 54.33645952913529
-))";
-$bounds = "POLYGON((
-	17.226562502593 53.887024366231,
-17.226562502593 54.847089981191,
-	20.039062502593 54.847089981191,
-20.039062502593 53.887024366231,
-	17.226562502593 53.887024366231
-))";
-$bounds = "POLYGON((
-	18.607297318347 54.334218457914,
-18.607297318347 54.337971594678,
-	18.618283646473 54.337971594678,
-18.618283646473 54.334218457914,
-	18.607297318347 54.334218457914
-))";
-$sql = "select t.`ID`
-		, t.`S_ADDRESS_STREET`
-		, AsWKT(t.`the_geom`) as the_geomWKT
-		, AsWKT(GeomFromText('{$bounds}')) as boundsWKT
-		, MBRWithin(GeomFromText('{$bounds}'), GeomFromText(AsWKT(t.`the_geom`))) as isInside
-		, MBRWithin(GeomFromText(AsWKT(t.`the_geom`)), GeomFromText('{$bounds}')) as isInside2
-	from `BUILDINGS` as t
-	where t.`the_geom` is not null
-	limit 10 ";
-echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."\n";print_r($sql);echo "\n".'</pre>';
-$res = $db->query($sql);
-while ($r = $db->fetch($res)) {
-	echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($r);echo'</pre>';
-}
-?>
--->
   <gml:boundedBy>
     <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
       <gml:lowerCorner>-180 -90</gml:lowerCorner>
@@ -1101,11 +1062,13 @@ class TableAjaxMapWpsServer {
 	private $_fun;// config for identifiers
 	private $_wfsAction;
 	private $_zasobID;
+	private $_acl;
 
-	public function __construct($zasobID) {
+	public function __construct($acl) {
 		$this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
-		$this->_wfsAction = new TableAjaxMapWfsAction($zasobID);
-		$this->_zasobID = $zasobID;
+		$this->_acl = $acl;
+		$this->_zasobID = $acl->getID();
+		$this->_wfsAction = new TableAjaxMapWfsAction($this->_acl);
 	}
 
 	public function parseXMLRequest() {
@@ -1130,21 +1093,39 @@ class TableAjaxMapWpsServer {
   </wfs:Query>
 </wfs:GetFeature>
 			 */
-			
-			$corners = $xml->children("wfs", TRUE)->Query->children("ogc", TRUE)->Filter->BBOX->children("gml", TRUE)->Envelope;
+			$corners = null;
+			$xmlTag = $xml->children("wfs", TRUE)->Query;
+			if (!empty($xmlTag)) {
+				$xmlTag = $xmlTag->children("ogc", TRUE)->Filter;
+				if (!empty($xmlTag)) {
+					$xmlTag = $xmlTag->BBOX;
+					if (!empty($xmlTag)) {
+						$xmlTag = $xmlTag->children("gml", TRUE)->Envelope;
+						if (!empty($xmlTag)) {
+							$corners = (object)array('lowerCorner' => (string)$xmlTag->lowerCorner, 'upperCorner' => (string)$xmlTag->upperCorner);
+						}
+					}
+				}
+			}
 
 			if ($corners) {
 				$lowerCorner = (string) $corners->lowerCorner;	
 				$upperCorner = (string) $corners->upperCorner;
-				$lowerCornerArray = explode(" ", $lowerCorner);
-				$upperCornerArray = explode(" ", $upperCorner);
-				if(count($lowerCornerArray) == 2 && count($upperCornerArray) == 2) {
-					$lowerCornerDouble = (double) $lowerCornerArray[0];
-					$upperCornerDouble = (double) $upperCornerArray[1];
-						if(($lowerCorner == (string) $lowerCornerDouble) && ($upperCorner == (string) $upperCornerDouble)) {
-							$data[lowerCorner] = $lowerCorner;
-							$data[upperCorner] = $upperCorner;
-						}
+				$lowerCorner = explode(" ", trim($lowerCorner));
+				$upperCorner = explode(" ", trim($upperCorner));
+				if (count($lowerCorner) == 2 && count($upperCorner) == 2) {
+					$points = array();
+					$points[] = $upperCorner[1];// top
+					$points[] = $upperCorner[0];// right
+					$points[] = $lowerCorner[1];// bottom
+					$points[] = $lowerCorner[0];// left
+					$isAllNumeric = true;
+					foreach ($points as $point) {
+						if (!is_numeric($point)) $isAllNumeric = false;
+					}
+					if ($isAllNumeric) {
+						$data['BBOX'] = $points;
+					}
 				}
 			} else {
 				// inna struktura xml'a