- $fHeight = $this->aViewBox[0]-$this->aViewBox[2];
- $fWidth = $this->aViewBox[1]-$this->aViewBox[3];
- $aBigViewBox[0] = $this->aViewBox[0] + $fHeight;
- $aBigViewBox[2] = $this->aViewBox[2] - $fHeight;
- $aBigViewBox[1] = $this->aViewBox[1] + $fWidth;
- $aBigViewBox[3] = $this->aViewBox[3] - $fWidth;
-
- $this->sViewboxSmallSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$this->aViewBox[0].",".(float)$this->aViewBox[1]."),ST_Point(".(float)$this->aViewBox[2].",".(float)$this->aViewBox[3].")),4326)";
- $this->sViewboxLargeSQL = "ST_SetSRID(ST_MakeBox2D(ST_Point(".(float)$aBigViewBox[0].",".(float)$aBigViewBox[1]."),ST_Point(".(float)$aBigViewBox[2].",".(float)$aBigViewBox[3].")),4326)";
- $bBoundingBoxSearch = $this->bBoundedSearch;
- }
-
- // Route SQL
- if ($this->aRoutePoints)
- {
- $sViewboxCentreSQL = "ST_SetSRID('LINESTRING(";
- $bFirst = true;
- foreach($this->aRoutePoints as $aPoint)
- {
- if (!$bFirst) $sViewboxCentreSQL .= ",";
- $sViewboxCentreSQL .= $aPoint[0].' '.$aPoint[1];
- $bFirst = false;
- }
- $sViewboxCentreSQL .= ")'::geometry,4326)";
-
- $sSQL = "select st_buffer(".$sViewboxCentreSQL.",".(float)($_GET['routewidth']/69).")";
- $this->sViewboxSmallSQL = $this->oDB->getOne($sSQL);
- if (PEAR::isError($this->sViewboxSmallSQL))
- {
- failInternalError("Could not get small viewbox.", $sSQL, $this->sViewboxSmallSQL);
- }
- $this->sViewboxSmallSQL = "'".$this->sViewboxSmallSQL."'::geometry";
-
- $sSQL = "select st_buffer(".$sViewboxCentreSQL.",".(float)($_GET['routewidth']/30).")";
- $this->sViewboxLargeSQL = $this->oDB->getOne($sSQL);
- if (PEAR::isError($this->sViewboxLargeSQL))
- {
- failInternalError("Could not get large viewbox.", $sSQL, $this->sViewboxLargeSQL);
- }
- $this->sViewboxLargeSQL = "'".$this->sViewboxLargeSQL."'::geometry";
- $bBoundingBoxSearch = $this->bBoundedSearch;
+ // For complex viewboxes (routes) precompute the bounding geometry
+ $sGeom = chksql($this->oDB->getOne("select ".$this->sViewboxSmallSQL),
+ "Could not get small viewbox");
+ $this->sViewboxSmallSQL = "'".$sGeom."'::geometry";
+
+ $sGeom = chksql($this->oDB->getOne("select ".$this->sViewboxLargeSQL),
+ "Could not get large viewbox");
+ $this->sViewboxLargeSQL = "'".$sGeom."'::geometry";