From 33e5bd7d7dac76726b9a02f609a09b182819899f Mon Sep 17 00:00:00 2001 From: pgiraud Date: Fri, 24 Oct 2008 08:29:01 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Layer/Vector.js | 10 +++++++--- tests/Layer/Vector.html | 12 ++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index d27c3f06df..93b47d5de7 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -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; diff --git a/tests/Layer/Vector.html b/tests/Layer/Vector.html index 0a61ce5d56..5cb3708b93 100644 --- a/tests/Layer/Vector.html +++ b/tests/Layer/Vector.html @@ -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));