void clickHelper_OnSingleClick(Point original, Point scaled) { ExplorerPoint explorerPoint = new ExplorerPoint(scaled.X, scaled.Y); ExplorerRegion region = parentMap.getRegionContainingPoint(explorerPoint); if(region != null) { Console.WriteLine(region.getName()); } Ellipse ellipse = new Ellipse(); ellipse.Width = 6; ellipse.Height = 6; Canvas.SetLeft(ellipse, original.X - 3); Canvas.SetTop(ellipse, original.Y - 3); parentCanvas.Children.Add(ellipse); Console.WriteLine("<point x=\"" + scaled.X + "\" y=\"" + scaled.Y + "\" />"); }
//C# Port example C code at http://alienryderflex.com/polygon/ public bool regionContainsPoint(ExplorerPoint point) { Boolean oddNodes = false; List<ExplorerPoint> points = getPoints(); int polySides = points.Count; int j = polySides - 1; double workingPointX = point.getX(); double workingPointY = point.getY(); for(int i = 0; i < polySides; i++) { if ((points[i].getY() < workingPointY && points[j].getY() >= workingPointY) || (points[j].getY() < workingPointY && points[i].getY() >= workingPointY)) { if(points[i].getX() + (workingPointY-points[i].getY())/(points[j].getY()-points[i].getY())*(points[j].getX() - points[i].getX()) < workingPointX) { oddNodes = !oddNodes; } } j = i; } return oddNodes; }
void clickHelper_OnSingleClick(Point relative_point, Point screen_point) { ExplorerPoint explorerPoint = new ExplorerPoint(relative_point.X, relative_point.Y); ExplorerRegion region = parentMap.getRegionContainingPoint(explorerPoint); if(region != null) { if(!highlightedRegions.ContainsKey(region)) { Color randomColor = RandomColorManager.getRandomColor(); if(OnRegionClick != null) { OnRegionClick(region, randomColor, screen_point); } } } else { Ellipse ellipse = new Ellipse(); ellipse.Width = 10; ellipse.Height = 10; ellipse.Stroke = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)); Canvas.SetLeft(ellipse, relative_point.X - 5); Canvas.SetTop(ellipse, relative_point.Y - 5); background.Children.Add(ellipse); Console.WriteLine("<point x=\"" + relative_point.X + "\" y=\"" + relative_point.Y + "\" />"); } }