the test to check if layer is drawn before we draw feature is moved to drawFeature method so that it doesn't fail when called directly at the application level r=elemoine,crschmidt (Closes #1785)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8189 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
pgiraud
2008-10-24 08:29:01 +00:00
parent 58fc08d574
commit 33e5bd7d7d
2 changed files with 17 additions and 5 deletions

View File

@@ -491,9 +491,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
this.preFeatureInsert(feature);
}
if (this.drawn) {
this.drawFeature(feature);
}
this.drawFeature(feature);
if (notify) {
this.events.triggerEvent("featureadded", {
@@ -612,6 +610,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
* style - {Object} Symbolizer hash or {String} renderIntent
*/
drawFeature: function(feature, style) {
// don't try to draw the feature with the renderer if the layer is not
// drawn itself
if (!this.drawn) {
return
}
if (typeof style != "object") {
var renderIntent = typeof style == "string" ?
style : feature.renderIntent;

View File

@@ -161,7 +161,7 @@
}
function test_Layer_Vector_drawFeature(t) {
t.plan(6);
t.plan(7);
var layer = new OpenLayers.Layer.Vector("Test Layer", {isBaseLayer: true});
var map = new OpenLayers.Map('map', {
maxExtent: new OpenLayers.Bounds(-100, -100, 100, 100)
@@ -173,7 +173,8 @@
var f, s;
// Bogus layer renderer needs some methods
// for functional tests.
// for functional tests.
layer.drawn = true;
layer.renderer = {
drawFeature: function(feature, style) {
f = feature;
@@ -212,7 +213,14 @@
layer.renderer.drawFeature = function(feature) {
return(feature.geometry.getBounds().intersectsBounds(map.getExtent()));
}
// reset the drawn to null as if the layer had never been rendered
layer.drawn = null;
layer.drawFeature(feature);
t.ok(true, "Trying to draw a feature on an not drawn layer doesn't throw any error.");
layer.addFeatures([feature]);
map.setCenter(new OpenLayers.Bounds(0, 0, 0, 0), 6);
t.ok(layer.unrenderedFeatures[feature.id], "Did not render feature outside the viewport.");
map.panTo(new OpenLayers.LonLat(10, 10));