[OpenLayers-Trac] [OpenLayers] #3554: single-arg Map constructor does not work if you pass a DOM element ref

OpenLayers trac-20090302 at openlayers.org
Wed Oct 19 12:31:45 EDT 2011


#3554: single-arg Map constructor does not work if you pass a DOM element ref
----------------------+-----------------------------------------------------
 Reporter:  domurtag  |       Owner:      
     Type:  bug       |      Status:  new 
 Priority:  major     |   Milestone:      
Component:  Map       |     Version:  2.11
 Keywords:            |       State:      
----------------------+-----------------------------------------------------
 The docs for OpenLayers.Map indicate that you can pass a DOM element into
 the single-arg constructor. You can verify that it doesn't work with:

 {{{

 <html>
         <body>
         <div id="mapdiv"></div>

         <script
 src="http://www.openlayers.org/api/OpenLayers.js"></script>

         <script type="text/javascript">
                 function Map(element) {
                 var map = new OpenLayers.Map(element);
                         map.addLayer(new OpenLayers.Layer.OSM());
                         map.zoomToMaxExtent();
                 }

                 var mapContainer = document.getElementById('mapdiv');
                 var map = new Map(mapContainer);
         </script>
         </body>
 </html>
 }}}

 You can workaround this problem, by replacing the last line above with:

 {{{
 var map = new Map({div: mapContainer});
 }}}

-- 
Ticket URL: <http://trac.openlayers.org/ticket/3554>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list