add onScreen() function to OpenLayers.Feature, and add tests to prove it.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1510 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-09-27 21:56:17 +00:00
parent 1cedf957b0
commit 73fb43712f
2 changed files with 41 additions and 0 deletions

View File

@@ -72,6 +72,21 @@ OpenLayers.Feature.prototype= {
}
},
/**
* @returns Whether or not the feature is currently visible on screen
* (based on its 'lonlat' property)
* @type Boolean
*/
onScreen:function() {
var onScreen = false;
if ((this.layer != null) && (this.layer.map != null)) {
var screenBounds = this.layer.map.getExtent();
onScreen = screenBounds.containsLonLat(this.lonlat);
}
return onScreen;
},
/**
* @returns A Marker Object created from the 'lonlat' and 'icon' properties

View File

@@ -76,6 +76,32 @@
"Layer div img contains correct url" );
*/
}
function test_03_Feature_onScreen(t) {
t.plan( 2 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
var wms = new OpenLayers.Layer.WMS(name, url);
map.addLayer(wms);
var layer = new OpenLayers.Layer("foo");
map.addLayer(layer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen feature
var feature1 = new OpenLayers.Feature(layer,
new OpenLayers.LonLat(0,0));
t.ok( feature1.onScreen(), "feature knows it's onscreen" );
//onscreen feature
var feature2 = new OpenLayers.Feature(layer,
new OpenLayers.LonLat(100,100));
t.ok( !feature2.onScreen(), "feature knows it's offscreen" );
}
// -->
</script>