Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 13 — I Need to Get To... 257


routedescription.value = ‘’;
infopanel.innerHTML = ‘’;
message.innerHTML = ‘Recording a new route’;
map.clearOverlays();
startRoute();
}


The route ID variable is set to zero, because this triggers the creation of a new route when the
route is saved to the backend CGI interface.


Deleting a Route


Deleting a route means removing the route not only from the current view within the browser,
but also from the database itself (if the route was one loaded from the database):


function delRoute() {
if (routeidfield.value != 0) {
routeidtext = ‘&routeid=’ + escape(routeidfield.value);
var request = GXmlHttp.create();
request.open(‘GET’,’/examples/ch13-backend.cgi?m=delroute’ ;



  • routeidtext,true);
    request.onreadystatechange = function() {
    if (request.readyState == 4) {
    var xmlsource = request.responseXML;


var msg = xmlsource.documentElement.getElementsByTagName(“message”);
if (msg.length > 0) {
message.innerHTML = msg[0].getAttribute(‘text’);
}
else
{
message.innerHTML = ‘Error sending request’;
}
}
}
}
request.send(null);
map.clearOverlays();
routeidfield.value = 0;
routetitle.value = ‘’;
routedescription.value = ‘’;
infopanel.innerHTML = ‘’;
}


It is easy to identify a route that has previously been saved (as opposed to one currently being
recorded): A saved route has a non-zero route ID.


To actually delete the route, the application has to compose a request to the CGI backend that
connects to the database. The request consists of the command delrouteand the route ID
number. The return value from the process should be a message, encoded in XML, that indi-
cates that the deletion was completed successfully. If the message could not be extracted prop-
erly (which probably means the return value was not XML), it reports there was an error
sending the request to the backend.

Free download pdf