Oracle Maps und APEX seit der Version 4.0 verwenden das JSON - Format zum direkten Datenzugriff aus der Datenbank und effizienten Verarbeitung in Javascript. Dieses Format hat sich auf Grund seiner Kompaktheit, guten Lesbarkeit und der direkten Ansprechbarkeit in Javascript als implizite JavaScript-Objektnotation in der WebBrowser-Technologie recht gut durchgesetzt.
CREATE OR REPLACE PROCEDURE get_simple_geojson_2 (p_x number, p_y number) IS
l_state varchar2(2);
FUNCTION fnc_get_state(p_x NUMBER, p_y NUMBER )
RETURN varchar2 IS
li_state varchar2(2);
BEGIN
SELECT /*+ ORDERD */
s.STATE_ABRV
into li_state
FROM states s
WHERE SDO_RELATE(s.geom,
SDO_GEOMETRY(2001,
8307,
SDO_POINT_TYPE(p_x, p_y, NULL),
NULL,
NULL),
'mask=CONTAINS') = 'TRUE'
AND ROWNUM<2;
RETURN(li_state);
EXCEPTION
WHEN OTHERS then
RETURN('RI');
END fnc_get_state;
FUNCTION get_XY (p_state varchar2) RETURN VARCHAR2 IS
l_coords varchar2(32767);
BEGIN
for l_xy in (SELECT t.X, t.Y
FROM states s,
TABLE(SDO_UTIL.GETVERTICES(s.geom)) t
WHERE s. STATE_ABRV = p_state
) loop
l_coords:= l_coords || '['|| l_xy.X ||','|| l_xy.Y ||'],';
end loop;
RETURN( substr(l_coords, 1, length(l_coords)-1) );
END get_XY;
BEGIN
l_state := fnc_get_state(p_x, p_y);
htp.p('
{
"type": "FeatureCollection",
"features": [
{"type":"Feature", "id":"OpenLayers.Feature.Vector_1489", "properties":{},
"geometry":{ "type":"Polygon",
"coordinates":[['
|| get_XY( l_state ) ||
']] },'||
'"crs":{"type":"OGC", "properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}
}'||
']
}
'
);
end get_simple_geojson_2;
/
function handleMapClick(e)
{
var lonlat = map.getLonLatFromViewPortPx(e.xy);
var newgeojson = new OpenLayers.Layer.GML("My GeoJSON Layer",
'http://localhost:8089/mvdemo/get_simple_geojson_2?p_x='+lonlat.lon+'&p_y='+lonlat.lat,
{format: OpenLayers.Format.GeoJSON});
map.addLayer(newgeojson);
}