OpenLayers OpenLayers

Ticket #762: encodeBBOX.patch

File encodeBBOX.patch, 6.3 kB (added by crschmidt, 11 months ago)
  • tests/Layer/test_WFS.html

    old new  
    2828        t.eq(setSize, true, "Renderer resize called on map size change."); 
    2929 
    3030    } 
     31    function test_Layer_WFS_drawmap(t) { 
     32        t.plan(2); 
     33        map = new OpenLayers.Map('map'); 
     34        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     35            "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 
     36        map.addLayer(layer); 
     37 
     38        layer = new OpenLayers.Layer.WFS( "Owl Survey", 
     39            "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?", 
     40            {typename: "OWLS", maxfeatures: 10}, 
     41            { featureClass: OpenLayers.Feature.WFS}); 
     42        map.addLayer(layer); 
     43        map.addControl(new OpenLayers.Control.LayerSwitcher()); 
     44        try {  
     45            map.setCenter(new OpenLayers.LonLat(-100, 60), 3); 
     46        } catch (Exception) { 
     47        }     
     48        t.eq(layer.tile.url, "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?typename=OWLS&maxfeatures=10&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&SRS=EPSG%3A4326&BBOX=-187.890625,-36.6796875,-12.109375,156.6796875", "Tile URL is set correctly when not encoded"); 
     49        map = new OpenLayers.Map('map'); 
     50        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     51            "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} 
     52            ); 
     53        map.addLayer(layer); 
     54 
     55        layer = new OpenLayers.Layer.WFS( "Owl Survey", 
     56            "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?", 
     57            {typename: "OWLS", maxfeatures: 10}, 
     58            { featureClass: OpenLayers.Feature.WFS, 'encodeBBOX': true}); 
     59        map.addLayer(layer); 
     60        map.addControl(new OpenLayers.Control.LayerSwitcher()); 
     61        try {  
     62            map.setCenter(new OpenLayers.LonLat(-100, 60), 3); 
     63        } catch (Exception) { 
     64        }   
     65        t.eq(layer.tile.url, "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?typename=OWLS&maxfeatures=10&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&SRS=EPSG%3A4326&BBOX=-187.890625%2C-36.679687%2C-12.109375%2C156.679688", "Tile URL is set correctly when not encoded"); 
     66    } 
     67 
    3168  // --> 
    3269  </script> 
    3370</head> 
  • tests/Layer/test_WMS.html

    old new  
    7070            SERVICE: "WMS", VERSION: "1.1.1", 
    7171            REQUEST: "GetMap", STYLES: "", 
    7272            EXCEPTIONS: "application/vnd.ogc.se_inimage", 
     73            SRS: "EPSG:4326", BBOX: [1,2,3,4], 
     74            WIDTH: "256", HEIGHT: "256" 
     75        }); 
     76        t.eq( img.src, 
     77             url + "?" + OpenLayers.Util.getParameterString(tParams), 
     78             "image src is created correctly via addtile" ); 
     79        t.eq( tile.frame.style.top, "6px", "image top is set correctly via addtile" ); 
     80        t.eq( tile.frame.style.left, "5px", "image top is set correctly via addtile" ); 
     81 
     82        var firstChild = layer.div.firstChild.firstChild; 
     83        if (!isMozilla) 
     84            t.ok( true, "skipping element test outside of Mozilla"); 
     85        else 
     86            t.ok( firstChild instanceof HTMLElement, "div first child is an image object" ); 
     87        t.eq( firstChild.src, 
     88             url + "?" + OpenLayers.Util.getParameterString(tParams), 
     89             "div first child is correct image object" ); 
     90        t.eq( tile.position.toString(), "x=5,y=6", "Position of tile is set correctly." ); 
     91        map.destroy(); 
     92    } 
     93     
     94    function test_Layer_WMS_bboxEncoding (t) { 
     95        t.plan( 6 ); 
     96     
     97        var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 
     98        layer = new OpenLayers.Layer.WMS(name, url, params, {encodeBBOX:true}); 
     99        var map = new OpenLayers.Map('map'); 
     100        map.addLayer(layer); 
     101        var pixel = new OpenLayers.Pixel(5,6); 
     102        var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); 
     103        tile.draw(); 
     104 
     105        var img = tile.imgDiv; 
     106        var tParams = OpenLayers.Util.extend({}, 
     107                        OpenLayers.Util.upperCaseObject(params)); 
     108        tParams = OpenLayers.Util.extend(tParams, { 
     109            SERVICE: "WMS", VERSION: "1.1.1", 
     110            REQUEST: "GetMap", STYLES: "", 
     111            EXCEPTIONS: "application/vnd.ogc.se_inimage", 
    73112            SRS: "EPSG:4326", BBOX: "1,2,3,4", 
    74113            WIDTH: "256", HEIGHT: "256" 
    75114        }); 
  • lib/OpenLayers/Layer/WMS.js

    old new  
    4343     * {Boolean} Default is true for WMS layer 
    4444     */ 
    4545    isBaseLayer: true, 
     46     
     47    /** 
     48     * APIProperty: encodeBBOX 
     49     * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no',  
     50     * but some services want it that way. Default false. 
     51     */ 
     52    encodeBBOX: false, 
    4653  
    4754    /** 
    4855     * Constructor: OpenLayers.Layer.WMS 
     
    146153         
    147154        var imageSize = this.getImageSize();  
    148155        return this.getFullRequestString( 
    149                      {BBOX:bounds.toBBOX(), 
     156                     {BBOX: this.encodeBBOX ?  bounds.toBBOX() : bounds.toArray(), 
    150157                      WIDTH:imageSize.w, 
    151158                      HEIGHT:imageSize.h}); 
    152159    }, 
  • lib/OpenLayers/Layer/WFS.js

    old new  
    5151     * {Boolean} Should be calculated automatically. 
    5252     */ 
    5353    vectorMode: true,  
     54     
     55    /** 
     56     * APIProperty: encodeBBOX 
     57     * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no',  
     58     * but some services want it that way. Default false. 
     59     */ 
     60    encodeBBOX: false, 
    5461 
    5562    /** 
    5663    * Constructor: OpenLayers.Layer.WFS 
     
    196203            //formulate request url string 
    197204            var url = this.getFullRequestString(); 
    198205         
    199             var params = { BBOX:tileBounds.toBBOX() }; 
     206            var params = {BBOX: this.encodeBBOX ? tileBounds.toBBOX()  
     207                                                : tileBounds.toArray()}; 
    200208            url += "&" + OpenLayers.Util.getParameterString(params); 
    201209 
    202210            if (!this.tile) {