Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-04-2012, 08:50 AM   PM User | #1
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
How to import XML data generated with PHP from MySQL into a JavaScript code?

I am working with Google Maps API and to add a layer of heatmap over it. This is the source code :-
Code:
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
    <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization"></script>
    <script>
      // Adding 500 Data Points
      var map, pointarray, heatmap;

      var taxiData = [
        new google.maps.LatLng(37.782551, -122.445368),
        new google.maps.LatLng(37.782745, -122.444586),
        new google.maps.LatLng(37.782842, -122.443688),
        new google.maps.LatLng(37.782919, -122.442815),
        new google.maps.LatLng(37.782992, -122.442112),
        new google.maps.LatLng(37.783100, -122.441461),
        new google.maps.LatLng(37.783206, -122.440829),
        new google.maps.LatLng(37.783273, -122.440324),
        new google.maps.LatLng(37.783316, -122.440023),
        new google.maps.LatLng(37.783357, -122.439794),
        new google.maps.LatLng(37.783371, -122.439687),
        new google.maps.LatLng(37.783368, -122.439666),
        new google.maps.LatLng(37.755503, -122.403406),
        new google.maps.LatLng(37.754665, -122.403242),
        new google.maps.LatLng(37.753837, -122.403172),
        new google.maps.LatLng(37.752986, -122.403112),
        new google.maps.LatLng(37.751266, -122.403355)
      ];

      function initialize() {
        var mapOptions = {
          zoom: 13,
          center: new google.maps.LatLng(37.774546, -122.433523),
          mapTypeId: google.maps.MapTypeId.SATELLITE
        };

        map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);

        pointArray = new google.maps.MVCArray(taxiData);

        heatmap = new google.maps.visualization.HeatmapLayer({
          data: pointArray
        });

        heatmap.setMap(map);
      }

      function toggleHeatmap() {
        heatmap.setMap(heatmap.getMap() ? null : map);
      }

      function changeGradient() {
        var gradient = [
          'rgba(0, 255, 255, 0)',
          'rgba(0, 255, 255, 1)',
          'rgba(0, 191, 255, 1)',
          'rgba(0, 127, 255, 1)',
          'rgba(0, 63, 255, 1)',
          'rgba(0, 0, 255, 1)',
          'rgba(0, 0, 223, 1)',
          'rgba(0, 0, 191, 1)',
          'rgba(0, 0, 159, 1)',
          'rgba(0, 0, 127, 1)',
          'rgba(63, 0, 91, 1)',
          'rgba(127, 0, 63, 1)',
          'rgba(191, 0, 31, 1)',
          'rgba(255, 0, 0, 1)'
        ]
        heatmap.setOptions({
          gradient: heatmap.get('gradient') ? null : gradient
        });
      }

      function changeRadius() {
        heatmap.setOptions({radius: heatmap.get('radius') ? null : 20});
      }

      function changeOpacity() {
        heatmap.setOptions({opacity: heatmap.get('opacity') ? null : 0.2});
      }
    </script>
  </head>

  <body onload="initialize()">
    <div id="map_canvas" style="height: 600px; width: 800px;"></div>
    <button onclick="toggleHeatmap()">Toggle Heatmap</button>
    <button onclick="changeGradient()">Change gradient</button>
    <button onclick="changeRadius()">Change radius</button>
    <button onclick="changeOpacity()">Change opacity</button>
  </body>
</html>
The above code creates a heatmap over Google Map. See their original documentation here :-
Code:
https://developers.google.com/maps/documentation/javascript/layers
There is documentation for the heatmap layer. In that, instead of merely adding Latitude and Longitude, there is option to add an intensity value too , the latter making the heatmap areas red where intensity is high and green where it is low...This can be given as shown below (like it is in documentation. The example is shown below) :-
Code:
var heatMapData = [
  {location: new google.maps.LatLng(37.782, -122.447), weight: 0.5},
  new google.maps.LatLng(37.782, -122.445),
  {location: new google.maps.LatLng(37.782, -122.443), weight: 2},
  {location: new google.maps.LatLng(37.782, -122.441), weight: 3},
  {location: new google.maps.LatLng(37.782, -122.439), weight: 2},
  new google.maps.LatLng(37.782, -122.437),
  {location: new google.maps.LatLng(37.782, -122.435), weight: 0.5},

  {location: new google.maps.LatLng(37.785, -122.447), weight: 3},
  {location: new google.maps.LatLng(37.785, -122.445), weight: 2},
  new google.maps.LatLng(37.785, -122.443),
  {location: new google.maps.LatLng(37.785, -122.441), weight: 0.5},
  new google.maps.LatLng(37.785, -122.439),
  {location: new google.maps.LatLng(37.785, -122.437), weight: 2},
  {location: new google.maps.LatLng(37.785, -122.435), weight: 3}
];
Now, I have an XML file which contains latitude,longitude and intensity values. The PHP code that generates this XML file is :-
Code:
<?php
error_reporting(E_PARSE);
function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",''',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a MySQL server
$connection=mysql_connect ("localhost","root","mysqlegregious");
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db("googlemaps");
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'intensity="' . $row['intensity'] . '" ';
  echo '/>';
}
I am totally new to JavaScript, but has a grip on PHP and MySQL.

