private void RemoveTracker(OverlayTrackerTileProvider tracker)
        {
            TileOverlay overlay = tracker.TileOverlay;

            tracker.RemoveAllTiles();
            overlay.Remove();

            _TileTrackers.Remove(tracker);
        }
Пример #2
0
        private void AddTrackerForOverlay(SKMapOverlay sharedOverlay)
        {
            OverlayTrackerTileProvider tracker        = new OverlayTrackerTileProvider(Context, NativeMap, sharedOverlay);
            TileOverlayOptions         overlayOptions = new TileOverlayOptions().InvokeTileProvider(tracker);
            TileOverlay overlay = NativeMap.AddTileOverlay(overlayOptions);

            tracker.TileOverlay = overlay;
            _TileTrackers.Add(tracker);
        }
        private void MapOverlaysCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            IEnumerable <SKMapOverlay> newItems = args.NewItems?
                                                  .OfType <SKMapOverlay>()
                                                  .DefaultIfEmpty();
            IEnumerable <SKMapOverlay> removedItems = args.OldItems?
                                                      .OfType <SKMapOverlay>()
                                                      .DefaultIfEmpty();

            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                foreach (SKMapOverlay mapOverlay in newItems)
                {
                    AddTrackerForOverlay(mapOverlay);
                }
                break;
            }

            case NotifyCollectionChangedAction.Remove:
            {
                foreach (SKMapOverlay mapOverlay in removedItems)
                {
                    OverlayTrackerTileProvider tracker = FindTrackerForOverlay(mapOverlay);

                    if (tracker != null)
                    {
                        RemoveTracker(tracker);
                    }
                }
                break;
            }

            case NotifyCollectionChangedAction.Replace:
            {
                foreach (SKMapOverlay mapOverlay in removedItems)
                {
                    OverlayTrackerTileProvider tracker = FindTrackerForOverlay(mapOverlay);

                    if (tracker != null)
                    {
                        RemoveTracker(tracker);
                    }
                }

                foreach (SKMapOverlay mapOverlay in newItems)
                {
                    AddTrackerForOverlay(mapOverlay);
                }
                break;
            }

            case NotifyCollectionChangedAction.Reset:
            {
                List <OverlayTrackerTileProvider> oldTrackers = new List <OverlayTrackerTileProvider>(_TileTrackers);

                foreach (OverlayTrackerTileProvider tracker in oldTrackers)
                {
                    RemoveTracker(tracker);
                }

                foreach (SKMapOverlay overlay in _SharedControl.MapOverlays)
                {
                    AddTrackerForOverlay(overlay);
                }
                break;
            }
            }
        }