Retrieve information from XML Google Maps

I am currently facing an issue with my code that retrieves data from Google Maps in XML format. The problem I'm encountering is that it only displays the last set of data. How can I resolve this issue?

You can find my code on jsFiddle

function getline() {


downloadUrl("line.php", function(doc) {



        var g = google.maps;

        var xmlDoc = xmlParse(doc);

        bounds = new google.maps.LatLngBounds();

      // ========= Now process the polylines ===========
      var lines = xmlDoc.documentElement.getElementsByTagName("line");

      // read each line
      for (var a = 0; a < lines.length; a++) {
        // get any line attributes
        var colour = lines[a].getAttribute("colour");
        var width  = parseFloat(lines[a].getAttribute("width"));
        var diameter = lines[a].getAttribute("diameter");
        var project = lines[a].getAttribute("projectid");
        var contract = lines[a].getAttribute("contract");
        var comp = lines[a].getAttribute("complated");
        var id = lines[a].getAttribute("id_line");
        // read each point on that line
        var points = lines[a].getElementsByTagName("point");
        var pts = [];
        var length = 0;
        var point = null;

        for (var i = 0; i < points.length; i++) {
           pts[i] = new g.LatLng(parseFloat(points[i].getAttribute("lng")),
                                parseFloat(points[i].getAttribute("lat")));
           if (i > 0) {
             length += pts[i-1].distanceFrom(pts[i]);
             if (isNaN(length)) { alert("["+i+"] length="+length+" segment="+pts[i-1].distanceFrom(pts[i])) };
           }
           bounds.extend(pts[i]);
           point = pts[parseInt(i/2)];

                var info = "<b> Contract: </b>" + contract + " <br/> <b>Project: </b>" + project +"<br/>  <b>Diameter: </b>" + diameter + " <br/> <b>Complated: </b>" + comp + "  <hr><br/><a class=\"inline-link-1\" href=\"#\">Change Data</a> <a class=\"inline-link-1\" href=\"#\">Edit</a> >" + id +"" ;

        }
        // length *= 0.000621371192; // miles/meter 

 if (comp < 1) { 
 colorr = '#FA0505' }

 if (comp > 0 && comp < 25 ) { 
 colorr = '#FFA640' }

 if (comp > 24 && comp < 50) { 
 colorr = '#FFFD91' }

 if (comp > 49 && comp < 75) { 
 colorr = '#E8E400' }

 if (comp > 74 && comp < 100) { 
 colorr = '#BFFFAD' }

 if (comp == 100) { 
 colorr = '#0F8500' }


        var polyline = new g.Polyline({
                          map:map,
                          path:pts,
                          strokeColor:colorr,
                          strokeWeight:width,
                          clickable: true
                          });
       //createClickablePolyline(polyloine, html, label, point, length);
     //  map.addOverlay(polyline);


  google.maps.event.addListener(polyline,'mouseover', function() {


        this.setOptions({strokeColor: '#690469' });
           this.setOptions({strokeOpacity: 1.0 });
           this.setOptions({strokeWeight: 4 });
  });

     google.maps.event.addListener(polyline,'mouseout', function() {


        this.setOptions({strokeColor: colorr });
           this.setOptions({strokeOpacity: 1.0 });
           this.setOptions({strokeWeight: 4 });
  });


  var  mpenc = new google.maps.InfoWindow();
  google.maps.event.addListener(polyline,'click', function(event) {
    mpenc.setContent(info, this);
    mpenc.setPosition(event.latLng, this);
    mpenc.open(map);
  });

      }
      map.fitBounds(bounds);




    });



}

Answer №1

It seems like you've taken some code, made changes to it, and then commented it out. What was the reason for doing so?

//createClickablePolyline(polyline, html, label, point, length);

This function is crucial for establishing a connection between the "data", polyline, and infowindow in my customized versions of the code.

Here's a fully functional v3 version of the code I've been working on.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sorting WordPress entries by nearby locations

I have WordPress posts that are being displayed on a Google Map. The posts are pulling data from a custom post field that contains the latlng value, where latitude and longitude are combined into one. Additionally, the map shows the user's location u ...

Ways to avoid overflow of dynamically added div element?

Currently, I am facing an issue while dynamically appending div elements with the .magnet class to my page. These elements end up overflowing the container boundaries and I am struggling to find a solution for this problem. If anyone could check out my j ...

Slider malfunctioning following AJAX loading

After the user clicks on #mail-wrap, I am attempting to trigger the ready event which loads another page with AJAX so that sss() can be refired. Despite my efforts, it seems like it is not working as expected. Can you help me identify what might be going w ...

