Exemplo n.º 1
0
        private void OnColoredMapLinePointsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Move)
            {
                return;
            }
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                SetMapLines(new List <MapPolyline>());
            }

            if (e.NewItems != null)
            {
                List <MapPolyline>      newPolylines         = new List <MapPolyline>();
                List <BasicGeoposition> currentLinePositions = new List <BasicGeoposition>();
                foreach (ColoredMapLine lineCollection in e.NewItems.OfType <ColoredMapLine>())
                {
                    for (int i = 0; i <= lineCollection.Count() - 2; i++)
                    {
                        var startPoint = lineCollection[i];
                        var nextPoint  = lineCollection[i + 1];
                        currentLinePositions.Add(startPoint.Coordinates);

                        Color nextColor = nextPoint.LineColor;
                        if (nextPoint == lineCollection.Last() || startPoint.LineColor != nextColor)
                        {
                            MapPolyline polyline = new MapPolyline();
                            polyline.Path            = new Geopath(currentLinePositions);
                            polyline.StrokeColor     = Color.FromArgb(192, startPoint.LineColor.R, startPoint.LineColor.G, startPoint.LineColor.B);
                            polyline.StrokeDashed    = startPoint.IsLineDashed;
                            polyline.StrokeThickness = 6;
                            if (lineCollection.OptionalId != Guid.Empty)
                            {
                                MapElementExtensions.SetPoiId(polyline, lineCollection.OptionalId);
                            }
                            newPolylines.Add(polyline);

                            currentLinePositions = new List <BasicGeoposition>();
                        }
                    }
                }
                AddMapLines(newPolylines);
            }

            if (e.OldItems != null)
            {
                var removedLines = new List <MapPolyline>();
                foreach (ColoredMapLine oldLine in e.OldItems.OfType <ColoredMapLine>())
                {
                    MapPolyline removedLine = DigiTransitMapControl.MapElements
                                              .OfType <MapPolyline>()
                                              .FirstOrDefault(line => MapElementExtensions.GetPoiId(line) == oldLine.OptionalId);
                    if (removedLine != null)
                    {
                        removedLines.Add(removedLine);
                    }
                }
                RemoveMapLines(removedLines);
            }
        }
Exemplo n.º 2
0
        private static async void OnPlacesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var _this = d as DigiTransitMap;

            if (_this == null)
            {
                return;
            }

            //set up INotifyCollectionChangeds
            var oldCollection = e.OldValue as INotifyCollectionChanged;
            var newCollection = e.NewValue as INotifyCollectionChanged;

            if (oldCollection != null)
            {
                oldCollection.CollectionChanged -= _this.OnPlacesCollectionChanged;
            }
            if (newCollection != null)
            {
                newCollection.CollectionChanged += _this.OnPlacesCollectionChanged;
            }

            var newList = e.NewValue as IEnumerable <IMapPoi>;

            if (newList == null)
            {
                return;
            }

            List <MapIcon> icons = new List <MapIcon>();

            foreach (var place in newList.OfType <IMapPoi>())
            {
                MapIcon element = new MapIcon();
                element.Image = RandomAccessStreamReference.CreateFromStream(await _themeIconSource);
                element.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
                element.Location = new Geopoint(place.Coords);
                element.Title    = place.Name;
                element.NormalizedAnchorPoint = new Point(0.5, 1.0);
                MapElementExtensions.SetPoiId(element, place.Id);
                icons.Add(element);
            }

            _this.SetMapIcons(icons);
        }
Exemplo n.º 3
0
        private async void OnPlacesCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action == NotifyCollectionChangedAction.Move)
            {
                return;
            }
            if (args.Action == NotifyCollectionChangedAction.Reset)
            {
                SetMapIcons(null);
            }

            if (args.NewItems != null)
            {
                var newIcons = new List <MapIcon>();
                foreach (IMapPoi place in args.NewItems.OfType <IMapPoi>())
                {
                    var element = new MapIcon();
                    element.Image = RandomAccessStreamReference.CreateFromStream(await _themeIconSource);
                    element.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
                    element.Location = new Geopoint(place.Coords);
                    element.Title    = place.Name;
                    element.NormalizedAnchorPoint = new Point(0.5, 1.0);
                    element.SetValue(PoiIdProperty, place.Id);
                    MapElementExtensions.SetPoiId(element, place.Id);
                    newIcons.Add(element);
                }
                AddMapIcons(newIcons);
            }

            if (args.OldItems != null)
            {
                var removedIcons = new List <MapIcon>();
                foreach (IMapPoi place in args.OldItems.OfType <IMapPoi>())
                {
                    var removedIcon = DigiTransitMapControl.MapElements
                                      .OfType <MapIcon>()
                                      .FirstOrDefault(x => x.Location.Position.Equals(place.Coords));
                    removedIcons.Add(removedIcon);
                }
                RemoveMapIcons(removedIcons);
            }
        }
Exemplo n.º 4
0
        private static void ColoredMapLinesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DigiTransitMap _this = d as DigiTransitMap;

            if (_this == null)
            {
                return;
            }

            var oldCollection = e.OldValue as INotifyCollectionChanged;
            var newCollection = e.NewValue as INotifyCollectionChanged;

            if (oldCollection != null)
            {
                oldCollection.CollectionChanged -= _this.OnColoredMapLinePointsCollectionChanged;
            }
            if (newCollection != null)
            {
                newCollection.CollectionChanged += _this.OnColoredMapLinePointsCollectionChanged;
            }

            IList <ColoredMapLine> newValue = e.NewValue as IList <ColoredMapLine>;

            if (newValue == null)
            {
                if (_this.DigiTransitMapControl.MapElements.OfType <MapPolyline>().Any())
                {
                    _this.SetMapLines(null);
                }
                return;
            }

            List <MapPolyline>      newPolylines         = new List <MapPolyline>();
            List <BasicGeoposition> currentLinePositions = new List <BasicGeoposition>();

            foreach (ColoredMapLine lineCollection in newValue)
            {
                for (int i = 0; i <= lineCollection.Count() - 2; i++)
                {
                    var startPoint = lineCollection[i];
                    var nextPoint  = lineCollection[i + 1];
                    currentLinePositions.Add(startPoint.Coordinates);

                    Color nextColor = nextPoint.LineColor;
                    if (nextPoint == lineCollection.Last() || startPoint.LineColor != nextColor)
                    {
                        MapPolyline polyline = new MapPolyline();
                        polyline.Path            = new Geopath(currentLinePositions);
                        polyline.StrokeColor     = Color.FromArgb(192, startPoint.LineColor.R, startPoint.LineColor.G, startPoint.LineColor.B);
                        polyline.StrokeDashed    = startPoint.IsLineDashed;
                        polyline.StrokeThickness = 6;
                        if (lineCollection.OptionalId != Guid.Empty)
                        {
                            MapElementExtensions.SetPoiId(polyline, lineCollection.OptionalId);
                        }
                        newPolylines.Add(polyline);

                        currentLinePositions = new List <BasicGeoposition>();
                    }
                }
            }

            _this.SetMapLines(newPolylines);
        }