Esempio n. 1
0
        /// <summary>
        /// Get fill color for cluster graphics. OrdersColor in case of only orders.
        /// Route color in case of unique route. GrayColor otherwise.
        /// </summary>
        /// <param name="cluster"></param>
        /// <returns></returns>
        private SolidColorBrush _GetFillColor(IList <Graphic> cluster)
        {
            ClusterSymbol   clusterSymbol = (ClusterSymbol)Symbol;
            SolidColorBrush brush         = (SolidColorBrush)clusterSymbol.ControlTemplate.Resources["GrayColor"];

            bool isOrders      = true;
            bool isUniqueRoute = true;

            foreach (Graphic graphic in cluster)
            {
                DataGraphicObject dataGraphic = (DataGraphicObject)graphic;
                if (dataGraphic.Data is Order)
                {
                    isUniqueRoute = false;
                }
                else
                {
                    isOrders = false;
                }

                if (isUniqueRoute)
                {
                    Stop stop = (Stop)dataGraphic.Data;
                    DataGraphicObject firstDataGraphic = (DataGraphicObject)cluster[0];
                    Stop firstStop = (Stop)firstDataGraphic.Data;
                    isUniqueRoute = stop.Route == firstStop.Route;
                }
            }

            if (isOrders)
            {
                Debug.Assert(!isUniqueRoute);
                brush = (SolidColorBrush)clusterSymbol.ControlTemplate.Resources["OrdersColor"];
            }

            if (isUniqueRoute)
            {
                Debug.Assert(!isOrders);
                DataGraphicObject firstDataGraphic = (DataGraphicObject)cluster[0];
                Stop  firstStop = (Stop)firstDataGraphic.Data;
                Route route     = firstStop.Route;

                // stop will not assign to route in case of not updated schedule
                if (route != null)
                {
                    Color mediaColor = System.Windows.Media.Color.FromArgb(route.Color.A,
                                                                           route.Color.R, route.Color.G, route.Color.B);
                    brush = new SolidColorBrush(mediaColor);

                    _route = route;
                    route.PropertyChanged += new PropertyChangedEventHandler(route_PropertyChanged);
                }
            }

            return(brush);
        }
        /// <summary>
        /// Process data graphic mouse events.
        /// </summary>
        /// <param name="dataGraphic">Data graphic.</param>
        /// <param name="clickedGraphic">Last clicked item.</param>
        private void _ProcessDataGraphicMouseEvents(DataGraphicObject dataGraphic, Graphic clickedGraphic)
        {
            Debug.Assert(dataGraphic != null);
            Debug.Assert(_mapControl != null);

            ObjectLayer layer = _FindObjectLayer(dataGraphic);

            // Candidates selects not in common map selected items, but diretly in object layer.
            if (dataGraphic is CandidateGraphicObject)
            {
                _AddToSelection(dataGraphic.Data);
            }
            else if (layer != null && layer.Selectable && !_mapControl.IsInEditedMode)
            {
                // Check down and up points equals.
                if (clickedGraphic == dataGraphic && layer.Selectable)
                {
                    // Do not need to clear selection and return the same element.
                    if (!(SelectedItems.Count == 1 && SelectedItems[0] == dataGraphic.Data))
                    {
                        if (Keyboard.Modifiers != ModifierKeys.Shift && Keyboard.Modifiers != ModifierKeys.Control && SelectedItems.Count > 0)
                        {
                            SelectedItems.Clear();
                        }

                        SelectionWasMade = true;

                        List<object> elementList = new List<object>();
                        elementList.Add(dataGraphic.Data);
                        _ProcessSelectionChanges(elementList, layer);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// React on mouse up.
        /// </summary>
        /// <param name="modifierKeys">Modifier keys state.</param>
        /// <param name="x">X coord.</param>
        /// <param name="y">Y coord.</param>
        public void OnMouseUp(MouseButton pressedButton,
            ModifierKeys modifierKeys, double x, double y)
        {
            Debug.Assert(_mapControl != null);

            _EndPan();

            if (_editingInProcess)
            {
                App.Current.Project.Save();

                // Save to local geocoder database.
                Order order = _mapControl.EditedObject as Order;
                if (order != null)
                {
                    NameAddressRecord nameAddressRecord = CommonHelpers.CreateNameAddressPair(order, null);

                    // Do save in local storage.
                    App.Current.NameAddressStorage.InsertOrUpdate(nameAddressRecord,
                        App.Current.Geocoder.AddressFormat);
                }

                // Check new position is near to road. Set match method if not.
                IGeocodable geocodable = _mapControl.EditedObject as IGeocodable;
                if (geocodable != null)
                {
                    Address addressUnderPoint = _ReverseGeocode(geocodable.GeoLocation.Value);
                    if (addressUnderPoint == null)
                    {
                        geocodable.Address.MatchMethod = (string)App.Current.FindResource(MANUALLY_EDITED_XY_FAR_FROM_NEAREST_ROAD_RESOURCE_NAME);
                    }
                }

                if (OnComplete != null)
                    OnComplete(this, EventArgs.Empty);
                _editingInProcess = false;
                _editedGraphic = null;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// React on mouse down.
        /// </summary>
        /// <param name="pressedButton">Pressed mouse button.</param>
        /// <param name="modifierKeys">Modifier keys state.</param>
        /// <param name="x">X coord.</param>
        /// <param name="y">Y coord.</param>
        public void OnMouseDown(MouseButton pressedButton,
            ModifierKeys modifierKeys, double x, double y)
        {
            Debug.Assert(_mapControl != null);

            if (_mapControl.PointedGraphic != null)
            {
                Point point = new Point(x, y);

                // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator.
                if (_mapControl.Map.SpatialReferenceID.HasValue)
                {
                    point = WebMercatorUtil.ProjectPointFromWebMercator(point, _mapControl.Map.SpatialReferenceID.Value);
                }

                // Save current position.
                _previousX = point.X;
                _previousY = point.Y;

                // Start dragging.
                DataGraphicObject pointedGraphicObject = _mapControl.PointedGraphic as DataGraphicObject;
                if (pointedGraphicObject != null &&
                    (pointedGraphicObject.Data == EditingObject || pointedGraphicObject is EditMarkerGraphicObject))
                {
                    _editingInProcess = true;
                    _editedGraphic = pointedGraphicObject;
                    _StartPan();
                }
            }
            else
            {
                _editingInProcess = false;
            }
        }
        private static Symbol _InitGraphicByRecord(SymbologyRecord record, DataGraphicObject graphicObject)
        {
            Symbol symbol = new MarkerSymbol();

            symbol.ControlTemplate = GetTemplateByFileName(record.SymbolFilename);
            graphicObject.Attributes[SymbologyContext.SIZE_ATTRIBUTE_NAME] = record.Size;
            graphicObject.Attributes[SymbologyContext.OFFSETX_ATTRIBUTE_NAME] =
                -record.Size / 2 - SymbologyManager.DEFAULT_INDENT / 2;
            graphicObject.Attributes[SymbologyContext.OFFSETY_ATTRIBUTE_NAME] =
                -record.Size / 2 - SymbologyManager.DEFAULT_INDENT / 2;
            graphicObject.Attributes[SymbologyContext.FULLSIZE_ATTRIBUTE_NAME] =
                record.Size + SymbologyManager.DEFAULT_INDENT;

            if (!record.UseRouteColor)
            {
                System.Drawing.Color color = (System.Drawing.Color)record.Color;
                System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
                graphicObject.Attributes[SymbologyContext.FILL_ATTRIBUTE_NAME] = new SolidColorBrush(mediaColor);
            }
            else
            {
                System.Windows.Media.Color mediaColor;

                Stop stop = graphicObject.Data as Stop;
                if (stop == null)
                    mediaColor = System.Windows.Media.Color.FromRgb(0, 0, 0);
                else
                {
                    System.Drawing.Color color = stop.Route.Color;
                    mediaColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
                }
                graphicObject.Attributes[SymbologyContext.FILL_ATTRIBUTE_NAME] = new SolidColorBrush(mediaColor);
            }

            return symbol;
        }
        private static Symbol _InitGraphicByQuantity(object value, DataGraphicObject graphicObject)
        {
            SymbologyRecord record = null;
            if (value != null)
            {
                double? numValue = null;
                if (value is string)
                {
                    double result;
                    if (double.TryParse((string)value, out result))
                        numValue = result;
                }
                else
                    numValue = (double)value;

                if (numValue.HasValue)
                {
                    foreach (OrderQuantity orderQuantity in OrderQuantities)
                    {
                        if (!orderQuantity.DefaultValue && value != null &&
                            (orderQuantity.MinValue == numValue ||
                            orderQuantity.MinValue < numValue && orderQuantity.MaxValue > numValue))
                        {
                            record = orderQuantity;
                        }
                    }
                }
            }

            if (record == null)
                foreach (OrderQuantity orderQuantity in OrderQuantities)
                    if (orderQuantity.DefaultValue)
                        record = orderQuantity;

            return _InitGraphicByRecord(record, graphicObject);
        }
        private static Symbol _InitGraphicByCategory(object value, DataGraphicObject graphicObject)
        {
            SymbologyRecord record = null;
            foreach (OrderCategory orderCategory in OrderCategories)
                if (!orderCategory.DefaultValue && value != null && orderCategory.Value == value.ToString())
                {
                    record = orderCategory;
                    break;
                }

            if (record == null)
                foreach (OrderCategory orderCategory in OrderCategories)
                    if (orderCategory.DefaultValue)
                        record = orderCategory;

            return _InitGraphicByRecord(record, graphicObject);
        }
        /// <summary>
        /// Init Graphic. Set it's attributes and symbol
        /// </summary>
        /// <param name="graphicObject">Graphic to init</param>
        public static void InitGraphic(DataGraphicObject graphicObject)
        {
            if (!_inited)
                _InitProjectSymbology();

            if (FieldName.Length == 0)
            {
                System.Windows.Media.Color mediaColor;

                Stop stop = graphicObject.Data as Stop;
                if (stop == null)
                    mediaColor = System.Windows.Media.Color.FromRgb(0, 0, 0);
                else
                {
                    System.Drawing.Color color = stop.Route.Color;
                    mediaColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
                }
                graphicObject.Attributes[SymbologyContext.FILL_ATTRIBUTE_NAME] = new SolidColorBrush(mediaColor);

                graphicObject.Symbol = new CustomOrderSymbol();
            }
            else
            {
                Order order = graphicObject.Data as Order;
                if (order == null)
                {
                    Stop stop = (Stop)graphicObject.Data;
                    order = (Order)stop.AssociatedObject;
                }

                object value = Order.GetPropertyValue(order, FieldName);
                Symbol orderSymbol;
                if (SymbologyType == SymbologyType.CategorySymbology)
                    orderSymbol = _InitGraphicByCategory(value, graphicObject);
                else
                    orderSymbol = _InitGraphicByQuantity(value, graphicObject);

                graphicObject.Symbol = orderSymbol;
            }
        }