Skip to content

Commit 0dc9821

Browse files
committed
Merge pull request openlayers#446 from candeira/fix_ticket_3554
Fix for trac ticket # 3554 single-arg Map constructor does not work if you pass a DOM element ref
2 parents 94017fe + 6dc97ff commit 0dc9821

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/OpenLayers/Map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ OpenLayers.Map = OpenLayers.Class({
545545
initialize: function (div, options) {
546546

547547
// If only one argument is provided, check if it is an object.
548-
if(arguments.length === 1 && typeof div === "object") {
548+
var isDOMElement = OpenLayers.Util.isElement(div);
549+
if(arguments.length === 1 && typeof div === "object" && !isDOMElement) {
549550
options = div;
550551
div = options && options.div;
551552
}

tests/Map.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@
130130
map.destroy();
131131
}
132132

133+
function test_Map_constructor_renderTo_DOM_element_ref(t) {
134+
t.plan( 1 );
135+
136+
var map_div = document.getElementById('map');
137+
map = new OpenLayers.Map(map_div);
138+
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
139+
"http://octo.metacarta.com/cgi-bin/mapserv?",
140+
{map: "/mapdata/vmap_wms.map", layers: "basic"});
141+
map.addLayer(baseLayer);
142+
143+
var mapDiv = document.getElementById("map");
144+
t.ok(map.div == mapDiv, "Map is rendered to the 'map' div.")
145+
146+
map.destroy();
147+
}
148+
133149
function test_Map_setOptions(t) {
134150
t.plan(2);
135151
map = new OpenLayers.Map('map', {maxExtent: new OpenLayers.Bounds(100, 200, 300, 400)});

0 commit comments

Comments
 (0)