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
| using System;
using System.Collections ;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SxCSWFLib
{
[System.Runtime.InteropServices.ComVisible(true)]
public partial class MyGoogleMapForm : Form // Needs be be "public" to communicate with JavaScript
{
private float InitialMapScale = 4 ;
public SxGoogleMapForm()
{
InitializeComponent();
GM_WebBrowser.ObjectForScripting = this ;
}
// -------------------------- GoogleMap exchanges -------------------------------------------------------------
//
public void FromGM_MapClick(float Lat, float Lon)
{
MessageBox.Show("Coord : "+Lat.ToString()+" / "+(-Lon).ToString());
}
private void ToGM_SetScaleControl(bool On)
{
object [] BrowserArgs = { On } ;
GM_WebBrowser.Document.InvokeScript("ToGM_SetScaleControl",BrowserArgs) ;
}
private void ToGM_SetZoomControl(bool On)
{
object [] BrowserArgs = { On } ;
GM_WebBrowser.Document.InvokeScript("ToGM_SetZoomControl",BrowserArgs) ;
}
private void ToGM_SetMapSize(int Width,int Height)
{
object [] BrowserArgs = { Width, Height } ;
GM_WebBrowser.Document.InvokeScript("ToGM_SetMapSize",BrowserArgs) ;
}
private void ToGM_SetMapType(string MapType)
{
object [] BrowserArgs = { MapType[0]+"" } ;
GM_WebBrowser.Document.InvokeScript("ToGM_SetMapType",BrowserArgs) ;
}
private string ToGM_GetMapCenter()
{ // keep center if MapCenter is undefined, keep Scale if Mapscale=0
string Result="" ;
object [] BrowserArgs = { } ;
string s=(string)GM_WebBrowser.Document.InvokeScript("ToGM_GetMapCenter",BrowserArgs) ;
if (s!=null) Result=s.Replace(".",SxStrings.NumberDecimalSeparator());
return Result ;
}
private float ToGM_GetScale()
{ // keep center if MapCenter is undefined, keep Scale if Mapscale=0
float Result ;
object [] BrowserArgs = { } ;
string s=GoogleMapActive?(string)GM_WebBrowser.Document.InvokeScript("ToGM_GetScale",BrowserArgs):"" ;
if (!float.TryParse(s.Replace(',','.'),out Result)) Result=NmPerPixelToGoogleScale(InitialMapScale) ;
return Result ;
}
private void ToGM_SetMapCenter(float LatInDeg,float LonInDeg, float MapScale)
{ // keep center if MapCenter is undefined, keep Scale if Mapscale=0
object [] BrowserArgs = { LatInDegl, LonInDeg, MapScale>0?(object)MapScale:null } ;
GM_WebBrowser.Document.InvokeScript("ToGM_SetMapCenter",BrowserArgs) ;
}
private void ToGM_SetMapCenterFromAddress(string Address,float Zoom)
{
object [] BrowserArgs = { Address, Zoom } ;
GM_WebBrowser.Document.InvokeScript("ToGM_SetMapCenterFromAddress",BrowserArgs) ;
}
// -------------------------- Tools -------------------------------------------------------------
//
private float NmPerPixelToGoogleScale(float NmPerPixel)
{
float Result ;
if (NmPerPixel<=0) Result=-1 ;
else
{
Result=4 ;
NmPerPixel=NmPerPixel/2.5f ; // 4 auparavant
while (NmPerPixel<1) { NmPerPixel=NmPerPixel*2 ; Result++ ; }
}
return Result ;
}
} // GoogleForm
} |
Partager