OpenLayers OpenLayers
Show
Ignore:
Timestamp:
09/28/06 09:05:36 (2 years ago)
Author:
crschmidt
Message:

Merge bugfixes and test improvements for rc4 release.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/openlayers/2.1/lib/OpenLayers/BaseTypes.js

    r1424 r1513  
    425425    }, 
    426426 
     427    /** 
     428     * @param {OpenLayers.LonLat} ll 
     429     * @param {Boolean} inclusive Whether or not to include the border.  
     430     *                            Default is true 
     431     * 
     432     * @return Whether or not the passed-in lonlat is within this bounds 
     433     * @type Boolean 
     434     */ 
     435    containsLonLat:function(ll, inclusive) { 
     436        return this.contains(ll.lon, ll.lat, inclusive); 
     437    }, 
     438 
     439    /** 
     440     * @param {OpenLayers.Pixel} px 
     441     * @param {Boolean} inclusive Whether or not to include the border.  
     442     *                            Default is true 
     443     * 
     444     * @return Whether or not the passed-in pixel is within this bounds 
     445     * @type Boolean 
     446     */ 
     447    containsPixel:function(px, inclusive) { 
     448        return this.contains(px.x, px.y, inclusive); 
     449    }, 
     450     
    427451    /** 
    428452    * @param {float} x 
  • branches/openlayers/2.1/lib/OpenLayers/Feature.js

    r1501 r1513  
    6868        } 
    6969        if (this.popup != null) { 
    70             this.popup.destroy(); 
     70            this.destroyPopup(this.popup); 
    7171            this.popup = null; 
    7272        } 
     73    }, 
     74     
     75    /** 
     76     * @returns Whether or not the feature is currently visible on screen 
     77     *           (based on its 'lonlat' property) 
     78     * @type Boolean 
     79     */ 
     80    onScreen:function() { 
     81         
     82        var onScreen = false; 
     83        if ((this.layer != null) && (this.layer.map != null)) { 
     84            var screenBounds = this.layer.map.getExtent(); 
     85            onScreen = screenBounds.containsLonLat(this.lonlat); 
     86        }     
     87        return onScreen; 
    7388    }, 
    7489     
     
    7792     * @returns A Marker Object created from the 'lonlat' and 'icon' properties 
    7893     *          set in this.data. If no 'lonlat' is set, returns null. If no 
    79      *          'icon' is set, OpenLayers.Marker() will load the default image 
     94     *          'icon' is set, OpenLayers.Marker() will load the default image. 
     95     *           
     96     *          Note: this.marker is set to return value 
     97     *  
    8098     * @type OpenLayers.Marker 
    8199     */ 
     
    90108    }, 
    91109 
     110    /** If user overrides the createMarker() function, s/he should be able 
     111     *   to also specify an alternative function for destroying it 
     112     */ 
    92113    destroyMarker: function() { 
    93114        this.marker.destroy();   
     
    95116 
    96117    /** 
     118     * @returns A Popup Object created from the 'lonlat', 'popupSize', 
     119     *          and 'popupContentHTML' properties set in this.data. It uses 
     120     *          this.marker.icon as default anchor.  
     121     *           
     122     *          If no 'lonlat' is set, returns null.  
     123     *          If no this.marker has been created, no anchor is sent. 
    97124     *  
     125     *          Note: this.popup is set to return value 
     126     *  
     127     * @type OpenLayers.Popup.AnchoredBubble 
    98128     */ 
    99129    createPopup: function() { 
     
    113143    }, 
    114144 
     145     
     146    /** As with the marker, if user overrides the createPopup() function, s/he  
     147     *   should also be able to override the destruction 
     148     */ 
     149    destroyPopup: function() { 
     150        this.popup.destroy()  
     151    }, 
     152     
    115153    CLASS_NAME: "OpenLayers.Feature" 
    116154}; 
  • branches/openlayers/2.1/lib/OpenLayers/Layer.js

    r1501 r1513  
    394394    getZoomForResolution: function(resolution) { 
    395395         
    396         for(var i=1; i <= this.resolutions.length; i++) { 
     396        for(var i=1; i < this.resolutions.length; i++) { 
    397397            if ( this.resolutions[i] < resolution) { 
    398398                break; 
  • branches/openlayers/2.1/lib/OpenLayers/Map.js

    r1501 r1513  
    355355           
    356356            // is newBaseLayer an already loaded layer? 
    357             var foundLayer = (this.layers.indexOf(newBaseLayer) != -1);     
    358             if (foundLayer) { 
     357            if (this.layers.indexOf(newBaseLayer) != -1) { 
    359358 
    360359                // make the old base layer invisible  
     
    456455 
    457456    /** 
    458     * @returns {OpenLayers.Size} 
     457    * @returns An OpenLayers.Size object that represents the size, in pixels,  
     458    *          of the div into which OpenLayers has been loaded.  
     459    *  
     460    *          Note: A clone() of this locally cached variable is returned, so  
     461    *                as not to allow users to modify it. 
     462    *  
     463    * @type OpenLayers.Size 
    459464    */ 
    460465    getSize: function () { 
    461         return this.size; 
     466        var size = null; 
     467        if (this.size != null) { 
     468            size = this.size.clone(); 
     469        } 
     470        return size; 
    462471    }, 
    463472 
     
    670679        if (lonlat != null) { 
    671680            var maxExtent = this.getMaxExtent(); 
    672             valid = maxExtent.contains(lonlat.lon, lonlat.lat);         
     681            valid = maxExtent.containsLonLat(lonlat);         
    673682        } 
    674683        return valid; 
  • branches/openlayers/2.1/lib/OpenLayers/Marker.js

    r1501 r1513  
    8383        if (this.map) { 
    8484            var screenBounds = this.map.getExtent(); 
    85             onScreen = screenBounds.contains(this.lonlat.lon, this.lonlat.lat); 
     85            onScreen = screenBounds.containsLonLat(this.lonlat); 
    8686        }     
    8787        return onScreen; 
  • branches/openlayers/2.1/tests/test_Bounds.html

    r1424 r1513  
    5454 
    5555     function test_04_Bounds_contains(t) { 
    56          t.plan( 4 ); 
     56         t.plan( 6 ); 
    5757         bounds = new OpenLayers.Bounds(10,10,40,40); 
    5858         t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" ); 
     
    6060         t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" ); 
    6161         t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" ); 
     62 
     63         var px = new OpenLayers.Pixel(15,30); 
     64         t.eq( bounds.containsPixel(px), bounds.contains(px.x, px.y), "containsPixel works"); 
     65 
     66         var ll = new OpenLayers.LonLat(15,30); 
     67         t.eq( bounds.containsLonLat(ll), bounds.contains(ll.lon, ll.lat), "containsLonLat works"); 
     68 
    6269     } 
    6370 
  • branches/openlayers/2.1/tests/test_Feature.html

    r1424 r1513  
    7777*/ 
    7878    } 
     79     
     80    function test_03_Feature_onScreen(t) { 
     81        t.plan( 2 ); 
     82 
     83        var map = new OpenLayers.Map("map"); 
     84 
     85        var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 
     86        var wms = new OpenLayers.Layer.WMS(name, url); 
     87 
     88        map.addLayer(wms); 
     89 
     90        var layer = new OpenLayers.Layer("foo"); 
     91        map.addLayer(layer); 
     92         
     93        map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 
     94 
     95        //onscreen feature 
     96        var feature1 = new OpenLayers.Feature(layer,  
     97                                              new OpenLayers.LonLat(0,0)); 
     98        t.ok( feature1.onScreen(), "feature knows it's onscreen" ); 
     99 
     100        //onscreen feature 
     101        var feature2 = new OpenLayers.Feature(layer,  
     102                                              new OpenLayers.LonLat(100,100)); 
     103        t.ok( !feature2.onScreen(), "feature knows it's offscreen" ); 
     104    } 
    79105 
    80106  // --> 
  • branches/openlayers/2.1/tests/test_Layer.html

    r1424 r1513  
    127127 
    128128 
     129    function test_06_Layer_getZoomForResolution(t) { 
     130 
     131        t.plan(4); 
     132 
     133        var layer = new OpenLayers.Layer('Test Layer'); 
     134             
     135        //make some dummy resolutions 
     136        layer.resolutions = [128, 64, 32, 16, 8, 4, 2]; 
     137         
     138        t.eq(layer.getZoomForResolution(200), 0, "zoom all the way out"); 
     139        t.eq(layer.getZoomForResolution(25), 2, "zoom in middle"); 
     140        t.eq(layer.getZoomForResolution(3), 5, "zoom allmost all the way in"); 
     141        t.eq(layer.getZoomForResolution(1), 6, "zoom  all the way in"); 
     142 
     143    } 
     144     
     145     
    129146/****** 
    130147 *  
  • branches/openlayers/2.1/tests/test_Layer_WMS.html

    r1433 r1513  
    1414    function test_01_Layer_WMS_constructor (t) { 
    1515        t.plan( 4 ); 
    16  
    17         layer = new OpenLayers.Layer.WMS(); 
    1816 
    1917        var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 
  • branches/openlayers/2.1/tests/test_Marker.html

    r1424 r1513  
    1515    } 
    1616 
     17    function test_02_Marker_onScreen(t) { 
     18        t.plan( 2 ); 
     19 
     20        var map = new OpenLayers.Map("map"); 
     21 
     22        var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 
     23        layer = new OpenLayers.Layer.WMS(name, url); 
     24 
     25        map.addLayer(layer); 
     26         
     27        mlayer = new OpenLayers.Layer.Markers('Test Layer'); 
     28        map.addLayer(mlayer); 
     29                
     30        map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 
     31 
     32        //onscreen marker 
     33        var ll = new OpenLayers.LonLat(0,0); 
     34        var marker = new OpenLayers.Marker(ll); 
     35        mlayer.addMarker(marker); 
     36         
     37        t.ok( marker.onScreen(), "marker knows it's onscreen" ); 
     38 
     39        //offscreen marker 
     40        var ll = new OpenLayers.LonLat(100,100); 
     41        var marker2 = new OpenLayers.Marker(ll); 
     42        mlayer.addMarker(marker2); 
     43 
     44        t.ok( !marker2.onScreen(), "marker knows it's offscreen" ); 
     45         
     46    } 
     47 
    1748 
    1849  // --> 
     
    2051</head> 
    2152<body> 
     53    <div id="map" style="width:500px;height:550px"></div> 
    2254</body> 
    2355</html>