/// <summary> /// An event handler called when the mouse leaves the control. /// </summary> /// <param name="e">The event arguments.</param> protected override void OnMouseLeave(EventArgs e) { // Call the base class methods. base.OnMouseLeave(e); // Clear the mouse over flag. this.mouseOverFlag = false; // If there exists a highlighted marker. if (null != this.highlightMarker) { // Invalidate the bounds of that region. this.Invalidate(this.highlightMarker.Bounds.Add(this.bitmapLocation)); // Set the highlighted marker to null. this.highlightMarker = null; } // If there exists a highlighted region. if (null != this.highlightRegion) { // Invalidate the bounds of that region. this.Invalidate(this.highlightRegion.Bounds.Add(this.bitmapLocation)); // Set the highlighted region to null. this.highlightRegion = null; } // If there exists an emphasized marker. if ((null != this.emphasizedMarker) && this.showMarkers) { // Show the info annotation. this.OnShowAnnotation(this.annotationInfo, this.emphasizedMarker.Name, this.emphasizedMarker); } else { // Hide the info annotation. this.OnHideAnnotation(this.annotationInfo); } }
/// <summary> /// An event handler called when finishing executing the mouse move lazy code. /// </summary> /// <param name="highlightMarker">The highlighted marker.</param> /// <param name="highlightRegion">The highlighted code.</param> private void OnMouseMoveLazyFinish(MapMarker highlightMarker, MapRegion highlightRegion) { // Execute the code on the UI thread. this.Invoke(() => { // If the mouse over flag is not set, do nothing. if (!this.mouseOverFlag) return; // If the highlighted marker has changed. if (this.highlightMarker != highlightMarker) { // If there exists a previous highlighted marker. if (null != this.highlightMarker) { // Invalidate the bounds of that marker. this.Invalidate(this.highlightMarker.Bounds.Add(this.bitmapLocation)); } // If there exists a current highlighted marker. if ((null != highlightMarker) && this.showMarkers) { // Invalidate the bounds of that marker. this.Invalidate(highlightMarker.Bounds.Add(this.bitmapLocation)); // Show the info annotation. this.OnShowAnnotation(this.annotationInfo, highlightMarker.Name, highlightMarker); } else { // If there is an emphasized marker. if ((null != this.emphasizedMarker) && this.showMarkers) { // Show the info annotation. this.OnShowAnnotation(this.annotationInfo, this.emphasizedMarker.Name, this.emphasizedMarker); } // Else, if there is a highlighted region. else if (null != highlightRegion) { // Show the info annotation. this.OnShowAnnotation(this.annotationInfo, highlightRegion.Name, highlightRegion); } // Else. else { // Hide the info annotation. this.OnHideAnnotation(this.annotationInfo); } } // Set the new highlighted marker. this.highlightMarker = highlightMarker; } // If the highlighted region has changed. if (this.highlightRegion != highlightRegion) { // If there exists a previous highlighted region. if (null != this.highlightRegion) { // Invalidate the bounds of that region. this.Invalidate(this.highlightRegion.Bounds.Add(this.bitmapLocation)); } // If there exists a current highlighted region. if (null != highlightRegion) { // Invalidate the bounds of that region. this.Invalidate(highlightRegion.Bounds.Add(this.bitmapLocation)); // If there is no highlighted marker and no emphasized marker or if the markers are hidden. if (((null == this.highlightMarker) && (null == this.emphasizedMarker)) || !this.showMarkers) { // Show the info annotation. this.OnShowAnnotation(this.annotationInfo, highlightRegion.Name, highlightRegion); } } else { // If there is no highlighted marker and no emphasized marker. if (((null == this.highlightMarker) && (null == this.emphasizedMarker)) || !this.showMarkers) { // Hide the info annotation. this.OnHideAnnotation(this.annotationInfo); } } // Set the new highlighted region. this.highlightRegion = highlightRegion; } }); }
/// <summary> /// An event handler called when starting executing the mouse move lazy code. /// </summary> /// <param name="e">The event arguments.</param> private void OnMouseMoveLazyStart(MouseEventArgs e) { // Compute the mouse location. Point location = e.Location.Subtract(this.bitmapLocation); // Execute the lazy code on the thread pool. ThreadPool.QueueUserWorkItem((object state) => { // If the object has been disposed, do nothing. if (this.IsDisposed) return; // Try lock the mouse move mutex. if (Monitor.TryEnter(this.syncMouseMove)) { try { // The current highlighted marker. MapMarker highlightMarker = null; // The current highlighted region. MapRegion highlightRegion = null; // Get an exclusive lock to the markers collection. this.markers.Lock(); try { // Compute the new highlight marker. foreach (MapMarker marker in this.markers) { // If the marker contains the mouse location. if (marker.IsVisible(location)) { // Set the current highlighted marker. highlightMarker = marker; // Stop the iteration. break; } } } finally { this.markers.Unlock(); } // Get an exclusive reader lock to the regions list. this.regions.Lock(); try { // Compute the new highlight region. foreach (MapRegion region in this.regions) { // If the region contains the mouse location. if (region.IsVisible(location)) { // Set the current highlighted region. highlightRegion = region; // Stop the iteration. break; } } } finally { this.regions.Unlock(); } // Call the mouse move lazy finish. this.OnMouseMoveLazyFinish(highlightMarker, highlightRegion); } finally { Monitor.Exit(this.syncMouseMove); } } }); }
// Private methods. /// <summary> /// Sets the current map. /// </summary> /// <param name="map">The map.</param> private void OnMapChanged(Map map) { // If the map has not changed, do nothing. if (this.map == map) return; // Lock the drawing synchronization object. lock (this.syncDrawing) { // Set the current map. this.map = map; // Get an exclusive reader lock to the regions list. this.regions.Lock(); try { // Dispose the existing map regions. foreach (MapRegion region in this.regions) { region.Dispose(); } } finally { this.regions.Unlock(); } // Clear the regions list. this.regions.Clear(); // If the current map is not null. if (null != this.map) { // Create the map shapes. foreach (MapShape shape in map.Shapes) { // Switch according to the shape type. switch (shape.Type) { case MapShapeType.Polygon: // Get the polygon shape. MapShapePolygon shapePolygon = shape as MapShapePolygon; // Create a map region for this shape. MapRegion region = new MapRegion(shapePolygon); // Update the region. region.Update(this.mapBounds, this.mapScale); // Add the map region to the region items. this.regions.Add(region); break; default: continue; } } } } // Refresh the current map. this.OnRefreshMap(); }