StableVersion4.3/HL_FristAidPlatform_RealTim.../WebMap.cs

229 lines
5.9 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
namespace HL_FristAidPlatform_RealTimeVideo
{
public class WebMap
{
private static readonly WebMap instance;
private double _longitude;
private double _latitude;
private WebBrowser browser;
private string BD_MapUrl = "http://api.map.baidu.com/api?v=2.0&ak=";
private string BD_Key = "yzC0EIsAMwK5AXdLzbNYM9gNCudAZmtq";
private string logUrl = "green.png";
private string html = "";
private string headscript = "";
private string myscript = "";
public static WebMap Instance => instance;
public double Longitude
{
get
{
return _longitude;
}
set
{
_longitude = value;
}
}
public double Latitude
{
get
{
return _latitude;
}
set
{
_latitude = value;
}
}
public WebBrowser WebBrowser1
{
get
{
return browser;
}
set
{
browser = value;
}
}
static WebMap()
{
instance = new WebMap();
}
private WebMap()
{
}
public void LoadDefaultUrl(M_CarGPS m_CarGPS)
{
browser.ScriptErrorsSuppressed = true;
string uriString = Application.StartupPath + "\\Map.html";
browser.Url = new Uri(uriString);
browser.ObjectForScripting = true;
addFunction();
browser.DocumentCompleted += delegate
{
browser.Document.InvokeScript("BD_MapDirectionShow", new object[4]
{
m_CarGPS.ambulanceNumber,
m_CarGPS.deviceId,
m_CarGPS.lpX,
m_CarGPS.lpY
});
};
}
public void BD_MapDirectionShow()
{
if (browser != null)
{
browser.Document.InvokeScript("BD_MapDirectionShow", new object[2]
{
_longitude,
_latitude
});
}
}
public void BD_MapDirectionShow(string ambulanceNumber, string deviceId, double lng, double lat)
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("BD_MapDirectionShow", new object[4]
{
ambulanceNumber,
deviceId,
lng,
lat
});
}
}
public void BD_MapDirectionShow(Point p)
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("BD_MapDirectionShow", new object[2]
{
p.X,
p.Y
});
}
}
public void BD_ClearOverlays()
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("ClearOverlays", new object[0]);
}
}
public void BD_ShowCarRuns()
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("BD_ShowCarRuns", new object[0]);
}
}
public void BD_ShowCarRun(MyLngLatPoint startPoint, MyLngLatPoint endPoint)
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("BD_ShowCarRun", new object[4]
{
startPoint.X,
startPoint.Y,
endPoint.X,
endPoint.Y
});
}
}
public object evel(MyLngLatPoint point)
{
return browser.Document.InvokeScript("eval", new object[1]
{
point
});
}
public void addFunctions()
{
HtmlElement htmlElement = browser.Document.CreateElement("script");
htmlElement.SetAttribute("type", "text/javascript");
htmlElement.SetAttribute("text", "function _func(){alert('OK')}");
HtmlElement htmlElement2 = browser.Document.Body.AppendChild(htmlElement);
browser.Document.InvokeScript("_func");
}
public void addFunction()
{
//try
//{
// string text = "alert('Hello');";
// browser.Document.InvokeScript("eval", new object[1]
// {
// text
// });
//}
//catch
//{
//}
}
public void PointPath(string start, string end)
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("PointPath", new object[2]
{
start,
end
});
}
}
public void EnableMouseDrag()
{
if (browser.Url != (Uri)null)
{
browser.Document.InvokeScript("enableMouseDrag", new object[0]{});
}
}
public void GetNavigation(string startPointX, string startPointY,string endPoint)
{
browser.ScriptErrorsSuppressed = true;
string uriString = Application.StartupPath + "\\Map.html";
browser.Url = new Uri(uriString);
browser.ObjectForScripting = true;
addFunction();
browser.DocumentCompleted += delegate
{
browser.Document.InvokeScript("getNavigation", new object[3] { startPointX, startPointY, endPoint });
};
}
}
}