As you can see from the first code, the heatmap generation is via client side through JavaScript. I want it to be more flexible and dynamic so that the Javascript values in the SECOND code that I posted can be imported from the XML data that I generated through MySQL. Is it possible?

Thanks in advance....
egregious is offline   Reply With Quote
Old 09-04-2012, 02:29 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
yes, it's very possible. You make an ajax call to retrieve the xml file then iterate through the nodes, building your array.

google made a little tutorial that does more or less what you are trying to do - dunno if you have seen it. It's here
xelawho is online now   Reply With Quote
Users who have thanked xelawho for this post:
egregious (09-04-2012)
Old 09-04-2012, 02:42 PM   PM User | #3
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
yes, it's very possible. You make an ajax call to retrieve the xml file then iterate through the nodes, building your array.

google made a little tutorial that does more or less what you are trying to do - dunno if you have seen it. It's here
Yes, I have seen that already and tested it. It's working.

But here , I want to import XML data as a MVC array like the one shown in the first code. Then it can be easily made into a heatmap layer. I am new to the scripting of JavaScript and that is why I am confused...
egregious is offline   Reply With Quote
Old 09-04-2012, 02:54 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I don't know if I'm getting the difference - you import your data via ajax, create the objects, push them onto an array and initialize it as an MVC array. That last bit's easy:

Code:
pointArray = new google.maps.MVCArray(taxiData);
what specifically are you getting confused about?
xelawho is online now   Reply With Quote
Old 09-04-2012, 03:07 PM   PM User | #5
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
I don't know if I'm getting the difference - you import your data via ajax, create the objects, push them onto an array and initialize it as an MVC array. That last bit's easy:

Code:
pointArray = new google.maps.MVCArray(taxiData);
what specifically are you getting confused about?
I am not confused about the script of the first code. The first code is just an example and as such it is not what I want.

I want an XML data generated by my PHP code to get incorporated into the array of 'taxidata' so that it offers me a much more dynamic choice.

Otherwise, I would have to type in the various Lat and Long positions myself in the JavaScript.

My XML output is of the form
Code:
<markers>
<marker> lat="",long="",intensity=""/>
</markers>
I want this 'lat', 'long','intensity' to be incorported into the first code (that is, instead of the example data of the taxidata array, I want my XML data to be part of it) so that it's more dynamic.


In that taxidata example, there is only the Lat and Long options. But Google documentation says that it's possible to include an additional variable of intensity in it too. That intensity value is there in my XML data.
egregious is offline   Reply With Quote
Old 09-04-2012, 03:20 PM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
right. so if your code is how I imagine it, and if you have an empty heatMapData array to push objects onto, wouldn't it be something like this:

