getting rid of unnecessary, undocumented 'drawn' property on marker. replacing it with accessor function isDrawn(), and putting an isDrawn() in icon as well. all tests pass r=elemoine (Closes #1759)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8091 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -193,6 +193,22 @@ OpenLayers.Icon = OpenLayers.Class({
|
|||||||
display: function(display) {
|
display: function(display) {
|
||||||
this.imageDiv.style.display = (display) ? "" : "none";
|
this.imageDiv.style.display = (display) ? "" : "none";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: isDrawn
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Boolean} Whether or not the icon is drawn.
|
||||||
|
*/
|
||||||
|
isDrawn: function() {
|
||||||
|
// nodeType 11 for ie, whose nodes *always* have a parentNode
|
||||||
|
// (of type document fragment)
|
||||||
|
var isDrawn = (this.imageDiv && this.imageDiv.parentNode &&
|
||||||
|
(this.imageDiv.parentNode.nodeType != 11));
|
||||||
|
|
||||||
|
return isDrawn;
|
||||||
|
},
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Icon"
|
CLASS_NAME: "OpenLayers.Icon"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ OpenLayers.Layer.Markers = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
if ((marker.icon != null) && (marker.icon.imageDiv != null) &&
|
if ((marker.icon != null) && (marker.icon.imageDiv != null) &&
|
||||||
(marker.icon.imageDiv.parentNode == this.div) ) {
|
(marker.icon.imageDiv.parentNode == this.div) ) {
|
||||||
this.div.removeChild(marker.icon.imageDiv);
|
this.div.removeChild(marker.icon.imageDiv);
|
||||||
marker.drawn = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -156,10 +155,9 @@ OpenLayers.Layer.Markers = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
if (px == null) {
|
if (px == null) {
|
||||||
marker.display(false);
|
marker.display(false);
|
||||||
} else {
|
} else {
|
||||||
var markerImg = marker.draw(px);
|
if (!marker.isDrawn()) {
|
||||||
if (!marker.drawn) {
|
var markerImg = marker.draw(px);
|
||||||
this.div.appendChild(markerImg);
|
this.div.appendChild(markerImg);
|
||||||
marker.drawn = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -129,6 +129,17 @@ OpenLayers.Marker = OpenLayers.Class({
|
|||||||
this.lonlat = this.map.getLonLatFromLayerPx(px);
|
this.lonlat = this.map.getLonLatFromLayerPx(px);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: isDrawn
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Boolean} Whether or not the marker is drawn.
|
||||||
|
*/
|
||||||
|
isDrawn: function() {
|
||||||
|
var isDrawn = (this.icon && this.icon.isDrawn());
|
||||||
|
return isDrawn;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: onScreen
|
* Method: onScreen
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,6 +33,32 @@
|
|||||||
icon.setOpacity(0.5);
|
icon.setOpacity(0.5);
|
||||||
t.eq(parseFloat(icon.imageDiv.style.opacity), 0.5, "icon.setOpacity() works");
|
t.eq(parseFloat(icon.imageDiv.style.opacity), 0.5, "icon.setOpacity() works");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Icon_isDrawn(t) {
|
||||||
|
t.plan(4);
|
||||||
|
|
||||||
|
var icon = {};
|
||||||
|
|
||||||
|
//no imageDiv
|
||||||
|
var drawn = OpenLayers.Icon.prototype.isDrawn.apply(icon, []);
|
||||||
|
t.ok(!drawn, "icon with no imageDiv not drawn");
|
||||||
|
|
||||||
|
//imageDiv no parentNode
|
||||||
|
icon.imageDiv = {};
|
||||||
|
drawn = OpenLayers.Icon.prototype.isDrawn.apply(icon, []);
|
||||||
|
t.ok(!drawn, "icon with imageDiv with no parentNode not drawn");
|
||||||
|
|
||||||
|
//imageDiv with parent
|
||||||
|
icon.imageDiv.parentNode = {};
|
||||||
|
drawn = OpenLayers.Icon.prototype.isDrawn.apply(icon, []);
|
||||||
|
t.ok(drawn, "icon with imageDiv with parentNode drawn");
|
||||||
|
|
||||||
|
//imageDiv with parent but nodetype 11
|
||||||
|
icon.imageDiv.parentNode = {'nodeType': 11};
|
||||||
|
drawn = OpenLayers.Icon.prototype.isDrawn.apply(icon, []);
|
||||||
|
t.ok(!drawn, "imageDiv with parent but nodetype 11 not drawn");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
t.ok(true, "removing marker when no markers present does not script error");
|
t.ok(true, "removing marker when no markers present does not script error");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Layer_Markers_destroy (t) {
|
function test_Layer_Markers_destroy (t) {
|
||||||
t.plan( 1 );
|
t.plan( 1 );
|
||||||
layer = new OpenLayers.Layer.Markers('Test Layer');
|
layer = new OpenLayers.Layer.Markers('Test Layer');
|
||||||
|
|||||||
@@ -134,6 +134,26 @@
|
|||||||
t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map");
|
t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map");
|
||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Marker_isDrawn(t) {
|
||||||
|
t.plan(3);
|
||||||
|
|
||||||
|
var marker = {};
|
||||||
|
|
||||||
|
//no icon
|
||||||
|
var drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
|
||||||
|
t.ok(!drawn, "marker with no icon not drawn");
|
||||||
|
|
||||||
|
//not drawn icon
|
||||||
|
marker.icon = { isDrawn: function() { return false; } };
|
||||||
|
drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
|
||||||
|
t.ok(!drawn, "marker with not drawn icon not drawn");
|
||||||
|
|
||||||
|
//drawn icon
|
||||||
|
marker.icon.isDrawn = function() { return true; };
|
||||||
|
drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
|
||||||
|
t.ok(drawn, "marker with drawn icon drawn");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user