OpenLayers OpenLayers

Ticket #808: remote_loading.patch

File remote_loading.patch, 15.1 kB (added by crschmidt, 1 year ago)

tests pass in IE

  • 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() { t.ok(true, "loadstart called.")}); 
     30        layer.events.register("loadend", layer, function() { t.ok(true, "loadend called.")}); 
     31        var map = new OpenLayers.Map("map"); 
     32        map.addLayer(layer); 
     33        map.zoomToMaxExtent(); 
     34        t.delay_call(1, function() { t.ok(true, "waited for 1s"); } ); 
     35 
     36    } 
    1737  </script> 
    1838</head> 
    1939<body> 
  • tests/Layer/test_Text.html

    old new  
    9595          t.eq(map.popups.length, 0, "no popup on second marker"); 
    9696        }); 
    9797    } 
     98    function test_Layer_Text_loadend_Event(t) { 
     99        t.plan(2); 
     100        layer = new OpenLayers.Layer.Text('Test Layer', {location:datafile}); 
     101        t.delay_call(2, function() {  
     102        layer.events.register('loadend', layer, function() { t.ok(true, "Loadend event fired"); }); 
     103        layer.parseData({'responseText':''}); 
     104        t.ok(true, "waited for load"); }); 
     105    } 
    98106 
    99107    function test_99_Layer_Text_destroy (t) { 
    100108        t.plan( 1 );     
  • tests/Layer/test_GeoRSS.html

    old new  
    7171        map.addLayer(layer); 
    7272        map.setCenter(new OpenLayers.LonLat(0,0),0); 
    7373        var event = {}; 
    74         t.delay_call( 1, function() {   
     74        t.delay_call( 2, function() {   
    7575          t.ok(layer.markers[0].events, "First marker has an events object"); 
    7676          t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); 
    7777          layer.markers[0].events.triggerEvent('click', event); 
     
    150150            t.eq(otherLayer.markers[0].icon.url, the_icon.url,"The layer with an icon has that icon."); 
    151151        }); 
    152152    } 
     153    function test_Layer_GeoRSS_loadend_Event(t) { 
     154        var browserCode = OpenLayers.Util.getBrowserName(); 
     155        if (browserCode == "msie") { 
     156            t.plan(1); 
     157            t.ok(true, "IE fails the GeoRSS test. This could probably be fixed by someone with enough energy to fix it."); 
     158        } else { 
     159            t.plan(2); 
     160            layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); 
     161            t.delay_call(2, function() {  
     162            layer.events.register('loadend', layer, function() { t.ok(true, "Loadend event fired"); }); 
     163            layer.parseData({'responseText':'<xml xmlns="http://example.com"><title> </title></xml>'}); 
     164            t.ok(true, "waited for load"); }); 
     165        }  
     166    } 
    153167     
    154168    function test_99_Layer_GeoRSS_destroy (t) { 
    155169        t.plan( 1 );     
  • 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 we're 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    }, 
     
    115122            var resultFeatures = OpenLayers.Ajax.getElementsByTagNameNS(doc, "http://www.opengis.net/gml","gml", "featureMember"); 
    116123            this.addResults(resultFeatures); 
    117124        } 
     125        if (this.isLoading) {  
     126            this.isLoading = false;  
     127            this.events.triggerEvent("loadend");  
     128        } 
    118129    }, 
    119130 
    120131    /** 
  • 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            this.events.triggerEvent("loadstart"); 
    5051            OpenLayers.loadURL(this.location, null, this, this.parseData); 
    5152        } 
    5253    }, 
     
    150151                } 
    151152            } 
    152153        } 
     154        this.events.triggerEvent("loadend"); 
    153155    }, 
    154156     
    155157    /** 
  • lib/OpenLayers/Layer/WFS.js

    old new  
    2929     */ 
    3030    ratio: 2, 
    3131 
     32    /** 
     33     * Property: numLoadingTiles 
     34     * {Int} The number of tiles outstanding. 
     35     */ 
     36    numLoadingTiles: 0,  
     37 
    3238    /**   
    3339     * Property: DEFAULT_PARAMS 
    3440     * {Object} Hashtable of default key/value parameters 
     
    225231            if (!this.tile) { 
    226232                this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,  
    227233                                                     url, tileSize); 
     234                this.addTileMonitoringHooks(this.tile); 
    228235                this.tile.draw(); 
    229236            } else { 
    230237                if (this.vectorMode) { 
     
    234241                    this.clearMarkers(); 
    235242                }     
    236243                this.tile.destroy(); 
     244                this.removeTileMonitoringHooks(this.tile); 
    237245                 
    238246                this.tile = null; 
    239247                this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,  
     
    243251        } 
    244252    }, 
    245253 
     254    /**  
     255     * Method: addTileMonitoringHooks 
     256     * This function takes a tile as input and adds the appropriate hooks to  
     257     *     the tile so that the layer can keep track of the loading tiles. 
     258     *  
     259     * Parameters:  
     260     * tile - {<OpenLayers.Tile>} 
     261     */ 
     262    addTileMonitoringHooks: function(tile) { 
     263        tile.onLoadStart = function() { 
     264            //if that was first tile then trigger a 'loadstart' on the layer 
     265            if (this.numLoadingTiles == 0) { 
     266                this.events.triggerEvent("loadstart"); 
     267            } 
     268            this.numLoadingTiles++; 
     269        }; 
     270        tile.events.register("loadstart", this, tile.onLoadStart); 
     271       
     272        tile.onLoadEnd = function() { 
     273            this.numLoadingTiles--; 
     274            this.events.triggerEvent("tileloaded"); 
     275            //if that was the last tile, then trigger a 'loadend' on the layer 
     276            if (this.numLoadingTiles == 0) { 
     277                this.events.triggerEvent("loadend"); 
     278            } 
     279        }; 
     280        tile.events.register("loadend", this, tile.onLoadEnd); 
     281    }, 
     282     
     283    /**  
     284     * Method: removeTileMonitoringHooks 
     285     * This function takes a tile as input and removes the tile hooks  
     286     *     that were added in addTileMonitoringHooks() 
     287     *  
     288     * Parameters:  
     289     * tile - {<OpenLayers.Tile>} 
     290     */ 
     291    removeTileMonitoringHooks: function(tile) { 
     292        tile.events.unregister("loadstart", this, tile.onLoadStart); 
     293        tile.events.unregister("loadend", this, tile.onLoadEnd); 
     294    }, 
     295 
    246296    /** 
    247297     * Method: onMapResize 
    248298     * Call the onMapResize method of the appropriate parent class.  
  • lib/OpenLayers/Layer/GeoRSS.js

    old new  
    6161        OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name, options]); 
    6262        this.location = location; 
    6363        this.features = []; 
     64        this.events.triggerEvent("loadstart"); 
    6465        OpenLayers.loadURL(location, null, this, this.parseData); 
    6566    }, 
    6667 
     
    198199            marker.events.register('click', feature, this.markerClick); 
    199200            this.addMarker(marker); 
    200201        } 
     202        this.events.triggerEvent("loadend"); 
    201203    }, 
    202204     
    203205    /**