OpenLayers OpenLayers

Ticket #808: remote_loading.2.patch

File remote_loading.2.patch, 15.6 kB (added by euzuro, 1 year ago)

some style changes, also fixing up the wfs tile's events to fire based only on the singletile

  • tests/owls.xml

    old new  
     1<?xml version='1.0' encoding="ISO-8859-1" ?> 
     2<wfs:FeatureCollection 
     3   xmlns:bsc="http://www.bsc-eoc.org/bsc" 
     4   xmlns:wfs="http://www.opengis.net/wfs" 
     5   xmlns:gml="http://www.opengis.net/gml" 
     6   xmlns:ogc="http://www.opengis.net/ogc" 
     7   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     8   xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-basic.xsd  
     9                       http://www.bsc-eoc.org/bsc http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=OWLS&amp;OUTPUTFORMAT=XMLSCHEMA"> 
     10      <gml:boundedBy> 
     11        <gml:Box srsName="EPSG:4326"> 
     12            <gml:coordinates>-89.817223,45.005555 -74.755001,51.701388</gml:coordinates> 
     13        </gml:Box> 
     14      </gml:boundedBy> 
     15    <gml:featureMember><bsc:OWLS> 
     16        <gml:boundedBy> 
     17            <gml:Box srsName="EPSG:4326"> 
     18                <gml:coordinates>-79.771668,45.891110 -79.771668,45.891110</gml:coordinates> 
     19            </gml:Box> 
     20        </gml:boundedBy> 
     21        <bsc:msGeometry> 
     22        <gml:Point srsName="EPSG:4326"> 
     23          <gml:coordinates>-79.771668,45.891110</gml:coordinates> 
     24        </gml:Point> 
     25        </bsc:msGeometry> 
     26      </bsc:OWLS> 
     27    </gml:featureMember> 
     28    <gml:featureMember> 
     29      <bsc:OWLS> 
     30        <gml:boundedBy> 
     31            <gml:Box srsName="EPSG:4326"> 
     32                <gml:coordinates>-83.755834,46.365277 -83.755834,46.365277</gml:coordinates> 
     33            </gml:Box> 
     34        </gml:boundedBy> 
     35        <bsc:owlname>owl</bsc:owlname> 
     36        <bsc:msGeometry> 
     37        <gml:Point srsName="EPSG:4326"> 
     38          <gml:coordinates>-83.755834,46.365277</gml:coordinates> 
     39        </gml:Point> 
     40        </bsc:msGeometry> 
     41      </bsc:OWLS> 
     42    </gml:featureMember> 
     43    <gml:featureMember> 
     44      <bsc:OWLS> 
     45        <gml:boundedBy> 
     46            <gml:Box srsName="EPSG:4326"> 
     47                <gml:coordinates>-83.808612,46.175277 -83.808612,46.175277</gml:coordinates> 
     48            </gml:Box> 
     49        </gml:boundedBy> 
     50        <bsc:msGeometry> 
     51        <gml:Point srsName="EPSG:4326"> 
     52          <gml:coordinates>-83.808612,46.175277</gml:coordinates> 
     53        </gml:Point> 
     54        </bsc:msGeometry> 
     55      </bsc:OWLS> 
     56    </gml:featureMember> 
     57    <gml:featureMember> 
     58      <bsc:OWLS> 
     59        <gml:boundedBy> 
     60            <gml:Box srsName="EPSG:4326"> 
     61                <gml:coordinates>-84.111112,46.309166 -84.111112,46.309166</gml:coordinates> 
     62            </gml:Box> 
     63        </gml:boundedBy> 
     64        <bsc:msGeometry> 
     65        <gml:Point srsName="EPSG:4326"> 
     66          <gml:coordinates>-84.111112,46.309166</gml:coordinates> 
     67        </gml:Point> 
     68        </bsc:msGeometry> 
     69      </bsc:OWLS> 
     70    </gml:featureMember> 
     71    <gml:featureMember> 
     72      <bsc:OWLS> 
     73        <gml:boundedBy> 
     74            <gml:Box srsName="EPSG:4326"> 
     75                <gml:coordinates>-83.678612,46.821110 -83.678612,46.821110</gml:coordinates> 
     76            </gml:Box> 
     77        </gml:boundedBy> 
     78        <bsc:msGeometry> 
     79        <gml:Point srsName="EPSG:4326"> 
     80          <gml:coordinates>-83.678612,46.821110</gml:coordinates> 
     81        </gml:Point> 
     82        </bsc:msGeometry> 
     83      </bsc:OWLS> 
     84    </gml:featureMember> 
     85    <gml:featureMember> 
     86      <bsc:OWLS> 
     87        <gml:boundedBy> 
     88            <gml:Box srsName="EPSG:4326"> 
     89                <gml:coordinates>-83.664445,46.518888 -83.664445,46.518888</gml:coordinates> 
     90            </gml:Box> 
     91        </gml:boundedBy> 
     92        <bsc:msGeometry> 
     93        <gml:Point srsName="EPSG:4326"> 
     94          <gml:coordinates>-83.664445,46.518888</gml:coordinates> 
     95        </gml:Point> 
     96        </bsc:msGeometry> 
     97      </bsc:OWLS> 
     98    </gml:featureMember> 
     99    <gml:featureMember> 
     100      <bsc:OWLS> 
     101        <gml:boundedBy> 
     102            <gml:Box srsName="EPSG:4326"> 
     103                <gml:coordinates>-80.613334,46.730277 -80.613334,46.730277</gml:coordinates> 
     104            </gml:Box> 
     105        </gml:boundedBy> 
     106        <bsc:msGeometry> 
     107        <gml:Point srsName="EPSG:4326"> 
     108          <gml:coordinates>-80.613334,46.730277</gml:coordinates> 
     109        </gml:Point> 
     110        </bsc:msGeometry> 
     111      </bsc:OWLS> 
     112    </gml:featureMember> 
     113    <gml:featureMember> 
     114      <bsc:OWLS> 
     115        <gml:boundedBy> 
     116            <gml:Box srsName="EPSG:4326"> 
     117                <gml:coordinates>-79.676946,45.428054 -79.676946,45.428054</gml:coordinates> 
     118            </gml:Box> 
     119        </gml:boundedBy> 
     120        <bsc:msGeometry> 
     121        <gml:Point srsName="EPSG:4326"> 
     122          <gml:coordinates>-79.676946,45.428054</gml:coordinates> 
     123        </gml:Point> 
     124        </bsc:msGeometry> 
     125      </bsc:OWLS> 
     126    </gml:featureMember> 
     127    <gml:featureMember> 
     128      <bsc:OWLS> 
     129        <gml:boundedBy> 
     130            <gml:Box srsName="EPSG:4326"> 
     131                <gml:coordinates>-83.853056,46.236944 -83.853056,46.236944</gml:coordinates> 
     132            </gml:Box> 
     133        </gml:boundedBy> 
     134        <bsc:msGeometry> 
     135        <gml:Point srsName="EPSG:4326"> 
     136          <gml:coordinates>-83.853056,46.236944</gml:coordinates> 
     137        </gml:Point> 
     138        </bsc:msGeometry> 
     139      </bsc:OWLS> 
     140    </gml:featureMember> 
     141    <gml:featureMember> 
     142      <bsc:OWLS> 
     143        <gml:boundedBy> 
     144            <gml:Box srsName="EPSG:4326"> 
     145                <gml:coordinates>-82.289167,45.896388 -82.289167,45.896388</gml:coordinates> 
     146            </gml:Box> 
     147        </gml:boundedBy> 
     148        <bsc:msGeometry> 
     149        <gml:Point srsName="EPSG:4326"> 
     150          <gml:coordinates>-82.289167,45.896388</gml:coordinates> 
     151        </gml:Point> 
     152        </bsc:msGeometry> 
     153      </bsc:OWLS> 
     154    </gml:featureMember> 
     155</wfs:FeatureCollection> 
     156 
  • tests/Layer/test_GML.html

    old new  
    55 
    66    var name = "GML Layer"; 
    77     
     8    var gml = "./owls.xml"; 
     9 
     10    // if this test is running online, different rules apply 
     11    var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1); 
     12    if (isMSIE) { 
     13        gml = "." + gml; 
     14    } 
     15     
    816    function test_01_Layer_GML_constructor(t) { 
    917        t.plan(3); 
    1018 
     
    1422        t.ok(layer.renderer.CLASS_NAME, "layer has a renderer"); 
    1523 
    1624    } 
     25    function test_Layer_GML_events(t) { 
     26        t.plan(3); 
     27 
     28        var layer = new OpenLayers.Layer.GML(name, gml, {isBaseLayer: true}); 
     29        layer.events.register("loadstart", layer, function() {  
     30            t.ok(true, "loadstart called.") 
     31        }); 
     32        layer.events.register("loadend", layer, function() {  
     33            t.ok(true, "loadend called.") 
     34        }); 
     35        var map = new OpenLayers.Map("map"); 
     36        map.addLayer(layer); 
     37        map.zoomToMaxExtent(); 
     38        t.delay_call(1, function() {  
     39            t.ok(true, "waited for 1s");  
     40        }); 
     41 
     42    } 
    1743  </script> 
    1844</head> 
    1945<body> 
  • tests/Layer/test_Text.html

    old new  
    118118          t.eq(map.popups.length, 0, "no popup on second marker"); 
    119119        }); 
    120120    } 
     121    function test_Layer_Text_loadend_Event(t) { 
     122        t.plan(2); 
     123        layer = new OpenLayers.Layer.Text('Test Layer', {location:datafile}); 
     124        t.delay_call(2, function() {  
     125            layer.events.register('loadend', layer, function() {  
     126                t.ok(true, "Loadend event fired");  
     127            }); 
     128            layer.parseData({ 
     129                'responseText':'' 
     130            }); 
     131            t.ok(true, "Parsing data didn't fail");  
     132        }); 
     133    } 
    121134 
    122135    function test_99_Layer_Text_destroy (t) { 
    123136        t.plan( 1 );     
  • tests/Layer/test_GeoRSS.html

    old new  
    8080        map.addLayer(layer); 
    8181        map.setCenter(new OpenLayers.LonLat(0,0),0); 
    8282        var event = {}; 
    83         t.delay_call( 1, function() {   
     83        t.delay_call( 2, function() {   
    8484          t.ok(layer.markers[0].events, "First marker has an events object"); 
    8585          t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); 
    8686          layer.markers[0].events.triggerEvent('click', event); 
     
    159159            t.eq(otherLayer.markers[0].icon.url, the_icon.url,"The layer with an icon has that icon."); 
    160160        }); 
    161161    } 
    162      
     162    function test_Layer_GeoRSS_loadend_Event(t) { 
     163        var browserCode = OpenLayers.Util.getBrowserName(); 
     164        if (browserCode == "msie") { 
     165            t.plan(1); 
     166            t.ok(true, "IE fails the GeoRSS test. This could probably be fixed by someone with enough energy to fix it."); 
     167        } else { 
     168            t.plan(2); 
     169            layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); 
     170            t.delay_call(2, function() {  
     171                layer.events.register('loadend', layer, function() {  
     172                    t.ok(true, "Loadend event fired");  
     173                }); 
     174                layer.parseData({ 
     175                    'responseText': '<xml xmlns="http://example.com"><title> </title></xml>' 
     176                }); 
     177                t.ok(true, "Parsing data didn't fail");  
     178            }); 
     179        }  
     180    } 
     181 
    163182    function test_99_Layer_GeoRSS_destroy (t) { 
    164183        t.plan( 1 );     
    165184        layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); 
  • lib/OpenLayers/Tile/WFS.js

    old new  
    7575     */ 
    7676    draw:function() { 
    7777        if (OpenLayers.Tile.prototype.draw.apply(this, arguments)) { 
     78            if (this.isLoading) { 
     79                //if already loading, send 'reload' instead of 'loadstart'. 
     80                this.events.triggerEvent("reload");  
     81            } else { 
     82                this.isLoading = true; 
     83                this.events.triggerEvent("loadstart"); 
     84            } 
    7885            this.loadFeaturesForRegion(this.requestSuccess); 
    7986        } 
    8087    }, 
     
    121128                this.addResults(resultFeatures); 
    122129            } 
    123130        } 
     131        if (this.events) { 
     132            this.events.triggerEvent("loadend");  
     133        } 
    124134    }, 
    125135 
    126136    /** 
  • lib/OpenLayers/Layer/GML.js

    old new  
    8181        // loaded after the GML is paited. 
    8282        // See http://trac.openlayers.org/ticket/404 
    8383        if(this.visibility && !this.loaded){ 
     84            this.events.triggerEvent("loadstart"); 
    8485            this.loadGML(); 
    8586        } 
    8687    }, 
     
    113114 
    114115        var gml = this.format ? new this.format() : new OpenLayers.Format.GML(); 
    115116        this.addFeatures(gml.read(doc)); 
     117        this.events.triggerEvent("loadend"); 
    116118    }, 
    117119     
    118120    /** 
     
    125127     */ 
    126128    requestFailure: function(request) { 
    127129        alert("Error in loading GML file "+this.url); 
     130        this.events.triggerEvent("loadend"); 
    128131    }, 
    129132 
    130133    CLASS_NAME: "OpenLayers.Layer.GML" 
  • lib/OpenLayers/Layer/Text.js

    old new  
    4747        OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); 
    4848        this.features = new Array(); 
    4949        if (this.location != null) { 
    50             OpenLayers.loadURL(this.location, null, this, this.parseData); 
     50 
     51            var onFail = function(e) { 
     52                this.events.triggerEvent("loadend"); 
     53            }; 
     54 
     55            this.events.triggerEvent("loadstart"); 
     56            OpenLayers.loadURL(this.location, null,  
     57                               this, this.parseData, onFail); 
    5158        } 
    5259    }, 
    5360 
     
    155162                } 
    156163            } 
    157164        } 
     165        this.events.triggerEvent("loadend"); 
    158166    }, 
    159167     
    160168    /** 
  • lib/OpenLayers/Layer/WFS.js

    old new  
    2323    isBaseLayer: false, 
    2424     
    2525    /** 
     26     * Property: tile 
     27     * {<OpenLayers.Tile.WFS>} 
     28     */ 
     29    tile: null,     
     30     
     31    /** 
    2632     * APIProperty: ratio 
    2733     * {Float} the ratio of image/tile size to map size (this is the untiled 
    2834     *     buffer) 
     
    234240            if (!this.tile) { 
    235241                this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,  
    236242                                                     url, tileSize); 
     243                this.addTileMonitoringHooks(this.tile); 
    237244                this.tile.draw(); 
    238245            } else { 
    239246                if (this.vectorMode) { 
     
    243250                    this.clearMarkers(); 
    244251                }     
    245252                this.tile.destroy(); 
     253                this.removeTileMonitoringHooks(this.tile); 
    246254                 
    247255                this.tile = null; 
    248256                this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,  
     
    252260        } 
    253261    }, 
    254262 
     263    /**  
     264     * Method: addTileMonitoringHooks 
     265     * This function takes a tile as input and adds the appropriate hooks to  
     266     *     the tile so that the layer can keep track of the loading tile 
     267     *     (making sure to check that the tile is always the layer's current 
     268     *     tile before taking any action). 
     269     *  
     270     * Parameters:  
     271     * tile - {<OpenLayers.Tile>} 
     272     */ 
     273    addTileMonitoringHooks: function(tile) { 
     274        tile.onLoadStart = function() { 
     275            //if this is the the layer's current tile, then trigger  
     276            // a 'loadstart' 
     277            if (this == this.layer.tile) { 
     278                this.layer.events.triggerEvent("loadstart"); 
     279            } 
     280        }; 
     281        tile.events.register("loadstart", tile, tile.onLoadStart); 
     282       
     283        tile.onLoadEnd = function() { 
     284            //if this is the the layer's current tile, then trigger  
     285            // a 'tileloaded' and 'loadend' 
     286            if (this == this.layer.tile) { 
     287                this.layer.events.triggerEvent("tileloaded"); 
     288                this.layer.events.triggerEvent("loadend"); 
     289            } 
     290        }; 
     291        tile.events.register("loadend", tile, tile.onLoadEnd); 
     292    }, 
     293     
     294    /**  
     295     * Method: removeTileMonitoringHooks 
     296     * This function takes a tile as input and removes the tile hooks  
     297     *     that were added in addTileMonitoringHooks() 
     298     *  
     299     * Parameters:  
     300     * tile - {<OpenLayers.Tile>} 
     301     */ 
     302    removeTileMonitoringHooks: function(tile) { 
     303        tile.events.unregister("loadstart", tile, tile.onLoadStart); 
     304        tile.events.unregister("loadend", tile, tile.onLoadEnd); 
     305    }, 
     306 
    255307    /** 
    256308     * Method: onMapResize 
    257309     * Call the onMapResize method of the appropriate parent class.  
  • lib/OpenLayers/Layer/GeoRSS.js

    old new  
    6767        OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name, options]); 
    6868        this.location = location; 
    6969        this.features = []; 
     70        this.events.triggerEvent("loadstart"); 
    7071        OpenLayers.loadURL(location, null, this, this.parseData); 
    7172    }, 
    7273 
     
    209210            marker.events.register('click', feature, this.markerClick); 
    210211            this.addMarker(marker); 
    211212        } 
     213        this.events.triggerEvent("loadend"); 
    212214    }, 
    213215     
    214216    /**