private void PerformSelection(D2DShape shape) { MapShapeModel model = shape.Model as MapShapeModel; if (model == null) { Debug.Assert(false, "Must have a model associated with each UI shape"); return; } var context = new SelectionChangeContext() { Layer = this.map.Layers.FindLayerById(shape.LayerId), Shape = shape, Model = model }; if (this.selectionModeCache == MapShapeSelectionMode.Single) { this.SingleSelect(context, true); } else if (this.selectionModeCache == MapShapeSelectionMode.MultiSimple) { this.SingleSelect(context, false); } else if (this.selectionModeCache == MapShapeSelectionMode.MultiExtended) { this.MultiExtendedSelect(context); } this.NotifySelectionChanged(context); }
private void ApplyShapeLabelStrategy(D2DShape shape) { if (this.shapeLabelLayoutStrategyCache == null) { return; } var context = new MapShapeLabelLayoutContext() { Shape = shape.Model as IMapShape, ZoomLevel = this.Owner.ZoomLevel, Label = shape.Label.Text, Center = this.Owner.Center, RenderLocationOrigin = new Point(0.5, 0.5) }; this.shapeLabelLayoutStrategyCache.Process(context, this); shape.LabelVisibility = context.Visibility; if (context.RenderLocation.HasValue) { var position = this.Owner.ConvertGeographicToPixelCoordinate(context.RenderLocation.Value); shape.LabelRenderPosition = position; } if (context.RenderLocationOrigin.HasValue) { shape.LabelRenderPositionOrigin = context.RenderLocationOrigin.Value; } }
private void ClearHoveredShape() { if (this.hoveredShape != null) { if (this.hoveredShape.UIState == ShapeUIState.PointerOver) { this.hoveredShape.UIState = ShapeUIState.Normal; } this.hoveredShape = null; } }
private void AddShape(D2DShape shape, MapShapeModel model) { // cross-references since we need to look-up a model from a shape and a shape from a model this.modelToVisualTable.Add(model, shape); shape.Model = model; // TODO: Extend label logic shape.Label = this.GetShapeTextBlock(model); this.ApplyShapeStyle(shape); this.shapes.Add(shape); }
/// <summary> /// Selects the shape. /// </summary> public void Select() { if (this.LayerPeer.SelectionBehavior != null) { D2DShape shape = this.LayerPeer.LayerOwner.Owner.FindShapeForModel(this.ShapeModel); if (shape != null) { this.LayerPeer.SelectionBehavior.PerformSelection(shape); this.RaisePropertyChangedEvent(SelectionItemPatternIdentifiers.IsSelectedProperty, false, true); } } }
private void ApplyShapeLabel(D2DShape shape, MapShapeStyleContext selectorContext) { if (shape.Label == null) { return; } D2DTextStyle labelStyle = this.labelStyleCache; if (selectorContext != null && selectorContext.LabelStyle != null) { labelStyle = selectorContext.LabelStyle; } if (labelStyle != null) { shape.Label.Style = labelStyle; } this.ApplyShapeLabelStrategy(shape); }
internal void UpdateHoveredShape(Point location) { foreach (var shape in this.HitTest(location)) { this.ClearHoveredShape(); if (shape == null || this.map == null) { continue; } var d2dShape = this.map.FindShapeForModel(shape); if (d2dShape == null) { continue; } if (d2dShape.UIState != ShapeUIState.Selected) { d2dShape.UIState = ShapeUIState.PointerOver; this.hoveredShape = d2dShape; } } }
private void ApplyShapeStyle(D2DShape shape) { (shape.Model as IMapShape).AttributeChanged -= this.MapShapeLayer_AttributeChanged; (shape.Model as IMapShape).AttributeChanged += this.MapShapeLayer_AttributeChanged; D2DShapeStyle normalStyle = this.normalStyleCache; D2DShapeStyle pointerOverStyle = this.pointerOverStyleCache; D2DShapeStyle selectedStyle = this.selectedStyleCache; if (this.colorizerCache != null && this.colorizerCache.IsProperlyInitialized) { var style = this.colorizerCache.GetShapeStyle(shape.Model as IMapShape); if (style != null) { if (normalStyle != null) { if (style.Stroke == null) { style.Stroke = normalStyle.Stroke; } if (style.Foreground == null) { style.Foreground = normalStyle.Foreground; } if (style.StrokeThickness == 1) { style.StrokeThickness = normalStyle.StrokeThickness; } } normalStyle = style; } } MapShapeStyleContext selectorContext = null; if (this.shapeStyleSelectorCache != null) { selectorContext = new MapShapeStyleContext() { Shape = shape.Model as IMapShape, UIState = shape.UIState }; this.shapeStyleSelectorCache.SelectStyle(selectorContext, this); if (selectorContext.NormalStyle != null) { normalStyle = selectorContext.NormalStyle; } if (selectorContext.PointerOverStyle != null) { pointerOverStyle = selectorContext.PointerOverStyle; } if (selectorContext.SelectedStyle != null) { selectedStyle = selectorContext.SelectedStyle; } } // TODO: We may run into a D2DFactory exception if the resources provided by the user are shared across different Map instances // TODO: This requires some refactoring, which will be handled after the Q3 release shape.NormalStyle = normalStyle; shape.PointerOverStyle = pointerOverStyle; shape.SelectedStyle = selectedStyle; this.ApplyShapeLabel(shape, selectorContext); }