Jump to content

Reloading an XML after clicking a button


altinnovation2

Recommended Posts

Hello, I have this code that reads an external xml file:

 

    <script type="text/javascript">

    //<![CDATA[

 

    if (GBrowserIsCompatible()) {

      var gmarkers = [];

      var gicons = [];

 

      var baseIcon = new GIcon(G_DEFAULT_ICON);

      baseIcon.iconAnchor = new GPoint(9,34);

      baseIcon.iconSize = new GSize(20,34);

      baseIcon.infoWindowAnchor = new GPoint(9,2);

 

 

      gicons["theatre"] = new GIcon(baseIcon,"colour086.png");

      gicons["golf"] = new GIcon(baseIcon,"colour108.png");

      gicons["info"] = new GIcon(baseIcon,"colour125.png");

 

      // A function to create the marker and set up the event window

      function createMarker(point,name,html,category) {

        var marker = new GMarker(point,gicons[category]);

        // === Store the category and name info as a marker properties ===

        marker.mycategory = category;                               

        marker.myname = name;

        GEvent.addListener(marker, "click", function() {

          marker.openInfoWindowHtml(html);

        });

        gmarkers.push(marker);

        return marker;

      }

 

      // == shows all markers of a particular category, and ensures the checkbox is checked ==

      function show(category) {

        for (var i=0; i<gmarkers.length; i++) {

          if (gmarkers.mycategory == category) {

            gmarkers.show();

          }

        }

        // == check the checkbox ==

        document.getElementById(category+"box").checked = true;

      }

 

      // == hides all markers of a particular category, and ensures the checkbox is cleared ==

      function hide(category) {

        for (var i=0; i<gmarkers.length; i++) {

          if (gmarkers.mycategory == category) {

            gmarkers.hide();

          }

        }

        // == clear the checkbox ==

        document.getElementById(category+"box").checked = false;

        // == close the info window, in case its open on a marker that we just hid

        map.closeInfoWindow();

      }

 

      // == a checkbox has been clicked ==

      function boxclick(box,category) {

        if (box.checked) {

          show(category);

        } else {

          hide(category);

        }

        // == rebuild the side bar

        makeSidebar();

      }

 

      function myclick(i) {

        GEvent.trigger(gmarkers,"click");

      }

 

 

      // == rebuilds the sidebar to match the markers currently displayed ==

      function makeSidebar() {

        var html = "";

        for (var i=0; i<gmarkers.length; i++) {

          if (!gmarkers.isHidden()) {

            html += '<a href="javascript:myclick(' + i + ')">' + gmarkers.myname + '<\/a><br>';

          }

        }

        document.getElementById("side_bar").innerHTML = html;

      }

 

 

      // create the map

      var map = new GMap2(document.getElementById("map"));

      map.addControl(new GLargeMapControl());

      map.addControl(new GMapTypeControl());

      map.setCenter(new GLatLng(53.8363,-3.0377), 11);

 

 

      // Read the data

      GDownloadUrl("categories.xml", function(doc) {

        var xmlDoc = GXml.parse(doc);

        var markers = xmlDoc.documentElement.getElementsByTagName("marker");

         

        for (var i = 0; i < markers.length; i++) {

          // obtain the attribues of each marker

          var lat = parseFloat(markers.getAttribute("lat"));

          var lng = parseFloat(markers.getAttribute("lng"));

          var point = new GLatLng(lat,lng);

          var address = markers.getAttribute("address");

          var name = markers.getAttribute("name");

          var html = "<b>"+name+"<\/b><p>"+address;

          var category = markers.getAttribute("category");

          // create the marker

          var marker = createMarker(point,name,html,category);

          map.addOverlay(marker);

        }

 

        // == show or hide the categories initially ==

        show("theatre");

        hide("golf");

        hide("info");

        // == create the initial sidebar ==

        makeSidebar();

      });

    }

 

    else {

      alert("Sorry, the Google Maps API is not compatible with this browser");

    }

    // This Javascript is based on code provided by the

    // Community Church Javascript Team

    // http://www.bisphamchurch.org.uk/ 

    // http://econym.org.uk/gmap/

 

    //]]>

    </script>

 

Notice the section in with bold letters, it loads an XML file.

 

How can I execute a script to load another file by clicking a link?

 

Thank you very much :)))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.