[OpenLayers-Users] Rookie problem with getting a map to draw with Drupal

Gene Sally gsally at touchtown.us
Wed Jan 14 15:46:27 EST 2009


Hi,

I'm trying to use openlayers in conjunction with Drupal and I'm having problems with the map rendering.  The javascript code runs without error, but I don't see the map on the page.  I've been fiddling with this to the point where I'm out of things to try.

I used a debugger (along with trusty alert() :) to make sure that the code was running.  All of the objects are instantiated and there aren't any run-time errors.  All of the code appears to run without error.

I experimented and called the OpenLayers.Map() constructor with an id that I knew wasn't on the page and it failed as expected, so I'm reasonably sure that OpenLayers can find the div with the ID of "map".  The image in question for the image layer exists and I can put the URL in my browser and see the file, so I think that's not at issue.  

This appears to be some sort of drupal related problem as when I strip out all of the drupal code, things work...  But, after struggling I can't seem to pinpoint the nature of the problem.

Here's what I have (my apologies for the code dump, I tried to make it as minimal as possible)  This code appears in a node that allows PHP code.  If anyone can point me in the right direction, I'd really appreciate the help.

Thanks much,
gene

<div id="map"></div>

<script type="text/javascript">

var map;

$(document).ready(function() {

           map = new OpenLayers.Map('map');
            var options = {numZoomLevels: 3};
            var graphic = new OpenLayers.Layer.Image(
                                'Campus Map',
                                'http://192.168.2.198/sites/default/files/images/firstmap.png',
                                new OpenLayers.Bounds(0, 0, 591, 571),
                                new OpenLayers.Size(591, 571),
                                options);
            map.addLayers([graphic]);
            map.zoomToMaxExtent();

});
</script>
<?php
drupal_add_js('misc/openlayers/OpenLayers.js'); 
?>





More information about the Users mailing list