public void InvokeHover(Point screenPosition, float scale, ISymbolCache symbolCache) { if (Hover == null) { return; } if (HoverLayers.Count == 0) { return; } var mapInfo = InfoHelper.GetMapInfo(Viewport, screenPosition, scale, HoverLayers, symbolCache); if (mapInfo?.Feature != _previousHoverEventArgs?.MapInfo.Feature) // only notify when the feature changes { var mapInfoEventArgs = new MapInfoEventArgs { MapInfo = mapInfo, NumTaps = 0, Handled = false }; _previousHoverEventArgs = mapInfoEventArgs; Hover?.Invoke(this, mapInfoEventArgs); } }
public void IgnoringDisabledLayers() { // arrange var map = new Map(); map.Viewport.Resolution = 1; map.Viewport.Width = 10; map.Viewport.Height = 10; map.Viewport.Center = new Point(5, 5); var disabledLayer = new MemoryLayer { Name = "TestLayer", DataSource = new MemoryProvider(CreatePolygon(1, 3)), Enabled = false }; map.Layers.Add(disabledLayer); map.InfoLayers.Add(disabledLayer); var screenPositionHit = map.Viewport.WorldToScreen(2, 2); // act var argsHit = InfoHelper.GetMapInfo(map.Viewport, screenPositionHit, map.InfoLayers, null); // assert; Assert.IsTrue(argsHit.Feature == null); Assert.IsTrue(argsHit.Layer == null); Assert.IsTrue(argsHit.WorldPosition.Equals(new Point(2, 2))); }
/// <summary> /// Check, if a widget or feature at a given screen position is clicked/tapped /// </summary> /// <param name="screenPosition">Screen position to check for widgets and features</param> /// <param name="startScreenPosition">Screen position of Viewport/MapControl</param> /// <param name="scale">Scale of scrren. Normally is 1, but could be greater.</param> /// <param name="symbolCache">Cache for symbols to determin size</param> /// <param name="widgetCallback">Callback, which is called when Widget is hiten</param> /// <param name="numTaps">Number of clickes/taps</param> /// <returns>True, if something done </returns> public bool InvokeInfo(Point screenPosition, Point startScreenPosition, float scale, ISymbolCache symbolCache, Action <IWidget, Point> widgetCallback, int numTaps) { var layerWidgets = Layers.Select(l => l.Attribution).Where(a => a != null); var allWidgets = layerWidgets.Concat(Widgets).ToList(); // Concat layer widgets and map widgets. // First check if a Widget is clicked. In the current design they are always on top of the map. var widget = WidgetTouch.GetWidget(screenPosition, startScreenPosition, scale, allWidgets); if (widget != null) { // TODO how should widgetCallback have a handled type thing? // Widgets should be iterated through rather than getting a single widget, // based on Z index and then called until handled = true; Ordered By highest Z widgetCallback(widget, new Point(screenPosition.X / scale, screenPosition.Y / scale)); return(true); } if (Info == null) { return(false); } var mapInfo = InfoHelper.GetMapInfo(Viewport, screenPosition, scale, InfoLayers, symbolCache); if (mapInfo != null) { // TODO Info items should be iterated through rather than getting a single item, // based on Z index and then called until handled = true; Ordered By highest Z var mapInfoEventArgs = new MapInfoEventArgs { MapInfo = mapInfo, NumTaps = numTaps, Handled = false }; Info?.Invoke(this, mapInfoEventArgs); return(mapInfoEventArgs.Handled); } return(false); }
public void IgnoringLayersOutOfScaleRange() { // arrange var map = new Map(); map.Viewport.Resolution = 1; map.Viewport.Width = 10; map.Viewport.Height = 10; map.Viewport.Center = new Point(5, 5); var layerBelowRange = new MemoryLayer { Name = "MaxVisibleLayer", DataSource = new MemoryProvider(CreatePolygon(1, 3)), MaxVisible = 0.9 }; var layerAboveRange = new MemoryLayer { Name = "MinVisibleLayer", DataSource = new MemoryProvider(CreatePolygon(1, 3)), MinVisible = 1.1 }; map.Layers.Add(layerBelowRange); map.Layers.Add(layerAboveRange); map.InfoLayers.Add(layerBelowRange); map.InfoLayers.Add(layerAboveRange); var screenPositionHit = map.Viewport.WorldToScreen(2, 2); var scale = 1; // act var argsHit = InfoHelper.GetMapInfo(map.Viewport, screenPositionHit, scale, map.InfoLayers, null); // assert; Assert.IsTrue(argsHit.Feature == null); Assert.IsTrue(argsHit.Layer == null); Assert.IsTrue(argsHit.WorldPosition.Equals(new Point(2, 2))); }
public void TestInfo() { // arrange var map = new Map(); map.Viewport.Resolution = 1; map.Viewport.Width = 10; map.Viewport.Height = 10; map.Viewport.Center = new Point(5, 5); var layer = new MemoryLayer { Name = "TestLayer", DataSource = new MemoryProvider(CreatePolygon(1, 4)) }; map.Layers.Add(layer); map.InfoLayers.Add(layer); var screenPositionHit = map.Viewport.WorldToScreen(2, 2); var screenPositionMiss = map.Viewport.WorldToScreen(9, 9); var scale = 1; // act var argsHit = InfoHelper.GetMapInfo(map.Viewport, screenPositionHit, scale, map.InfoLayers, null); var argsMis = InfoHelper.GetMapInfo(map.Viewport, screenPositionMiss, scale, map.InfoLayers, null); // assert; Assert.IsTrue(argsHit.Feature.Geometry != null); Assert.IsTrue(argsHit.Layer.Name == "TestLayer"); Assert.IsTrue(argsHit.WorldPosition.Equals(new Point(2, 2))); // If not on feature still return args with world position. Assert.IsTrue(argsMis.Feature?.Geometry == null); Assert.IsTrue(argsMis.Layer == null); Assert.IsTrue(argsMis.WorldPosition.Equals(new Point(9, 9))); }