I'm having trouble getting the npm install for classnames to work within my li tag

I need some help with React JS. I'm attempting to merge my classes using the npm package called classnames. https://www.npmjs.com/package/classnames However, I'm encountering an issue: classnames doesn't seem to be working as expecte ...

What is the best way to deactivate the second selection option?

<select id="title0"> <option value="0">--- disable</option> <option value="1"> books</option> </select> <button id="save" type="submit">Save</button> <select id="title1"> <option value="0"& ...

Encountering a jQuery error while attempting to initiate an AJAX request

I'm currently working on a project in SharePoint and I want to integrate JQuery to make an ajax call from the homepage. However, when I attempt to make the call, I encounter an error stating "Array.prototype.slice: 'this' is not a JavaScript ...

Determine if a MySQL query in node.js returns no results

I'm trying to determine if there are no matching results in MySQL using Node.js. How can I achieve this? mysql.query("select * from table1 where name = 'abcd'", function(error, result, field) { if(error) { handleNoError(error); ...

The module specifier "tslib" could not be resolved due to a TypeError. It is necessary for relative references to begin with either "/", "./", or "../"

Hey there, I recently started learning npm. I'm trying to install "@fullcalendar" and use it, but I keep getting this error message: "Uncaught TypeError: Failed to resolve module specifier "tslib". Relative references must start with either "/", "./", ...

Enable arrow keys feature in Regular Expressions

Currently, I am implementing alphanumeric validation to ensure that users can only input alphanumeric values and also paste alphanumeric values exclusively. In order to achieve this, I have utilized the following regular expression: function OnlyAlphaNum ...

Is there a way to seamlessly roll the camera using a button in ThreeJS alongside TrackballControls without causing any conflicts?

When working with ThreeJS, I encountered an issue with rotating the camera using a button. Here is the code snippet I used: camera = new THREE.PerspectiveCamera(...) function roll(angle) { const quaternion = new THREE.Quaternion(); const lookat = ...

Issue: ASSERTION ERROR: token must be declared [Expecting => null is not undefined <=Actual]

I encountered an error while working on my project. The only special thing I did was use oidc(openId) for authentication. I made some changes to the bootstrap project and now the first component that is running is the home-main component, which includes t ...

Exploring the Magic of Class Variable Destructuring in React

Is there a simpler method to break down a prop object and assign them to variables of the same name in the class? I am familiar with ({ first: this.first, second: this.second, } = props) however, it can get complicated when dealing with numerous variable ...

Tips for utilizing onsubmit following an ajax validation check

How can I implement the onsubmit method after an ajax check? The current onsubmit function is not working. $(document).ready(function(){ $("#p_code").change(function(){ $("#message").html("<img src='ajax_loader.gif' width='26 ...

New replacement for the .selector method that has been eliminated in JQuery version 3.0

The JQuery version 3.0 has permanently removed the .selector property, leaving me confused about what to use as a replacement for it. I currently have utilized the .selector like this in my code: var TaxYearNode = $(EmployerLatestYear).find("TaxYear&q ...

Interactive ajax and php dropdown menu

Hey there, I'm running into a small snag with my dynamic select feature, as mentioned in the title. I am aiming to achieve the following outcome: When a user selects an instrument from the first dropdown menu, the second dropdown menu labeled "Besetzu ...

What are effective ways to eliminate script tags from a webpage?

I have implemented tags on my website that users can use to interact with the site. My goal is to figure out how to make the browser only read text from a specific file I write, without any HTML. This should be restricted to certain sections of my websit ...

Dynamically Loading External JavaScript Files Depending on User Input

Looking for guidance on how to dynamically load a single javascript file out of several options based on user input in an HTML code. Any suggestions on how to achieve this task? Thank you! ...

Storing JSON data in a MongoDb database using the Sails.js framework

I'm looking to build my database using an external API. To begin, I've created a function called loadData(req, res){} in my DBController that retrieves data from the API in JSON format. Now, I want to save this imported JSON data into my mongoDB ...

Using JavaScript/JQuery to Access an External SQLite Database

Is there a way to incorporate my own SQLite database into a website using JavaScript and JQuery? I've searched for examples but have yet to find any helpful articles on the topic! ...

Javascript JSON is unable to retrieve the tag

Looking at this JSON structure: { "armament": { "air_armament": [ { "names": { "russian_name": "R-60", "NATO_name": "AA-8 Aphid" }, "weight": " ...