use geometry WKT for highlighting in search view

also cleans up unused code in details view
This commit is contained in:
Sarah Hoffmann
2012-11-09 22:35:45 +01:00
parent 77bbbd2498
commit cc3e4aa532
3 changed files with 59 additions and 70 deletions

View File

@@ -56,21 +56,13 @@ body {
map.addLayer(new OpenLayers.Layer.OSM.<?php echo CONST_Tile_Default;?>("Default", map.addLayer(new OpenLayers.Layer.OSM.<?php echo CONST_Tile_Default;?>("Default",
{ attribution : '© <a target="_parent" href="http://www.openstreetmap.org">OpenStreetMap</a> and contributors, under an <a target="_parent" href="http://www.openstreetmap.org/copyright">open license</a>'})); { attribution : '© <a target="_parent" href="http://www.openstreetmap.org">OpenStreetMap</a> and contributors, under an <a target="_parent" href="http://www.openstreetmap.org/copyright">open license</a>'}));
var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
layer_style.fillOpacity = 0.2; layer_style.fillOpacity = 0.2;
layer_style.graphicOpacity = 0.2; layer_style.graphicOpacity = 0.2;
vectorLayer = new OpenLayers.Layer.Vector("Points", {style: layer_style}); vectorLayer = new OpenLayers.Layer.Vector("Points", {style: layer_style});
map.addLayer(vectorLayer); map.addLayer(vectorLayer);
var pointList = [];
var style = {
strokeColor: "#75ADFF",
fillColor: "#F0F7FF",
strokeWidth: 2,
strokeOpacity: 0.75,
fillOpacity: 0.75
};
var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326"); var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326");
var proj_map = map.getProjectionObject(); var proj_map = map.getProjectionObject();

View File

