public static void partial(int x, int y) { level++; WebClient wc = new WebClient(); s.Clear(); m_Images.Clear(); if (mouseEvent == false) { mapX = (x + mapX * 256) / 256 * 2 - 1; mapY = (y + mapY * 256) / 256 * 2; } else { mouseEvent = false; } for (int i = mapY; i < range + mapY; i++) { for (int j = mapX; j < range + mapX; j++) { s.Add(BingMaps.TileXYToQuadKey(j, i, level)); } } for (int i = 0; i < range * range; i++) { m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/" + layer + s[i] + ".jpeg?g=3649")))); } total = range * range; length = (1 << level); }
public static void loginMap(int Level, int Range, int Length, int MapX, int MapY, int Total, bool mrt, bool district, bool icon, char layer) { total = Total; range = Range; level = Level; length = Length; mapX = MapX; mapY = MapY; Form1.showMRT = mrt; testFlag = district; iconFlag = icon; MapView.layer = layer; WebClient wc = new WebClient(); s.Clear(); m_Images.Clear(); int cnt = 0; for (int i = mapY; i < range + mapY; i++) { for (int j = mapX; j < range + mapX; j++) { s.Add(BingMaps.TileXYToQuadKey(j, i, level)); MapView.m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/" + MapView.layer + MapView.s[cnt] + ".jpeg?g=3649")))); cnt++; } } }
public static void landmarkFocus(int returnx, int returny) { WebClient wc = new WebClient(); s.Clear(); m_Images.Clear(); mapY = returny / 256 - 1; mapX = returnx / 256 - 2; level = 17; range = 4; length = 4; for (int i = mapY; i < range + mapY; i++) { for (int j = mapX; j < range + mapX; j++) { s.Add(BingMaps.TileXYToQuadKey(j, i, level)); } } for (int i = 0; i < range * range; i++) { m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/" + layer + s[i] + ".jpeg?g=3649")))); } total = range * range; locateFlag = true; locateX = returnx - MapView.mapX * 256 - 7; locateY = returny - MapView.mapY * 256 - 63; }
public void returnInfo(int x, int y, out string content, out string name) { content = ""; name = ""; string sql = "SELECT * from landmark"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); SqlDataReader dd = cmd.ExecuteReader(); while (dd.Read()) { double lat = Convert.ToDouble(dd["latitude"]); double lon = Convert.ToDouble(dd["longitude"]); int pixelX, pixelY; BingMaps.LatLongToPixelXY(lat, lon, MapView.level, out pixelX, out pixelY); pixelX -= MapView.mapX * 256; pixelY -= MapView.mapY * 256; if (x == pixelX && y == pixelY) { name = Convert.ToString(dd["name"]); content = Convert.ToString(dd["location"]) + "\r\n" + Convert.ToString(dd["telephone"]); } } conn.Close(); cmd.Dispose(); }
public static void reduce() { if (level > 1) { level--; if (level == 1) { total = 4; range = 2; } WebClient wc = new WebClient(); s.Clear(); m_Images.Clear(); mapX = (mapX - 1) / 2; mapY = (mapY - 1) / 2; for (int i = mapY; i < range + mapY; i++) { for (int j = mapX; j < range + mapX; j++) { s.Add(BingMaps.TileXYToQuadKey(j, i, level)); } } for (int i = 0; i < range * range; i++) { m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/" + layer + s[i] + ".jpeg?g=3649")))); } total = range * range; length = (1 << level); } }
public bool findLocation(string locationName, out int returnx, out int returny, bool isFirst) { string sql = "SELECT * from landmark"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); SqlDataReader dd = cmd.ExecuteReader(); string s = ""; returnx = 0; returny = 0; while (dd.Read()) { s = Convert.ToString(dd["name"]).TrimEnd(); if (s.IndexOf(locationName) != -1) { if (isFirst == true) { MapView.level = 19; } BingMaps.LatLongToPixelXY(Convert.ToDouble(dd["latitude"]), Convert.ToDouble(dd["longitude"]), MapView.level, out returnx, out returny); conn.Close(); cmd.Dispose(); return(true); } } conn.Close(); cmd.Dispose(); return(false); }
public void isExist(double lat, double lon, double lat2, double lon2, out List <int> lati, out List <int> longi, out List <string> cate) { string sql = "SELECT latitude,longitude,category from landmark"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); SqlDataReader dd = cmd.ExecuteReader(); List <int> temp = new List <int>(), temp2 = new List <int>(); List <string> temp3 = new List <string>(); while (dd.Read()) { double d = Convert.ToDouble(dd["latitude"]), d2 = Convert.ToDouble(dd["longitude"]); if (clip(lat2, lat, d) && clip(lon, lon2, d2)) { int x, y; BingMaps.LatLongToPixelXY(d, d2, MapView.level, out x, out y); x -= MapView.mapX * 256; y -= MapView.mapY * 256; temp.Add(x); temp2.Add(y); temp3.Add(Convert.ToString(dd["category"])); } } lati = temp; longi = temp2; cate = temp3; conn.Close(); cmd.Dispose(); }
public void drawIcon(int topx, int btnx, int topy, int btny, out List <int> lati, out List <int> longi, out List <string> cate) { double lat, lon, lat2, lon2; conection con = new conection(); BingMaps.PixelXYToLatLong(topx, topy, MapView.level, out lat, out lon); BingMaps.PixelXYToLatLong(btnx, btny, MapView.level, out lat2, out lon2); con.isExist(lat, lon, lat2, lon2, out lati, out longi, out cate); }
private void richTextBox_MouseUp(object sender, MouseEventArgs e) { isDragging = false; Xaxis = (Xaxis - e.X) / 256; Yaxis = (Yaxis - e.Y) / 256; if (MapView.level >= 2 && selectionFlag == false) { WebClient wc = new WebClient(); MapView.m_Images.Clear(); MapView.s.Clear(); int cnt = 0; for (int i = MapView.mapY; i < MapView.range + MapView.mapY; i++) { for (int j = MapView.mapX; j < MapView.range + MapView.mapX; j++) { MapView.s.Add(BingMaps.TileXYToQuadKey(j + Xaxis, i + Yaxis, MapView.level)); MapView.m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/" + MapView.layer + MapView.s[cnt] + ".jpeg?g=3649")))); cnt++; } } MapView.total = MapView.range * MapView.range; MapView.mapX += Xaxis; MapView.mapY += Yaxis; } if (selectionFlag == true) { middlex = e.X - mouseRect.Width / 2; middley = e.Y - mouseRect.Height / 2; //MessageBox.Show(middlex + " " + middley); MapView.partial(middlex, middley); Cursor.Clip = Rectangle.Empty; DrawRectangle(); mouseRect = Rectangle.Empty; selectionFlag = false; mapView1.Cursor = Cursors.Default; } if (MapView.testFlag == true) { TownLayer.drawPolygon(); } if (MapView.iconFlag == true) { test.drawIcon(MapView.mapX * 256 + 1024, MapView.mapX * 256, MapView.mapY * 256 + 1024, MapView.mapY * 256, out MapView.ltox, out MapView.ltoy, out MapView.cate); } if (MapView.locateFlag == true) { locateXY(); } mapView1.Invalidate(); }
public static void drawPolygon() { int cnt = -1, arrayCnt = 0; string tmp = ""; Array.Resize(ref poi, 0); List <string> array = new List <string>(); List <string> array2 = new List <string>(); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_town.geo", out array); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_town.csv", out array2); arrayNum.Clear(); for (int i = 0; i < 42; i++) { string[] words = array2[i].Split(','); TownName.Add(words[4]); } for (int i = 0; i < 66; i++) { string[] words = array[i].Split(','); double[] intWords = new double[words.Length]; for (int k = 0; k < words.Length; k++) { intWords[k] = Convert.ToDouble(words[k]); } for (int j = 3; j + 1 < Convert.ToInt32(words[2]) * 2 + 3; j += 2) { BingMaps.LatLongToPixelXY(intWords[j + 1], intWords[j], MapView.level, out TownPixelX, out TownPixelY); cnt++; Array.Resize(ref poi, poi.Length + 1); poi[cnt] = new Point(TownPixelX, TownPixelY); } if (words[1] != tmp) { tmp = words[1]; if (i != 0) { arrayNum.Add(arrayCnt); } arrayCnt = 0; } arrayCnt += Convert.ToInt32(intWords[2]); if (i == 65) { arrayNum.Add(arrayCnt); } } forFlag = true; }
public static void drawLine() { List <string> array = new List <string>(); List <string> array2 = new List <string>(); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_mrt.geo", out array); readFile("C:\\Users\\ColifeTNNB01\\Desktop\\maptest2\\題目\\Khsc_mrt.csv", out array2); for (int i = 0; i < 107; i++) { string[] words = array[i].Split(','); string[] color = array2[i].Split(','); double[] intWords = new double[words.Length]; for (int k = 0; k < words.Length; k++) { intWords[k] = double.Parse(words[k]); } for (int j = 2; j + 3 < Convert.ToInt32(words[1]) * 2 + 2; j += 2) { BingMaps.LatLongToPixelXY(intWords[j + 1], intWords[j], MapView.level, out Form1.pixelX, out Form1.pixelY); BingMaps.LatLongToPixelXY(intWords[j + 3], intWords[j + 2], MapView.level, out Form1.pixelx, out Form1.pixely); drawX.Add(Form1.pixelX); drawY.Add(Form1.pixelY); drawx.Add(Form1.pixelx); drawy.Add(Form1.pixely); if (color[3] == "紅線") { red.Add(1); } else { red.Add(0); } cnt++; } } }
public static void allView() { total = 16; range = 4; level = 2; length = 4; mapX = 0; mapY = 0; WebClient wc = new WebClient(); s.Clear(); m_Images.Clear(); for (int i = mapY; i < range + mapY; i++) { for (int j = mapX; j < range + mapX; j++) { s.Add(BingMaps.TileXYToQuadKey(j, i, level)); } } for (int i = 0; i < range * range; i++) { m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/" + layer + s[i] + ".jpeg?g=3649")))); } }
private void search(object sender, EventArgs e) { string address = textBox1.Text; int x, y; string requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address)); XmlDocument doc = new XmlDocument(); doc.Load(requestUri); if (doc.SelectSingleNode("//status").InnerText == "OK") { XmlNodeList nodes = doc.SelectNodes("//location"); double lng = Convert.ToDouble(nodes[0].SelectSingleNode("lng").InnerText); double lat = Convert.ToDouble(nodes[0].SelectSingleNode("lat").InnerText); //string s = string.Format("logitude: {0} latitude: {1}", lng,lat); BingMaps.LatLongToPixelXY(lat, lng, 17, out x, out y); MapView.landmarkFocus(x, y); MessageBox.Show(Convert.ToString(doc.SelectSingleNode("//formatted_address").InnerText), "地理資訊"); this.Refresh(); } else { MessageBox.Show("找不到目標", "ERROR"); } }
private void richTextBox_MouseMove(object sender, MouseEventArgs e) { if (isDragging) { if (selectionFlag == true) { ResizeToRectangle(e.Location); } if (MapView.level < 2 && selectionFlag == false) { mapView1.Left += (e.X - px); mapView1.Top += (e.Y - py); disx += (e.X - px); disy += (e.Y - py); } if (MapView.level > 100) { if ((e.X - Xaxis) <= -5) { // Xaxis = 1; WebClient wc = new WebClient(); MapView.m_Images.Clear(); MapView.s.Clear(); int cnt = 0; for (int i = MapView.mapY; i < MapView.range + MapView.mapY; i++) { for (int j = MapView.mapX; j < MapView.range + MapView.mapX; j++) { MapView.s.Add(BingMaps.TileXYToQuadKey(j - 2, i, MapView.level)); MapView.m_Images.Add(Image.FromStream(new MemoryStream(wc.DownloadData("https://ecn.t1.tiles.virtualearth.net/tiles/a" + MapView.s[cnt] + ".jpeg?g=3649")))); cnt++; } } //MessageBox.Show((e.X - Xaxis)+"\n"+e.X+"\n"+Xaxis); } } px = e.X; py = e.Y; release = 1; this.Refresh(); } toolTip1.ToolTipIcon = ToolTipIcon.Info; toolTip1.ForeColor = Color.Blue; toolTip1.BackColor = Color.Gray; for (int i = 0; i < MapView.ltox.Count; i++) { if (e.X >= MapView.ltox[i] - 20 && e.X <= MapView.ltox[i] + 20 && e.Y <= MapView.ltoy[i] + 20 && e.Y >= MapView.ltoy[i] - 20 && MapView.iconFlag == true) { conection con = new conection(); string s = "", tile = ""; con.returnInfo(MapView.ltox[i], MapView.ltoy[i], out s, out tile); toolTip1.ToolTipTitle = tile; //Thread.Sleep(500); toolTip1.Show(s, this, new Point(MapView.ltox[i], MapView.ltoy[i])); break; } else { toolTip1.RemoveAll(); } } BingMaps.PixelXYToLatLong(e.X + MapView.mapX * 256, e.Y + MapView.mapY * 256, MapView.level, out lalitude, out longitude); this.Text = "lalitude: " + lalitude + " longitude: " + longitude + " X: " + e.X + " Y: " + e.Y + " MapX: " + MapView.mapX + " MapY: " + MapView.mapY; }