unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ExtCtrls, XPMan, ComCtrls,MSHTML;
type
TForm2 = class(TForm)
WebBrowser1: TWebBrowser;
LabelAddress: TLabel;
PanelHeader: TPanel;
ButtonGotoLocation: TButton;
MemoAddress: TMemo;
ButtonGotoAddress: TButton;
LabelLatitude: TLabel;
LabelLongitude: TLabel;
Longitude: TEdit;
Latitude: TEdit;
CheckBoxTraffic: TCheckBox;
CheckBoxBicycling: TCheckBox;
CheckBoxStreeView: TCheckBox;
ButtonClearMarkers: TButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure ButtonGotoAddressClick(Sender: TObject);
procedure ButtonGotoLocationClick(Sender: TObject);
procedure CheckBoxTrafficClick(Sender: TObject);
procedure CheckBoxBicyclingClick(Sender: TObject);
procedure CheckBoxStreeViewClick(Sender: TObject);
procedure ButtonClearMarkersClick(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
private
{ Private declarations }
HTMLWindow2: IHTMLWindow2;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses
ActiveX, Unit1;
{$R *.dfm}
const
HTMLStr: AnsiString =
'<
html> '+
'<head> '+
'<meta name="viewport" content="initial-scale=1.0, user-scalable=yes" /> '+
'<script type="text/javascript" src="http://maps.google.com/maps/
api/js?sensor=true"></script> '+
'<script type="text/javascript"> '+
''+
''+
' var geocoder; '+
' var map; '+
' var Beachclub; '+
' var marker; '+ // Markierung
' var trafficLayer;'+ // Layer Verkehr
' var bikeLayer;'+ // Layer
' var markersArray = [];'+
''+
''+
' function initialize() { '+
''+
' geocoder = new google.maps.Geocoder();'+
''+
' var latlng = new google.maps.LatLng(39.550189, 2.691211); '+
' var latlng2 = new google.maps.LatLng(39.551200, 2.691211); '+
''+
' var myOptions = { '+
' zoom: 15, '+
' center: latlng, '+
' mapTypeId: google.maps.MapTypeId.SATELLITE, '+ // ROADMAP (GROß geschrieben)
' mapTypeControl: true, '+
' mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU} '+
' }; '+
''+
' map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); '+
''+
' marker = new google.maps.Marker({ position: latlng , map: map, title: "Hello World!" }); '+
' Beachclub = new google.maps.Marker({ position: latlng2, title: "Hello AAAA" }); '+
''+
' trafficLayer = new google.maps.TrafficLayer();'+
' bikeLayer = new google.maps.BicyclingLayer();'+
' map.set("streetViewControl", false);'+
' } '+
''+
''+
' function codeAddress(address) { '+
' if (geocoder) {'+
' geocoder.geocode( { address: address}, function(results, status) { '+
' if (status == google.maps.GeocoderStatus.OK) {'+
' map.setCenter(results[0].geometry.location);'+
' PutMarker(results[0].geometry.location.lat(), results[0].geometry.location.lng(), results[0].geometry.location.lat()+","+results[0].geometry.location.lng());'+
' } else {'+
' alert("Geocode was not successful for the following reason: " + status);'+
' }'+
' });'+
' }'+
' }'+
''+
''+
' function GotoLatLng(Lat, Lang) { '+
' var latlng = new google.maps.LatLng(Lat,Lang);'+
' map.setCenter(latlng);'+
' PutMarker(Lat, Lang, Lat+","+Lang);'+
' }'+
''+
''+
'function ClearMarkers() { '+
' if (markersArray) { '+
' for (i in markersArray) { '+
' markersArray[i].setMap(null); '+
' } '+
' } '+
'} '+
''+
' function PutMarker(Lat, Lang, Msg) { '+
' var latlng = new google.maps.LatLng(Lat,Lang);'+
' var marker = new google.maps.Marker({'+
' position: latlng, '+
' map: map,'+
' title: Msg+" ("+Lat+","+Lang+")"'+
' });'+
' markersArray.push(marker); '+
' }'+
''+
''+
' function TrafficOn() { trafficLayer.setMap(map); }'+
''+
' function TrafficOff() { trafficLayer.setMap(null); }'+
''+''+
' function CheckBox1On() { map.set ("overviewMapControl", true); }'+ //
''+
' function CheckBox1Off() { map.set ("overviewMapControl", false); }'+ //
''+''+
' function CheckBox2On() { Beachclub.setMap(map); }'+ //
''+
' function CheckBox2Off() { Beachclub.setMap(null); }'+ //
''+''+
' function BicyclingOn() { bikeLayer.setMap(map); }'+
''+
' function BicyclingOff(){ bikeLayer.setMap(null);}'+
''+
' function StreetViewOn() { map.set("streetViewControl", true); }'+
''+
' function StreetViewOff() { map.set("streetViewControl", false); }'+
''+
''+'</script> '+
'</head> '+
'<body onload="initialize()"> '+
' <div id="map_canvas" style="width:100%; height:100%"></div> '+
'</body> '+
'</
html> ';
procedure TForm2.FormCreate(Sender: TObject);
var
aStream : TMemoryStream;
begin
WebBrowser1.Navigate('about
:blank');
if Assigned(WebBrowser1.Document) then
begin
aStream := TMemoryStream.Create;
try
aStream.WriteBuffer(Pointer(HTMLStr)^, Length(HTMLStr));
//aStream.Write(HTMLStr[1], Length(HTMLStr));
aStream.Seek(0, soFromBeginning);
(WebBrowser1.Document as IPersistStreamInit).Load(TStreamAdapter.Create(aStream));
finally
aStream.Free;
end;
HTMLWindow2 := (WebBrowser1.Document as IHTMLDocument2).parentWindow;
end;
end;
procedure TForm2.ButtonGotoLocationClick(Sender: TObject);
begin
HTMLWindow2.execScript(Format('GotoLatLng(%s,%s)',[Latitude.Text,Longitude.Text]), 'JavaScript');
end;
procedure TForm2.ButtonClearMarkersClick(Sender: TObject);
begin
HTMLWindow2.execScript('ClearMarkers()', 'JavaScript')
end;
procedure TForm2.ButtonGotoAddressClick(Sender: TObject);
var
address : string;
begin
address := MemoAddress.Lines.Text;
address := StringReplace(StringReplace(Trim(address), #13, ' ', [rfReplaceAll]), #10, ' ', [rfReplaceAll]);
HTMLWindow2.execScript(Format('codeAddress(%s)',[QuotedStr(address)]), 'JavaScript');
end;
procedure TForm2.CheckBoxStreeViewClick(Sender: TObject);
begin
if CheckBoxStreeView.Checked then
HTMLWindow2.execScript('StreetViewOn()', 'JavaScript')
else
HTMLWindow2.execScript('StreetViewOff()', 'JavaScript');
end;
procedure TForm2.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
HTMLWindow2.execScript('CheckBox1On()', 'JavaScript')
else
HTMLWindow2.execScript('CheckBox1Off()', 'JavaScript');
end;
procedure TForm2.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked then
HTMLWindow2.execScript('CheckBox2On()', 'JavaScript')
else
HTMLWindow2.execScript('CheckBox2Off()', 'JavaScript');
end;
procedure TForm2.CheckBoxBicyclingClick(Sender: TObject);
begin
if CheckBoxBicycling.Checked then
HTMLWindow2.execScript('BicyclingOn()', 'JavaScript')
else
HTMLWindow2.execScript('BicyclingOff()', 'JavaScript');
end;
procedure TForm2.CheckBoxTrafficClick(Sender: TObject);
begin
if CheckBoxTraffic.Checked then
HTMLWindow2.execScript('TrafficOn()', 'JavaScript')
else
HTMLWindow2.execScript('TrafficOff()', 'JavaScript');
end;
end.