From: Sarah Hoffmann Date: Fri, 9 Nov 2012 21:35:45 +0000 (+0100) Subject: use geometry WKT for highlighting in search view X-Git-Tag: v2.2.0~181 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/cc3e4aa532559b5c8948152fb6d4ab68da22fe28?hp=77bbbd24983356f388d1ae1ad2dc44a8472c3ce2 use geometry WKT for highlighting in search view also cleans up unused code in details view --- diff --git a/lib/template/details-html.php b/lib/template/details-html.php index 9c967fff..f20ec619 100644 --- a/lib/template/details-html.php +++ b/lib/template/details-html.php @@ -56,21 +56,13 @@ body { map.addLayer(new OpenLayers.Layer.OSM.("Default", { attribution : '© OpenStreetMap and contributors, under an open license'})); - var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); - layer_style.fillOpacity = 0.2; - layer_style.graphicOpacity = 0.2; + var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); + layer_style.fillOpacity = 0.2; + layer_style.graphicOpacity = 0.2; vectorLayer = new OpenLayers.Layer.Vector("Points", {style: layer_style}); 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_map = map.getProjectionObject(); diff --git a/lib/template/search-html.php b/lib/template/search-html.php index 7698ebd0..3fd8096d 100644 --- a/lib/template/search-html.php +++ b/lib/template/search-html.php @@ -216,40 +216,34 @@ form{ map.panTo(lonLat, 10); } - function panToLatLonBoundingBox(lat,lon,minlat,maxlat,minlon,maxlon,points) { - var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326"); - var proj_map = map.getProjectionObject(); - map.zoomToExtent(new OpenLayers.Bounds(minlon,minlat,maxlon,maxlat).transform(proj_EPSG4326, proj_map)); - var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); + function panToLatLonBoundingBox(lat,lon,minlat,maxlat,minlon,maxlon,wkt) { + vectorLayer.destroyFeatures(); + var proj_EPSG4326 = new OpenLayers.Projection("EPSG:4326"); + var proj_map = 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, ); - 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_map = map.getProjectionObject(); - if (points) - { - points.each(function(p){ - pointList.push(new OpenLayers.Geometry.Point(p[0],p[1])); - }); - 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(); - vectorLayer.addFeatures([polygonFeature]); - } - else + if (wkt) { - var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); - var point = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat); - var pointFeature = new OpenLayers.Feature.Vector(point,null,style); - vectorLayer.destroyFeatures(); - vectorLayer.addFeatures([pointFeature]); + var freader = new OpenLayers.Format.WKT({ + 'internalProjection': proj_map, + 'externalProjection': proj_EPSG4326 + }); + + var feature = freader.read(wkt); + if (feature) + { + feature.style = { + strokeColor: "#75ADFF", + fillColor: "#F0F7FF", + strokeWidth: 2, + strokeOpacity: 0.75, + fillOpacity: 0.75, + pointRadius: 100 + }; + vectorLayer.addFeatures([feature]); + } } } @@ -327,7 +321,7 @@ form{ - > Highlight + > Highlight Data: Documentation | FAQ echo ', '.$aResult['aBoundingBox'][1]; echo ', '.$aResult['aBoundingBox'][2]; echo ', '.$aResult['aBoundingBox'][3]; - if (isset($aResult['aPolyPoints'])) echo ', '.json_encode($aResult['aPolyPoints']); - echo ');\'>'; + if (isset($aResult['astext'])) echo ', "'.$aResult['astext'].'"'; + echo ");'>\n"; } elseif (isset($aResult['zoom'])) { @@ -451,11 +445,7 @@ init(); echo ', '.$aResult['aBoundingBox'][1]; echo ', '.$aResult['aBoundingBox'][2]; echo ', '.$aResult['aBoundingBox'][3]; - if (isset($aResult['aPolyPoints'])) - { - echo ', '; - echo javascript_renderData($aResult['aPolyPoints']); - } + if (isset($aResult['astext'])) echo ", '".$aResult['astext']."'"; echo ');'."\n"; } else diff --git a/website/search.php b/website/search.php index 3272aff3..d0b183ea 100755 --- a/website/search.php +++ b/website/search.php @@ -32,22 +32,30 @@ // Show / use polygons $bShowPolygons = (boolean)isset($_GET['polygon']) && $_GET['polygon']; - $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson']; - $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml']; - $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg']; - $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text']; - if ((($bShowPolygons?1:0) - + ($bAsGeoJSON?1:0) - + ($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"); + if ($sOutputFormat == 'html') { + $bAsText = $bShowPolygons; + $bShowPolygons = false; + $bAsGeoJSON = false; + $bAsKML = false; + $bAsSVG = false; + } else { + $bAsGeoJSON = (boolean)isset($_GET['polygon_geojson']) && $_GET['polygon_geojson']; + $bAsKML = (boolean)isset($_GET['polygon_kml']) && $_GET['polygon_kml']; + $bAsSVG = (boolean)isset($_GET['polygon_svg']) && $_GET['polygon_svg']; + $bAsText = (boolean)isset($_GET['polygon_text']) && $_GET['polygon_text']; + if ((($bShowPolygons?1:0) + + ($bAsGeoJSON?1:0) + + ($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 @@ -1228,8 +1236,7 @@ if ($bAsGeoJSON) $sSQL .= ",ST_AsGeoJSON(geometry) as asgeojson"; if ($bAsKML) $sSQL .= ",ST_AsKML(geometry) as askml"; if ($bAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg"; - if ($bAsText) $sSQL .= ",ST_AsText(geometry) as astext"; - if ($bShowPolygons) $sSQL .= ",ST_AsText(geometry) as outlinestring"; + if ($bAsText || $bShowPolygons) $sSQL .= ",ST_AsText(geometry) as astext"; $sSQL .= " from placex where place_id = ".$aResult['place_id'].' and st_geometrytype(Box2D(geometry)) = \'ST_Polygon\''; $aPointPolygon = $oDB->getRow($sSQL); if (PEAR::IsError($aPointPolygon)) @@ -1250,15 +1257,15 @@ if ($bShowPolygons) { // 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); } - 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); } - 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; $iSteps = ($fRadius * 40000)^2;