Changeset 10225

Show
Ignore:
Timestamp:
04/16/10 14:53:40 (5 months ago)
Author:
bartvde
Message:

add testcase for inline GML and KML

Location:
sandbox/bartvde/owc/openlayers
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • sandbox/bartvde/owc/openlayers/lib/OpenLayers/Format/Context.js

    r10224 r10225  
    2020 
    2121    /** 
    22      * APIProperty: layerOptions 
    23      * {Object} Default options for layers created by the parser. 
    24      *     Per layer type (identified by CLASS_NAME) an object is required. 
    25      * 
    26      *     Example: 
    27      *     (code) 
    28      *     layerOptions: { 
    29      *         'OpenLayers.Layer.WMS': {singleTile: true, ratio: 1, buffer: 0} 
    30      *     } 
    31      *     (end) 
    32      */ 
    33     layerOptions: {}, 
    34  
    35     /** 
    36      * APIProperty: layerParams 
     22     * Property: layerOptions 
     23     * {Object} Default options for layers created by the parser. These 
     24     *     options are overridden by the options which are read from the 
     25     *     capabilities document. 
     26     */ 
     27    layerOptions: null, 
     28 
     29    /** 
     30     * Property: layerParams 
    3731     * {Object} Default parameters for layers created by the parser. This 
    38      *     can be used to override DEFAULT_PARAMS. Per layer type 
    39      *     (identified by CLASS_NAME) an object. 
    40      * 
    41      *     Example: 
    42      *     (code) 
    43      *     layerParams: { 
    44      *         'OpenLayers.Layer.WMS': {'TRANSPARENT': 'TRUE'} 
    45      *     } 
    46      *     (end) 
    47      */ 
    48     layerParams: {}, 
     32     *     can be used e.g. to override DEFAULT_PARAMS for  
     33     *     OpenLayers.Layer.WMS. 
     34     */ 
     35    layerParams: null, 
    4936 
    5037    /** 
     
    211198                options 
    212199            ); 
     200        } else if (layerContext.service == 'urn:ogc:serviceType:GML') { 
     201            // use a vector layer with a HTTP Protocol and a Fixed strategy 
     202            options.strategies = [new OpenLayers.Strategy.Fixed()]; 
     203            options.protocol = new OpenLayers.Protocol.HTTP({ 
     204                url: layerContext.url,  
     205                format: new OpenLayers.Format.GML() 
     206            }); 
     207            layer = new OpenLayers.Layer.Vector( 
     208                layerContext.title || layerContext.name, 
     209                options 
     210            ); 
     211        } else if (layerContext.features) { 
     212            // inline GML or KML features 
     213            layer = new OpenLayers.Layer.Vector( 
     214                layerContext.title || layerContext.name, 
     215                options 
     216            ); 
     217            layer.addFeatures(layerContext.features); 
    213218        } else { 
    214219            layer = new OpenLayers.Layer.WMS( 
  • sandbox/bartvde/owc/openlayers/tests/Format/OWSContext/v0_3_1.html

    r10224 r10225  
    115115    } 
    116116*/ 
     117    function test_read_inline(t) { 
     118        t.plan(10); 
     119        var text = '<?xml version="1.0" encoding="UTF-8"?><OWSContext xmlns="http://www.opengis.net/ows-context" xmlns:gml="http://www.opengis.net/gml" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns:sld="http://www.opengis.net/sld" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="0.3.1" id="ows-context-ex-1-v3" xsi:schemaLocation="http://www.opengis.net/ows-context http://www.ogcnetwork.net/schemas/owc/0.3.0/owsContext.xsd"><General><ows:BoundingBox crs="urn:ogc:def:crs:EPSG:6.6:4326"><ows:LowerCorner>-117.44667178362664 32.57086210449395</ows:LowerCorner><ows:UpperCorner>-116.74066794885977 32.921986352104064</ows:UpperCorner></ows:BoundingBox><ows:Title>OWS Context version 0.3.0 Inline KML and GML examples</ows:Title></General><ResourceList><!-- WMS Example --><Layer name="topp:major_roads" queryable="1" hidden="1">  <ows:Title>Tiger 2005fe major roads</ows:Title> <ows:OutputFormat>image/png</ows:OutputFormat><Server service="urn:ogc:serviceType:WMS" version="1.1.1"><OnlineResource xlink:href="http://sigma.openplans.org:8080/geoserver/wms?SERVICE=WMS"/></Server></Layer><!-- Inline KML Example --><Layer name="archsites"><ows:Title>Architectural Sites</ows:Title><kml:Document><kml:name>opengeo:archsites 1 to 100</kml:name><kml:Style id="archsitesStyle"><kml:IconStyle><kml:color>ffffffff</kml:color><kml:colorMode>normal</kml:colorMode><kml:Icon><kml:href>http://maps.google.com/mapfiles/kml/pal4/icon25.png</kml:href></kml:Icon></kml:IconStyle></kml:Style><kml:Placemark id="archsites.1"><kml:name>Signature Rock</kml:name><kml:description>Signature Rock Description</kml:description><kml:styleUrl>#archsitesStyle</kml:styleUrl><kml:Point><kml:coordinates>-103.82681673,44.38162255</kml:coordinates></kml:Point></kml:Placemark></kml:Document></Layer><!-- Inline GML Example --><Layer name="coastg"><ows:Title>Coastg as GML Points</ows:Title><InlineGeometry><gml:boundedBy><gml:Box><gml:coord><gml:X>-43.379</gml:X><gml:Y>72.746</gml:Y></gml:coord><gml:coord><gml:X>-43.390</gml:X><gml:Y>72.755</gml:Y></gml:coord></gml:Box></gml:boundedBy><gml:featureMember><au1:coastg xmlns:au1="http://www.ionicsoft.com/wfs" fid="coastg.0"><au1:MERGE>1</au1:MERGE><au1:AREA>0.0020000000000000005</au1:AREA><au1:PERIMETER>0.167</au1:PERIMETER><au1:GEOMETRY><gml:Polygon srsName="urn:ogc:def:crs:EPSG:6.6:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>129.29167335893825,71.9583353847737 129.29167335893825,72.0000014248896 129.33332733905414,72.0000014248896 129.33332733905414,71.9583353847737 129.29167335893825,71.9583353847737</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></au1:GEOMETRY></au1:coastg></gml:featureMember><gml:featureMember><au1:coastg xmlns:au1="http://www.ionicsoft.com/wfs" fid="coastg.1"><au1:MERGE>1</au1:MERGE><au1:AREA>0.0020000000000000005</au1:AREA><au1:PERIMETER>0.167</au1:PERIMETER><au1:GEOMETRY><gml:Polygon srsName="urn:ogc:def:crs:EPSG:6.6:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>135.45832829609282,35.66666796381659 135.41667179597695,35.66666796381659 135.41667179597695,35.70833202393249 135.45832829609282,35.70833202393249 135.45832829609282,35.66666796381659</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></au1:GEOMETRY></au1:coastg></gml:featureMember></InlineGeometry></Layer></ResourceList></OWSContext>'; 
     120        var parser = new OpenLayers.Format.OWSContext(); 
     121        var context = parser.read(text, {map: 'map'}); 
     122        t.ok(context.layers[1] instanceof OpenLayers.Layer.Vector, "Inline KML results in a vector layer"); 
     123        t.eq(context.layers[1].features.length, 1, "Inline KML layer has one feature"); 
     124        t.ok(context.layers[1].features[0].geometry instanceof OpenLayers.Geometry.Point, "KML feature is a point"); 
     125        t.eq(context.layers[1].features[0].attributes.description, "Signature Rock Description", "KML Description correctly parsed"); 
     126        t.eq(context.layers[1].features[0].fid, "archsites.1", "KML feature id correctly parsed"); 
     127        t.eq(context.layers[1].features[0].style.externalGraphic, "http://maps.google.com/mapfiles/kml/pal4/icon25.png", "Style url for KML feature correctly parsed"); 
     128        t.ok(context.layers[2] instanceof OpenLayers.Layer.Vector, "Inline GML results in a vector layer"); 
     129        t.eq(context.layers[2].features.length, 2, "Inline GML layer has two features"); 
     130        t.ok(context.layers[2].features[0].geometry instanceof OpenLayers.Geometry.Polygon, "GML feature is a polygon"); 
     131        t.eq(context.layers[2].features[0].attributes.MERGE, "1", "GML attribute read correctly"); 
     132    } 
     133 
    117134    function test_read_kml(t) { 
    118135        t.plan(3);