Avoid code duplication
This commit is contained in:
parent
338756306b
commit
1e8914fe50
@ -156,5 +156,45 @@ abstract class PMA_GIS_Geometry
|
||||
|
||||
return $points_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates JavaScriipt for adding points for OpenLayers polygon.
|
||||
*
|
||||
* @param string $polygon points of a polygon in WKT form
|
||||
* @param string $srid spatial reference id
|
||||
*
|
||||
* @return JavaScriipt for adding points for OpenLayers polygon
|
||||
*/
|
||||
protected function addPointsForOpenLayersPolygon($polygon, $srid)
|
||||
{
|
||||
$row = 'new OpenLayers.Geometry.Polygon(new Array(';
|
||||
// If the polygon doesnt have an inner polygon
|
||||
if (strpos($polygon, "),(") === false) {
|
||||
$points_arr = $this->extractPoints($polygon, null);
|
||||
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
|
||||
foreach ($points_arr as $point) {
|
||||
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] . '))'
|
||||
. '.transform(new OpenLayers.Projection("EPSG:' . $srid . '"), map.getProjectionObject()), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= '))';
|
||||
} else {
|
||||
// Seperate outer and inner polygons
|
||||
$parts = explode("),(", $polygon);
|
||||
foreach ($parts as $ring) {
|
||||
$points_arr = $this->extractPoints($ring, null);
|
||||
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
|
||||
foreach ($points_arr as $point) {
|
||||
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] . '))'
|
||||
. '.transform(new OpenLayers.Projection("EPSG:' . $srid . '"), map.getProjectionObject()), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= ')), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
}
|
||||
$row .= ')), ';
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -257,33 +257,7 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry
|
||||
. 'new OpenLayers.Geometry.MultiPolygon(new Array(';
|
||||
|
||||
foreach ($polygons as $polygon) {
|
||||
$row .= 'new OpenLayers.Geometry.Polygon(new Array(';
|
||||
// If the polygon doesnt have an inner polygon
|
||||
if (strpos($polygon, "),(") === false) {
|
||||
$points_arr = $this->extractPoints($polygon, null);
|
||||
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
|
||||
foreach ($points_arr as $point) {
|
||||
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] . '))'
|
||||
. '.transform(new OpenLayers.Projection("EPSG:' . $srid . '"), map.getProjectionObject()), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= '))';
|
||||
} else {
|
||||
// Seperate outer and inner polygons
|
||||
$parts = explode("),(", $polygon);
|
||||
foreach ($parts as $ring) {
|
||||
$points_arr = $this->extractPoints($ring, null);
|
||||
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
|
||||
foreach ($points_arr as $point) {
|
||||
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] . '))'
|
||||
. '.transform(new OpenLayers.Projection("EPSG:' . $srid . '"), map.getProjectionObject()), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= ')), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
}
|
||||
$row .= ')), ';
|
||||
$row .= $this->addPointsForOpenLayersPolygon($polygon, $srid);
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= ')), null, ' . json_encode($style_options) . '));';
|
||||
|
||||
@ -234,34 +234,9 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry
|
||||
// Trim to remove leading 'POLYGON((' and trailing '))'
|
||||
$polygon = substr($spatial, 9, (strlen($spatial) - 11));
|
||||
|
||||
$row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
|
||||
. 'new OpenLayers.Geometry.Polygon(new Array(';
|
||||
// If the polygon doesnt have an inner polygon
|
||||
if (strpos($polygon, "),(") === false) {
|
||||
$points_arr = $this->extractPoints($polygon, null);
|
||||
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
|
||||
foreach ($points_arr as $point) {
|
||||
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] . '))'
|
||||
. '.transform(new OpenLayers.Projection("EPSG:' . $srid . '"), map.getProjectionObject()), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= '))';
|
||||
} else {
|
||||
// Seperate outer and inner polygons
|
||||
$parts = explode("),(", $polygon);
|
||||
foreach ($parts as $ring) {
|
||||
$points_arr = $this->extractPoints($ring, null);
|
||||
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
|
||||
foreach ($points_arr as $point) {
|
||||
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] . '))'
|
||||
. '.transform(new OpenLayers.Projection("EPSG:' . $srid . '"), map.getProjectionObject()), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
$row .= ')), ';
|
||||
}
|
||||
$row = substr($row, 0, strlen($row) - 2);
|
||||
}
|
||||
$row .= ')), null, ' . json_encode($style_options) . '));';
|
||||
$row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(';
|
||||
$row .= $this->addPointsForOpenLayersPolygon($polygon, $srid);
|
||||
$row .= 'null, ' . json_encode($style_options) . '));';
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user