1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
| unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ExtCtrls, ComCtrls,MSHTML;
type
TForm7 = class(TForm)
PageControl1: TPageControl;
Situation: TTabSheet;
Carte: TTabSheet;
Tâches: TTabSheet;
Equipe: TTabSheet;
Chat: TTabSheet;
Notes: TTabSheet;
Indicateur: TShape;
ColorBox1: TColorBox;
Modifier: TButton;
Panel1: TPanel;
Panel2: TPanel;
StaticText1: TStaticText;
StaticText2: TStaticText;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Edit2: TEdit;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
StaticText6: TStaticText;
Panel3: TPanel;
StaticText7: TStaticText;
StaticText8: TStaticText;
StaticText9: TStaticText;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
ComboBox1: TComboBox;
RichEdit1: TRichEdit;
Panel4: TPanel;
RichEdit2: TRichEdit;
Button5: TButton;
Button6: TButton;
WebBrowser1: TWebBrowser;
ListView1: TListView;
LabelLongitude: TLabel;
Longitude: TEdit;
LabelLatitude: TLabel;
Latitude: TEdit;
ButtonGotoLocation: TButton;
ButtonClearMarkers: TButton;
StaticText10: TStaticText;
StaticText11: TStaticText;
procedure clickModifier(Sender: TObject);
procedure selectColor(Sender: TObject);
procedure clickModifPopulation(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonClearMarkersClick(Sender: TObject);
procedure WebBrowser1CommandStateChange(ASender: TObject; Command: Integer; Enable: WordBool);
procedure ButtonGotoLocationClick(Sender: TObject);
private
HTMLWindow2: IHTMLWindow2;
procedure AddLatLngToList(const Lat,Lng:string);
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form7: TForm7;
implementation
uses Unit1, uMain, ActiveX;
{$R *.dfm}
procedure Search(const Adresse : string; const CP : string;
const Ville : string);
var URL : string;
begin
URL := 'http://maps.google.fr/maps?f=q&hl=fr&q=';
URL := URL + Adresse + ' ,+ ' + CP + '+' + Ville;
end;
procedure TForm7.Button5Click(Sender: TObject);
begin
ShowMessage('Deconnexion réussie');
form1.Show;
form7.Visible:=false;
end;
procedure TForm7.Button6Click(Sender: TObject);
begin
FrmMain.Show;
end;
procedure TForm7.clickModifier(Sender: TObject);
begin
ColorBox1.Visible:=true;
Edit2.Enabled:=true;
end;
procedure TForm7.clickModifPopulation(Sender: TObject);
begin
Edit1.Enabled:=true;
Edit3.Enabled:=true;
Edit4.Enabled:=true;
Edit5.Enabled:=true;
Edit6.Enabled:=true;
ComboBox1.Enabled:=true;
end;
procedure TForm7.selectColor(Sender: TObject);
begin
Indicateur.Brush.Color :=ColorBox1.Selected;
end;
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=false&language=en"></script> '+
//'<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> '+
'<script type="text/javascript"> '+
''+
''+
' var geocoder; '+
' var map; '+
' var markersArray = [];'+
''+
''+
' function initialize() { '+
' geocoder = new google.maps.Geocoder();'+
' var latlng = new google.maps.LatLng(40.714776,-74.019213); '+
' var myOptions = { '+
' zoom: 13, '+
' center: latlng, '+
' mapTypeId: google.maps.MapTypeId.ROADMAP '+
' }; '+
' map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); '+
' map.set("streetViewControl", false);'+
' google.maps.event.addListener(map, "click", '+
' function(event) '+
' {'+
' document.getElementById("LatValue").value = event.latLng.lat(); '+
' document.getElementById("LngValue").value = event.latLng.lng(); '+
' PutMarker(document.getElementById("LatValue").value, document.getElementById("LngValue").value,"") '+
' } '+
' ); '+
''+
' } '+
''+
''+
' function GotoLatLng(Lat, Lang) { '+
' var latlng = new google.maps.LatLng(Lat,Lang);'+
' map.setCenter(latlng);'+
' }'+
''+
''+
'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); '+
' index= (markersArray.length % 10);'+
' if (index==0) { index=10 } '+
' icon = "http://www.google.com/mapfiles/kml/paddle/"+index+"-lv.png"; '+
' marker.setIcon(icon); '+
' }'+
''+
''+
''+'</script> '+
'</head> '+
''+
'<body onload="initialize()"> '+
' <div id="map_canvas" style="width:100%; height:100%"></div> '+
' <div id="latlong"> '+
' <input type="hidden" id="LatValue" >'+
' <input type="hidden" id="LngValue" >'+
' </div> '+
''+
'</body> '+
'</html> ';
procedure TForm7.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 TForm7.WebBrowser1CommandStateChange(ASender: TObject; Command: Integer; Enable: WordBool);
var
ADocument : IHTMLDocument2;
ABody : IHTMLElement2;
Lat : string;
Lng : string;
function GetIdValue(const Id : string):string;
var
Tag : IHTMLElement;
TagsList : IHTMLElementCollection;
Index : Integer;
begin
Result:='';
TagsList := ABody.getElementsByTagName('input');
for Index := 0 to TagsList.length-1 do
begin
Tag:=TagsList.item(Index, EmptyParam) As IHTMLElement;
if CompareText(Tag.id,Id)=0 then
Result := Tag.getAttribute('value', 0);
end;
end;
begin
if TOleEnum(Command) <> CSC_UPDATECOMMANDS then
Exit;
ADocument := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(ADocument) then
Exit;
if not Supports(ADocument.body, IHTMLElement2, ABody) then
exit;
Lat :=GetIdValue('LatValue');
Lng :=GetIdValue('LngValue');
if (Lat<>'') and (Lng<>'') and ((Lat<>Latitude.Text) or (Lng<>Longitude.Text)) then
begin
Latitude.Text :=Lat;
Longitude.Text:=Lng;
AddLatLngToList(Lat, Lng);
end;
end;
procedure TForm7.AddLatLngToList(const Lat, Lng: string);
var
Item : TListItem;
begin
if (Lat<>'') and (Lng<>'') then
begin
Item:=ListView1.Items.Add;
Item.Caption:=Lng;
Item.SubItems.Add(Lat);
Item.MakeVisible(False);
end;
end;
procedure TForm7.ButtonClearMarkersClick(Sender: TObject);
begin
HTMLWindow2.execScript('ClearMarkers()', 'JavaScript');
ListView1.Items.Clear;
end;
procedure TForm7.ButtonGotoLocationClick(Sender: TObject);
begin
if Assigned(ListView1.Selected) then
HTMLWindow2.execScript(Format('GotoLatLng(%s,%s)',[ListView1.Selected.SubItems[0],ListView1.Selected.Caption]), 'JavaScript');
end;
end. |
Partager