@@ -216,40 +216,34 @@ form{
map.panTo(lonLat, 10); map.panTo(lonLat, 10);
} }
function panToLatLonBoundingBox(lat,lon,minlat,maxlat,minlon,maxlon,points) { function panToLatLonBoundingBox(lat,lon,minlat,maxlat,minlon,maxlon,wkt) {
var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326"); vectorLayer.destroyFeatures();
var proj_map = map.getProjectionObject(); var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326");
map.zoomToExtent(new OpenLayers.Bounds(minlon,minlat,maxlon,maxlat).transform(proj_EPSG4326, proj_map)); var proj_map = map.getProjectionObject();
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); map.zoomToExtent(new OpenLayers.Bounds(minlon,minlat,maxlon,maxlat).transform(proj_EPSG4326, proj_map));
var lonLat = new OpenLayers.LonLat(lon, lat).transform(proj_EPSG4326, proj_map);
map.panTo(lonLat, <?php echo $iZoom ?>); map.panTo(lonLat, <?php echo $iZoom ?>);
var pointList = []; if (wkt)
var style = {
strokeColor: "#75ADFF",
fillColor: "#F0F7FF",
strokeWidth: 2,
strokeOpacity: 0.75,
fillOpacity: 0.75
};
var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326");
var proj_map = map.getProjectionObject();
if (points)
{ {
points.each(function(p){ var freader = new OpenLayers.Format.WKT({
pointList.push(new OpenLayers.Geometry.Point(p[0],p[1])); 'internalProjection': proj_map,
}); 'externalProjection': proj_EPSG4326
var linearRing = new OpenLayers.Geometry.LinearRing(pointList).transform(proj_EPSG4326, proj_map);; });
var polygonFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([linearRing]),null,style);
vectorLayer.destroyFeatures(); var feature = freader.read(wkt);
vectorLayer.addFeatures([polygonFeature]); if (feature)
} {
else feature.style = {
{ strokeColor: "#75ADFF",
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); fillColor: "#F0F7FF",
var point = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat); strokeWidth: 2,
var pointFeature = new OpenLayers.Feature.Vector(point,null,style); strokeOpacity: 0.75,
vectorLayer.destroyFeatures(); fillOpacity: 0.75,
vectorLayer.addFeatures([pointFeature]); pointRadius: 100
};
vectorLayer.addFeatures([feature]);
}
} }
} }
@@ -327,7 +321,7 @@ form{
<td valign="center" style="width:400px;"><input id="q" name="q" value="<?php echo htmlspecialchars($sQuery); <td valign="center" style="width:400px;"><input id="q" name="q" value="<?php echo htmlspecialchars($sQuery);
?>" style="width:270px;"><input type="text" id="viewbox" style="width:130px;" name="viewbox"></td> ?>" style="width:270px;"><input type="text" id="viewbox" style="width:130px;" name="viewbox"></td>
<td style="width:80px;"><input type="submit" value="Search"></td> <td style="width:80px;"><input type="submit" value="Search"></td>
<?php if (CONST_Search_AreaPolygons) { ?> <td style="width:100px;"><input type="checkbox" value="1" name="polygon" <?php if ($bShowPolygons) echo "checked"; ?>> Highlight</td> <?php if (CONST_Search_AreaPolygons) { ?> <td style="width:100px;"><input type="checkbox" value="1" name="polygon" <?php if ($bAsText) echo "checked"; ?>> Highlight</td>
<td style="text-align:right;">Data: <?php echo $sDataDate; ?></td> <td style="text-align:right;">Data: <?php echo $sDataDate; ?></td>
<td style="text-align:right;"> <td style="text-align:right;">
<a href="http://wiki.openstreetmap.org/wiki/Nominatim" target="_blank">Documentation</a> | <a href="http://wiki.openstreetmap.org/wiki/Nominatim/FAQ" <a href="http://wiki.openstreetmap.org/wiki/Nominatim" target="_blank">Documentation</a> | <a href="http://wiki.openstreetmap.org/wiki/Nominatim/FAQ"
@@ -359,8 +353,8 @@ target="_blank">FAQ</a></td>
echo ', '.$aResult['aBoundingBox'][1]; echo ', '.$aResult['aBoundingBox'][1];
echo ', '.$aResult['aBoundingBox'][2]; echo ', '.$aResult['aBoundingBox'][2];
echo ', '.$aResult['aBoundingBox'][3]; echo ', '.$aResult['aBoundingBox'][3];
if (isset($aResult['aPolyPoints'])) echo ', '.json_encode($aResult['aPolyPoints']); if (isset($aResult['astext'])) echo ', "'.$aResult['astext'].'"';
echo ');\'>'; echo ");'>\n";
} }
elseif (isset($aResult['zoom'])) elseif (isset($aResult['zoom']))
{ {
@@ -451,11 +445,7 @@ init();
echo ', '.$aResult['aBoundingBox'][1]; echo ', '.$aResult['aBoundingBox'][1];
echo ', '.$aResult['aBoundingBox'][2]; echo ', '.$aResult['aBoundingBox'][2];
echo ', '.$aResult['aBoundingBox'][3]; echo ', '.$aResult['aBoundingBox'][3];
if (isset($aResult['aPolyPoints'])) if (isset($aResult['astext'])) echo ", '".$aResult['astext']."'";
{
echo ', ';
echo javascript_renderData($aResult['aPolyPoints']);
}
echo ');'."\n"; echo ');'."\n";
} }
else else

View File

@@ -32,22 +32,30 @@
// Show / use polygons // Show / use polygons
$bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon']; $bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon'];
$bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson']; if ($sOutputFormat == 'html') {
$bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml']; $bAsText = $bShowPolygons;
$bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg']; $bShowPolygons = false;
$bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text']; $bAsGeoJSON = false;
if ((($bShowPolygons?1:0) $bAsKML = false;
+ ($bAsGeoJSON?1:0) $bAsSVG = false;
+ ($bAsKML?1:0) } else {
+ ($bAsSVG?1:0) $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson'];
+ ($bAsText?1:0) $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml'];
) > CONST_PolygonOutput_MaximumTypes) { $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg'];
if (CONST_PolygonOutput_MaximumTypes) { $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text'];
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option"); if ((($bShowPolygons?1:0)
} else { + ($bAsGeoJSON?1:0)
userError("Polygon output is disabled"); + ($bAsKML?1:0)
+ ($bAsSVG?1:0)
+ ($bAsText?1:0)
) > CONST_PolygonOutput_MaximumTypes) {
if (CONST_PolygonOutput_MaximumTypes) {
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} else {
userError("Polygon output is disabled");
}
exit;
} }
exit;
} }
// Show address breakdown // Show address breakdown
@@ -1228,8 +1236,7 @@
if ($bAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson"; if ($bAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson";
if ($bAsKML) $sSQL .= ",ST_AsKML(geometry) as askml"; if ($bAsKML) $sSQL .= ",ST_AsKML(geometry) as askml";
if ($bAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg"; if ($bAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg";
if ($bAsText) $sSQL .= ",ST_AsText(geometry) as astext"; if ($bAsText || $bShowPolygons) $sSQL .= ",ST_AsText(geometry) as astext";
if ($bShowPolygons) $sSQL .= ",ST_AsText(geometry) as outlinestring";
$sSQL .= " from placex where place_id = ".$aResult['place_id'].' and st_geometrytype(Box2D(geometry)) = \'ST_Polygon\''; $sSQL .= " from placex where place_id = ".$aResult['place_id'].' and st_geometrytype(Box2D(geometry)) = \'ST_Polygon\'';
$aPointPolygon = $oDB->getRow($sSQL); $aPointPolygon = $oDB->getRow($sSQL);
if (PEAR::IsError($aPointPolygon)) if (PEAR::IsError($aPointPolygon))
@@ -1250,15 +1257,15 @@
if ($bShowPolygons) if ($bShowPolygons)
{ {
// Translate geometary string to point array // Translate geometary string to point array
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch)) if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['astext'],$aMatch))
{ {
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER); preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
} }
elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$aPointPolygon['outlinestring'],$aMatch)) elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$aPointPolygon['astext'],$aMatch))
{ {
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER); preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
} }
elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['outlinestring'],$aMatch)) elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['astext'],$aMatch))
{ {
$fRadius = 0.01; $fRadius = 0.01;
$iSteps = ($fRadius * 40000)^2; $iSteps = ($fRadius * 40000)^2;