Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an OpenLayers map on my JQM site which is failing to load properly. I'm convinced it's down to the onclick() method but I'm not too sure on any other ways around it. I've looked at the .click() method on the JQuery site but I don't think this will work due to how the method has to work.

The onclick() method is located within a list and loads a JS function which updates the html on another page. The list is populated by a PHP loop which gets it data from an array; the HTML which is changed depends on which item is picked. The function also creates the map on the same page.

Here is the PHP loop:

<?php       
          for ($row = 0; $row < $arrlength; $row++)
          {
              echo "<li>";   
              echo "<a href='#room-info' onclick='updateRoom(\"".$rooms[$row]["Room"]."\", \"".$rooms[$row]["Building"]."\", \"".$rooms[$row]["Campus"]."\", \"".$rooms[$row]["X"]."\", \"".$rooms[$row]["Y"]."\");'>";
              echo $rooms[$row]["Room"];
              echo "</a>"; 
              echo "</li>";
          }
?>

Here is the JS function:

function updateRoom(roomNumber, building, campus, xCoor, yCoor)
    {
        x=document.getElementById("roomInfo");  // Find the element
        x.innerHTML="<h1>Room</h1>" + roomNumber + "<br><h1>Building</h1>" + building + "<br><h1>Campus</h1>" + campus;    // Change the content

        var map, baseLayer;
        var options = {numZoomLevels: 7, isBaseLayer: true,};

        map = new OpenLayers.Map('map');            
        baseLayer = new OpenLayers.Layer.Image("College Lane","college-lane-large.png", 
        new OpenLayers.Bounds(-1000, -1000, 1000, 1000),
        new OpenLayers.Size(1500,1500), options);
        map.addLayer(baseLayer);

        var center = new OpenLayers.LonLat(xCoor,yCoor);
        map.setCenter(center ,0);  

        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.addControl(new OpenLayers.Control.MousePosition());

        var size = new OpenLayers.Size(21,25);
        var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
        var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);
        var markers = new OpenLayers.Layer.Markers( "Marker" );
        map.addLayer(markers);
        markers.addMarker(new OpenLayers.Marker(center), icon);
    }

Once an item is chosen, you are then taken to a page which shows the updated HTML and also the OpenLayers map. The html text updates correctly but the OpenLayers map is empty.

I would put the code on here but there is quite a bit. My site can be found here: http://getontinternet.com/fyp/index.php

To get to the troublesome page you have to first click 'find a room', search LC154 since this is the only item I have set up properly. Once that room is selected it will show the page.

I've been trying to fix this for days now so I will be so grateful is someone actually manages to figure out why it's not working :)

share|improve this question
check the chat chat.stackoverflow.com/rooms/27727/… – Omar Apr 9 at 13:25

1 Answer

Your result page gives this errors: TypeError: $.event.handle is undefined. I think you should take a look at: Getting back the event handler returns undefined

share|improve this answer
I'm not too sure I understand. Do you think onclick() is the problem? Should I be using addEventListener() instead? – mrpopo Apr 8 at 19:09
Maybe i was wrong. The js erros show before the map shows. When i use the openlayers demo can i can show your map ([demomap]gizzing.nl/map.html). You have a comma behind "true" in your option which me break IE. I found you use the newest versions of jquery / jqm. The openlayer example code use older versions. I use jquery-1.8.2 and jquery.mobile-1.3.0. – Bass Jobsen Apr 8 at 21:55
do you think switching to the older versions will help? – mrpopo Apr 8 at 22:13
maybe. Have you test your map without jqm? – Bass Jobsen Apr 8 at 22:22
Well the map actually works on another one of my pages where it's just a default map here:getontinternet.com/fyp/college-lane.html# It's only when I try create the map using variables that it goes wrong. – mrpopo Apr 8 at 22:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.