Code:
var markers = xml.documentElement.getElementsByTagName("marker");
  for (var i = 0; i < markers.length; i++) {
    var int = markers[i].getAttribute("intensity");
    var point = new google.maps.LatLng(
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng")));
    var hObj = {
      location: point,
      weight: int
    }
heatMapData.push(hObj);
}
xelawho is online now   Reply With Quote
Users who have thanked xelawho for this post:
egregious (09-04-2012)
Old 09-04-2012, 03:34 PM   PM User | #7
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
right. so if your code is how I imagine it, and if you have an empty heatMapData array to push objects onto, wouldn't it be something like this:

Code:
var markers = xml.documentElement.getElementsByTagName("marker");
  for (var i = 0; i < markers.length; i++) {
    var int = markers[i].getAttribute("intensity");
    var point = new google.maps.LatLng(
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng")));
    var hObj = {
      location: point,
      weight: int
    }
heatMapData.push(hObj);
}
Yes, exactly.

The example given in Google Maps API documentation is given below :-
Code:
/* Data points defined as a mixture of WeightedLocation and LatLng objects */
var heatMapData = [
  {location: new google.maps.LatLng(37.782, -122.447), weight: 0.5},
  new google.maps.LatLng(37.782, -122.445),
  {location: new google.maps.LatLng(37.782, -122.443), weight: 2},
  {location: new google.maps.LatLng(37.782, -122.441), weight: 3},
  {location: new google.maps.LatLng(37.782, -122.439), weight: 2},
  new google.maps.LatLng(37.782, -122.437),
  {location: new google.maps.LatLng(37.782, -122.435), weight: 0.5},

  {location: new google.maps.LatLng(37.785, -122.447), weight: 3},
  {location: new google.maps.LatLng(37.785, -122.445), weight: 2},
  new google.maps.LatLng(37.785, -122.443),
  {location: new google.maps.LatLng(37.785, -122.441), weight: 0.5},
  new google.maps.LatLng(37.785, -122.439),
  {location: new google.maps.LatLng(37.785, -122.437), weight: 2},
  {location: new google.maps.LatLng(37.785, -122.435), weight: 3}
];

var sanFrancisco = new google.maps.LatLng(37.774546, -122.433523);

map = new google.maps.Map(document.getElementById('map_canvas'), {
  center: sanFrancisco,
  zoom: 13,
  mapTypeId: google.maps.MapTypeId.SATELLITE
});

var heatmap = new google.maps.visualization.HeatmapLayer({
  data: heatMapData
});
heatmap.setMap(map);
As you can see, they have entered 'data' in variable heatmap as 'heatMapData', which in our case , would be 'hObj' , I presume.

Will try this and let you know soon
egregious is offline   Reply With Quote
Old 09-04-2012, 03:39 PM   PM User | #8
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I think not. hObj is just a name for the objects getting pushed onto the array.

If you look, google passes the entire array to the HeatmapLayer object, so I am thinking that in your case it would be:
Code:
var heatmap = new google.maps.visualization.HeatmapLayer({
  data: heatMapData
});
heatmap.setMap(map);
as well
xelawho is online now   Reply With Quote
Old 09-04-2012, 04:04 PM   PM User | #9
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
I think not. hObj is just a name for the objects getting pushed onto the array.

If you look, google passes the entire array to the HeatmapLayer object, so I am thinking that in your case it would be:
Code:
var heatmap = new google.maps.visualization.HeatmapLayer({
  data: heatMapData
});
heatmap.setMap(map);
as well
I am not sure. Because in the Google example, the array name is heatMapData.

In this case, our data is of latitude and longitude is in the variable named 'hObj'.

By the way, I tried this code and it didn't work :-
Code:
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map { height: 100%;
      float:right; }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization"></script>
<script type="text/javascript">

function initialize() {
        var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(21.1438, 79.0926),
          mapTypeId: google.maps.MapTypeId.SATELLITE
        };
        downloadUrl("phpsqlajax_genxml.php", function(data) {
           var xml = data.responseXML;
           var markers = xml.documentElement.getElementsByTagName("marker");
             for (var i = 0; i < markers.length; i++) {
                    var point = new google.maps.LatLng(
                    parseFloat(markers[i].getAttribute("lat")),
                    parseFloat(markers[i].getAttribute("lng")));
                  var hObj = {
                              point
                               }
}
}
         map = new google.maps.Map(document.getElementById('map'),
            mapOptions);
         var heatmap = new google.maps.visualization.HeatmapLayer({
             data: hObj
});
heatmap.setMap(map);
}
</script>
</head>
<body onload="initialize()">
    <div id="map" style="height: 600px; width: 800px;"></div>
  </body>
</html>
egregious is offline   Reply With Quote
Old 09-04-2012, 05:11 PM   PM User | #10
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
You're not listening. hObj is just an object, and every time the loop iterates it gets overwritten. That's why you need to push it onto an array (inside the loop) and then pass the array to the heatMapLayer (outside the loop).

I would try this:

Code:
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map { height: 100%;
      float:right; }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization"></script>
<script type="text/javascript">
var heatMapData=[]//empty array to store objects

function initialize() {
        var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(21.1438, 79.0926),
          mapTypeId: google.maps.MapTypeId.SATELLITE
        };
        downloadUrl("phpsqlajax_genxml.php", function(data) {
           var xml = data.responseXML;
           var markers = xml.documentElement.getElementsByTagName("marker");
  for (var i = 0; i < markers.length; i++) { //loop through nodes getting info
    var int = markers[i].getAttribute("intensity");
    var point = new google.maps.LatLng(
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng")));
    var hObj = { //create object
      location: point,
      weight: int
    }
heatMapData.push(hObj); //push object onto array
}
}
         pointArray = new google.maps.MVCArray(heatMapData); //convert array to MVC array

        heatmap = new google.maps.visualization.HeatmapLayer({
          data: pointArray
        }); //create heat map object

        heatmap.setMap(map); //display heat map on map
}
</script>
</head>
<body onload="initialize()">
    <div id="map" style="height: 600px; width: 800px;"></div>
  </body>
</html>
xelawho is online now   Reply With Quote
Users who have thanked xelawho for this post:
egregious (09-04-2012)
Old 09-04-2012, 07:04 PM   PM User | #11
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Right, I got this.

Did try your code. But it didn't work. Did a few editing by myself and still can not seem to get it working.

Code:
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas{ height: 100%;}
    </style>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&libraries=visualization"></script>
<script type="text/javascript">
var heatMapData=[]//empty array to store objects
function initialize() {
        var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(21.1438, 79.0926),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
        downloadUrl("phpsqlajax_genxml_heatmap.php", function(data) {
           var xml = data.responseXML;
           var markers = xml.documentElement.getElementsByTagName("marker");
  for (var i = 0; i < markers.length; i++) { //loop through nodes getting info
    var int = markers[i].getAttribute("intensity");
    var point = new google.maps.LatLng(
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng")));
    var hObj = { //create object
      location: point,
      weight: int
    }
heatMapData.push(hObj); //push object onto array
}
}
         pointArray = new google.maps.MVCArray(heatMapData); //convert array to MVC array

        heatmap = new google.maps.visualization.HeatmapLayer({
          data: pointArray
        }); //create heat map object

        heatmap.setMap(map); //display heat map on map
}
  function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }
    function doNothing() {}
</script>
</head>
<body onload="initialize()">
    <div id="map_canvas"></div>
  </body>
</html>
egregious is offline   Reply With Quote
Old 09-04-2012, 10:49 PM   PM User | #12
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I think it might be time to see a link to your map
xelawho is online now   Reply With Quote
Old 09-05-2012, 06:26 AM   PM User | #13
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
I think it might be time to see a link to your map
Well, I am getting the Google Map image. There were a few syntax errors in the original code. I corrected them. But still the heatmap layer is not coming over the Map image.

Code:
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Google Maps JavaScript API v3 Example: Heatmap Layer</title>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas{ height: 100%;}
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization"></script>
<script type="text/javascript">
var heatMapData=[];//empty array to store objects
var pointArray;
var heatmap;
     function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }
    function doNothing() {}
       
function initialize() {
        var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(21.1438, 79.0926),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);

downloadUrl("phpsqlajax_genxml_heatmap.php", function(data) {
           var xml = data.responseXML;
           var markers = xml.documentElement.getElementsByTagName("marker");
  for (var i = 0; i < markers.length; i++) { //loop through nodes getting info
        var point = new google.maps.LatLng(
        parseFloat(markers[i].getAttribute("lat")),
        parseFloat(markers[i].getAttribute("lng")));
        var intensity = markers[i].getAttribute("intensity");
    var hObj = { //create object
      location: point,
      weight: intensity
    }
heatMapData.push(hObj); //push object onto array
}
});
       pointArray = new google.maps.MVCArray(heatMapData); //convert array to MVC array
       heatmap = new google.maps.visualization.HeatmapLayer({
          data: pointArray
        }); //create heat map object

        heatmap.setMap(map); //display heat map on map
}
 function toggleHeatmap() {
        heatmap.setMap(heatmap.getMap() ? null : map);
      }

      function changeGradient() {
        var gradient = [
          'rgba(0, 255, 255, 0)',
          'rgba(0, 255, 255, 1)',
          'rgba(0, 191, 255, 1)',
          'rgba(0, 127, 255, 1)',
          'rgba(0, 63, 255, 1)',
          'rgba(0, 0, 255, 1)',
          'rgba(0, 0, 223, 1)',
          'rgba(0, 0, 191, 1)',
          'rgba(0, 0, 159, 1)',
          'rgba(0, 0, 127, 1)',
          'rgba(63, 0, 91, 1)',
          'rgba(127, 0, 63, 1)',
          'rgba(191, 0, 31, 1)',
          'rgba(255, 0, 0, 1)'
        ]
        heatmap.setOptions({
          gradient: heatmap.get('gradient') ? null : gradient
        });
      }

      function changeRadius() {
        heatmap.setOptions({radius: heatmap.get('radius') ? null : 20});
      }

      function changeOpacity() {
        heatmap.setOptions({opacity: heatmap.get('opacity') ? null : 0.2});
      }


</script>
</head>
 <body onload="initialize()">
    <div id="map_canvas" style="height: 600px; width: 800px;">
    </div>
    <button onclick="toggleHeatmap()">Toggle Heatmap</button>
    <button onclick="changeGradient()">Change gradient</button>
    <button onclick="changeRadius()">Change radius</button>
    <button onclick="changeOpacity()">Change opacity</button>
  </body>
</html>
egregious is offline   Reply With Quote
Old 09-05-2012, 02:26 PM   PM User | #14
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
Right. I think it might be time to see a link to your map
xelawho is online now   Reply With Quote
Old 09-08-2012, 03:40 PM   PM User | #15
egregious
New Coder

 
Join Date: Sep 2012
Posts: 24
Thanks: 10
Thanked 1 Time in 1 Post
egregious is an unknown quantity at this point
Quote:
Originally Posted by xelawho View Post
Right. I think it might be time to see a link to your map
I finally did it.

But there is one problem. If we refresh the page, the layer goes missing.
egregious is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:59 AM.


Advertisement
Log in to turn off these ads.