Re: Running JavaScript on Delphi web browser
- From: "Tom de Neef" <tdeneef@xxxxxxxx>
- Date: Sun, 23 Sep 2007 19:00:25 +0200
"Mark Dradey" <markd@xxxxxxxxxxxxxxxxxxx> schreef in bericht
news:k5KdneemZctyAnvbnZ2dnUVZ8qWhnZ2d@xxxxxxxxx
Hi,
I am trying to see if I can integrate Google maps into my Delphi
application. I have found some JavaScript which would take parameters, see
http://www.stevetrefethen.com/files/googlemap.htm What I can't work out is
how to run that JavaScript from Delphi. Can anyone help me.
The way I've tackled this (using TwebBrowser) is as follows (apart from
declarations, try's, etc):
1) construct the javascript as part of a complete HTML file. Eg:
txt:='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN '+
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+nlcr+
'<html xmlns="http://www.w3.org/1999/xhtml">'+nlcr+
'<head>'+nlcr+
'<meta http-equiv="content-type" content="text/html;
charset=utf-8">'+nlcr+
'<script src="http://maps.google.com/maps?file=api&v=2&key='+
preferences.GoogleMAPSkey+'" '+
'type="text/javascript"></script>'+nlcr+
'<script type="text/javascript">'+nlcr+
'//<![CDATA['+nlcr+
' function load() {'+nlcr+
' if (GBrowserIsCompatible()) {'+nlcr+
' var map = new GMap2(document.getElementById("map"));'+nlcr+
' map.addControl(new GSmallMapControl());'+nlcr+
' var zoomLevel = map.getBoundsZoomLevel(new GLatLngBounds('+
GLatLng(minLAT,minLONG)+','+GLatLng(maxLAT,maxLONG)+'));'+nlcr+
' map.setCenter('+GLatLng((minLAT+maxLAT) DIV
2,(minLONG+maxLONG) DIV 2)+',zoomLevel);'+nlcr+
' map.enableDoubleClickZoom();'+nlcr+
' map.enableContinuousZoom();'+nlcr+
'
GEvent.addListener(map,"mousemove",function(){map.closeInfoWindow()});'+nlcr+
markers+
' GEvent.addListener(map, "click", function(overlay,
point){'+nlcr+
' map.clearOverlays();'+nlcr+
' if (point) {'+nlcr+
' var DragMarker = new GMarker(point, {icon:G_DEFAULT_ICON,
draggable: true});'+nlcr+
' map.addOverlay(DragMarker);'+nlcr+
' DragMarker.enableDragging();'+nlcr+
' map.panTo(point);'+nlcr+
' var lat100 =Math.round(point.lat()*100);'+nlcr+
' var long100=Math.round(point.lng()*100);'+nlcr+
' msg = "LAT: <B>"+lat100+"</B> LONG:
<B>"+long100+"</B>";'+nlcr+
' document.getElementById("pointRef").innerHTML = msg;'+nlcr+
' GEvent.addListener(DragMarker,"drag",function(){'+nlcr+
' var lat100
=Math.round(DragMarker.getPoint().lat()*100);'+nlcr+
' var
long100=Math.round(DragMarker.getPoint().lng()*100);'+nlcr+
' msg = "LAT: <B>"+lat100+"</B> LONG:
<B>"+long100+"</B>";'+nlcr+
' document.getElementById("pointRef").innerHTML = msg;'+nlcr+
' });'+nlcr+
' }'+nlcr+
' });'+nlcr+
' }'+nlcr+
' }'+nlcr+
'//]]>'+nlcr+
'</script>'+nlcr+
'</head>'+nlcr+
'<body style="font-family:Arial" onload="load()"
onunload="GUnload()">'+nlcr+
' <table width=100%>'+nlcr+
' <tr><td id="map" style="height:254px">'+nlcr+
' <tr><td id="pointRef" align=right style="font-size:10pt">'+s+
' </table>'+nlcr+
'</body>'+nlcr+
'</html>';
2) write the string to a disk file:
assignFile(textfile,filename);
rewrite(textfile);
writeln(textFile,txt);
flush(textfile);
CloseFile(textFile);
3) call the file from the TwebBrowser:
webBrowser.Navigate(Filename);
Tom
.
- References:
- Running JavaScript on Delphi web browser
- From: Mark Dradey
- Running JavaScript on Delphi web browser
- Prev by Date: Do you want to sell runescape gold?welcone to www.sell-runescape-gold.com
- Next by Date: Just-in-time Debugger
- Previous by thread: Running JavaScript on Delphi web browser
- Next by thread: buy cheap runescape gold on www.buy-runescape-money.com
- Index(es):
Relevant Pages
|