Beispiel #1
0
        public void Overlays7()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Inconclusive("requires 7.0+");
            }

            using (var polygon = new MKPolygon())
                using (var polyline = new MKPolyline())
                    using (var circle = new MKCircle())
                        using (var tile = new MKTileOverlay())
                            using (MKMapView mv = new MKMapView()) {
                                // new API accepted MKOverlay (better protocol support)
                                mv.AddOverlay(polygon, MKOverlayLevel.AboveLabels);
                                mv.AddOverlay(tile, MKOverlayLevel.AboveLabels);
                                Assert.That(mv.Overlays.Length, Is.EqualTo(2), "1");
                                mv.RemoveOverlay(tile);
                                mv.RemoveOverlay(polygon);
                                Assert.That(mv.Overlays, Is.Empty, "2");

                                IMKOverlay[] list = { polygon, polyline, circle, tile };
                                mv.AddOverlays(list, MKOverlayLevel.AboveRoads);
                                Assert.That(mv.Overlays.Length, Is.EqualTo(4), "3");
                                mv.RemoveOverlays(list);
                                Assert.That(mv.Overlays, Is.Empty, "4");
                            }
        }
Beispiel #2
0
        public void InsertCoordinate(int index, CLLocationCoordinate2D coord)
        {
            var indexOverlay = GetOverlayIndex(ZIndex);

            if (_polylines.Count == 0)
            {
                // no position yet
                var polyline = MKPolyline.FromCoordinates(new[] { coord });
                _map.InsertOverlay(polyline, indexOverlay);
                _polylines.Add(polyline);
            }
            else
            {
                // find the polyline to extend with the new coordinate
                // add position to the las polyline
                var polyline = _polylines.Last();
                _map.RemoveOverlay(polyline);
                _polylines.Remove(polyline);
                var points = new List <CLLocationCoordinate2D>(polyline.GetCoordinates(0, (int)polyline.PointCount));
                points.Add(coord);
                polyline = MKPolyline.FromCoordinates(points.ToArray());
                _polylines.Add(polyline);
                _map.InsertOverlay(polyline, indexOverlay);

                if (polyline.PointCount == PolylineSegmentLength + 1)
                {
                    // Polyline is full
                    var nextPolyline = MKPolyline.FromCoordinates(new[] { coord });
                    _map.InsertOverlay(nextPolyline, indexOverlay);
                    _polylines.Add(nextPolyline);
                }
            }
        }
Beispiel #3
0
 public void removeOverlays()
 {
     if (nativeMap.Overlays != null && nativeMap.Overlays.Length > 0)
     {
         nativeMap.RemoveOverlay(nativeMap.Overlays[0]);
         this.circleRenderer       = null;
         nativeMap.OverlayRenderer = this.GetOverlayRenderer;
     }
 }
Beispiel #4
0
        public void updatePolygon()
        {
            var points = itemsArray.Select(l => l.Coordinate).ToArray();

            if (Polygon != null)
            {
                mainMapView.RemoveOverlay(Polygon);
            }
            Polygon = MKPolygon.FromCoordinates(points);
            mainMapView.AddOverlay(Polygon);
        }
        private void UpdatePolyLine()
        {
            //var nativeMap = Control as MKMapView;

            if (polyline != null)
            {
                nativeMap.RemoveOverlay(polyline);
                polyline.Dispose();
            }

            nativeMap.OverlayRenderer = GetOverlayRenderer;

            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];

            int index = 0;

            foreach (var position in formsMap.RouteCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }

            var routeOverlay = MKPolyline.FromCoordinates(coords);

            nativeMap.AddOverlay(routeOverlay);

            polyline = routeOverlay;
        }
 protected override void RemoveSearchAreaPolygon()
 {
     if (_currentSearchPolygon != null)
     {
         _nativeMap.RemoveOverlay(_currentSearchPolygon);
     }
 }
Beispiel #7
0
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            var pointAnnotation = (PolylinePointAnnotation)annotation;

            var annotationView = new XIPinAnnotationView(mapView, annotation, "ximpav")
            {
                Draggable      = pointAnnotation.Polyline?.CanWrite == true,
                AnimatesDrop   = true,
                CanShowCallout = true,
            };

            annotationView.DragLocationChanged += (o, e) => {
                var value = annotationView.Frame;
                if (!isDragging || mapView?.Overlays == null)
                {
                    return;
                }

                if (editPolyline != null)
                {
                    mapView.RemoveOverlay(editPolyline);
                }

                var newPoints = pointAnnotation.Polyline.Value.ToCoordinates();
                newPoints [pointAnnotation.Index] = e.DragLocation;

                editPolyline = MKPolyline.FromCoordinates(newPoints);
                mapView.AddOverlay(editPolyline);
            };

            return(annotationView);
        }
Beispiel #8
0
        void ShowDirections(MKMapItem destination, MKMapView mapView)
        {
            var source = new MKMapItem(new MKPlacemark(ViewController.currentLocation, (MKPlacemarkAddress)null));

            var request = new MKDirectionsRequest()
            {
                Destination             = destination,
                Source                  = source,
                RequestsAlternateRoutes = false,
            };

            var directions = new MKDirections(request);

            directions.CalculateDirections((MKDirectionsResponse response, NSError e) => {
                if (this.route != null)
                {
                    mapView.RemoveOverlay(this.route);
                }

                if (response == null || response.Routes.Length == 0)
                {
                    return;
                }

                //save the overlay so we can remove it next time we draw
                route = response.Routes[0].Polyline;

                mapView.AddOverlay(route, MKOverlayLevel.AboveRoads);
            });
        }
Beispiel #9
0
        public void removeOverlays()
        {
            if (nativeMap.Overlays != null && nativeMap.Overlays.Length > 0)
            {
                nativeMap.Overlays[0].Dispose();
                nativeMap.RemoveOverlay(nativeMap.Overlays[0]);

            }

        }
Beispiel #10
0
        private void RemoveRouteView(Route route)
        {
            MKPolyline polyline;

            if (renderedRoute.TryGetValue(route, out polyline))
            {
                mapControl?.RemoveOverlay(polyline);
            }
            renderedRoute.Remove(route);
        }
Beispiel #11
0
 //when you click on a part of the callout, delete polygon
 public void removePolygon()
 {
     System.Diagnostics.Debug.WriteLine("delete polygon!------");
     map.setPolygonPoints(0);
     map.ShapeCoordinates.Clear();
     nativeMap.RemoveOverlay(polygon);
     polygonRenderer = null;
     polygon         = null;
     clearShapeMarkers();
 }
Beispiel #12
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                nativeMap.GetViewForAnnotation           = null;
                nativeMap.OverlayRenderer                = null;
                nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       -= OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     -= OnDidDeselectAnnotationView;
            }

            if (e.NewElement != null)
            {
                formsMap  = (LocationMap)e.NewElement;
                nativeMap = Control as MKMapView;

                var circle = formsMap.Circle;
                nativeMap.OverlayRenderer = GetOverlayRenderer;


                if (circle.Position.Latitude != 0.0)
                {
                    _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                    nativeMap.AddOverlay(_circle);
                }

                /* Listen for circle change events */
                MessagingCenter.Subscribe <CustomCircle>(this, "CircleChanged", (obj) =>
                {
                    if (_circle == null)
                    {
                        _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(obj.Position.Latitude, obj.Position.Longitude), obj.Radius);
                        nativeMap.AddOverlay(_circle);
                    }
                    else
                    {
                        nativeMap.RemoveOverlay(_circle);
                        _circle.Dispose();
                        _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(obj.Position.Latitude, obj.Position.Longitude), obj.Radius);
                        nativeMap.AddOverlay(_circle);
                    }
                });

                nativeMap.GetViewForAnnotation           = GetViewForAnnotation;
                nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       += OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     += OnDidDeselectAnnotationView;
            }
        }
Beispiel #13
0
        public void Overlays7()
        {
            TestRuntime.AssertXcodeVersion(5, 0, 1);

            using (var polygon = new MKPolygon())
                using (var polyline = new MKPolyline())
                    using (var circle = new MKCircle())
                        using (var tile = new MKTileOverlay())
                            using (MKMapView mv = new MKMapView()) {
                                // new API accepted MKOverlay (better protocol support)
                                mv.AddOverlay(polygon, MKOverlayLevel.AboveLabels);
                                mv.AddOverlay(tile, MKOverlayLevel.AboveLabels);
                                Assert.That(mv.Overlays.Length, Is.EqualTo(2), "1");
                                mv.RemoveOverlay(tile);
                                mv.RemoveOverlay(polygon);
                                Assert.That(mv.Overlays, Is.Empty, "2");

                                IMKOverlay[] list = { polygon, polyline, circle, tile };
                                mv.AddOverlays(list, MKOverlayLevel.AboveRoads);
                                Assert.That(mv.Overlays.Length, Is.EqualTo(4), "3");
                                mv.RemoveOverlays(list);
                                Assert.That(mv.Overlays, Is.Empty, "4");
                            }
        }
        public void RefreshOrganCircleOnMap(object o)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                organTimeLeft--;

                if (organTimeLeft <= 0)
                {
                    return;
                }
                else
                {
                    double mapRadius;
                    double distanceTime = organTimeLeft * 70;

                    if (distanceTime > 500000)
                    {
                        mapRadius = 500000;
                    }
                    else
                    {
                        mapRadius = distanceTime;
                    }
                    Position currentPosition = customPin.Position;

                    map.Circle = new CustomCircle
                    {
                        Position = currentPosition,
                        Radius   = mapRadius
                    };
                    var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(map.Circle.Position.Latitude, map.Circle.Position.Longitude), map.Circle.Radius);
                    if (nativeMap.Overlays == null || nativeMap.Overlays.Length == 0)
                    {
                        return;
                    }
                    else
                    {
                        nativeMap.RemoveOverlay(nativeMap.Overlays[0]);

                        customMapRenderer.circleRenderer = null;
                        nativeMap.OverlayRenderer        = customMapRenderer.GetOverlayRenderer;

                        nativeMap.AddOverlay(circleOverlay);
                    }
                }
            });
        }
Beispiel #15
0
        public void Overlays()
        {
            using (var polygon = new MKPolygon())
                using (var polyline = new MKPolyline())
                    using (var circle = new MKCircle())
                        using (MKMapView mv = new MKMapView()) {
                            // old API accepted NSObject (limited protocol support)
                            mv.AddOverlay(polygon);
                            Assert.That(mv.Overlays.Length, Is.EqualTo(1), "1");
                            mv.RemoveOverlay(polygon);
                            Assert.That(mv.Overlays, Is.Empty, "2");

                            IMKOverlay[] list = { polygon, polyline, circle };
                            mv.AddOverlays(list);
                            Assert.That(mv.Overlays.Length, Is.EqualTo(3), "3");
                            mv.RemoveOverlays(list);
                            Assert.That(mv.Overlays, Is.Empty, "4");
                        }
        }
Beispiel #16
0
        void Update()
        {
            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[_formsMap.PolylineCoordinates.Count];

            int index = 0;

            foreach (var position in _formsMap.PolylineCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }

            if (_nativeMap.Overlays?.Length > 0 && _routeOverlay != null)
            {
                _nativeMap.RemoveOverlay(_routeOverlay);
            }

            _routeOverlay = MKPolyline.FromCoordinates(coords);
            _nativeMap.AddOverlay(_routeOverlay);
        }
Beispiel #17
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (CustomMap.ShowTileLayerProperty.PropertyName == e.PropertyName)
            {
                if (map == null)
                {
                    return;
                }

                if (CustomMap.ShowTileLayer)
                {
                    map.AddOverlay(TileOverlay, MKOverlayLevel.AboveRoads);
                }
                else
                {
                    map.RemoveOverlay(TileOverlay);
                }
            }
        }
Beispiel #18
0
        public override void ChangedDragState(
            MKMapView mapView,
            MKAnnotationView annotationView,
            MKAnnotationViewDragState newState,
            MKAnnotationViewDragState oldState)
        {
            if (newState == MKAnnotationViewDragState.Ending)
            {
                isDragging = false;

                if (mapView.Overlays != null)
                {
                    mapView.RemoveOverlays(mapView.Overlays);
                }

                var annotation = (PolylinePointAnnotation)annotationView.Annotation;
                annotation.Polyline.Value.Points [annotation.Index] = new GeoLocation(
                    annotation.Coordinate.Latitude,
                    annotation.Coordinate.Longitude);
                var newPolyline = annotation.Polyline.Value.ToMKPolyline();
                mapView.AddOverlay(newPolyline);

                annotation.Polyline.RaisePropertyChanged();

                return;
            }
            else if (newState == MKAnnotationViewDragState.Starting ||
                     newState == MKAnnotationViewDragState.Dragging)
            {
                isDragging = true;
            }
            else
            {
                isDragging = false;
                if (editPolyline != null)
                {
                    mapView.RemoveOverlay(editPolyline);
                }
            }
        }
Beispiel #19
0
        public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view)
        {
            Algorithm algorithm             = new Algorithm();
            CLLocationCoordinate2D origin   = new CLLocationCoordinate2D(45.523538, -122.623040);
            CLLocationCoordinate2D endpoint = new CLLocationCoordinate2D(45.504796, -122.638593);
            GeoPoint originGeo   = new GeoPoint(45.523538, -122.623040);
            GeoPoint endpointGeo = new GeoPoint(45.504796, -122.638593);

            var sampleAnnotation = view.Annotation as PitStopAnnotation;

            if (sampleAnnotation != null)
            {
                TravelData pitStopRouteData = algorithm.getPitStopRoute("driving", originGeo, new GeoPoint(sampleAnnotation.Coordinate.Latitude, sampleAnnotation.Coordinate.Longitude), endpointGeo);

                List <CLLocationCoordinate2D> pitStopCoordsList = new List <CLLocationCoordinate2D> ();
                for (int i = 0; i < pitStopRouteData.steps.Count; i++)
                {
                    Step step = pitStopRouteData.steps [i];
                    pitStopCoordsList.Add(new CLLocationCoordinate2D(pitStopRouteData.steps [i].originXY.latitude, pitStopRouteData.steps [i].originXY.longitude));
                    List <GeoPoint> polylinePoints = Algorithm.decodePoints(step.polyLine);
                    foreach (GeoPoint geoPoint in polylinePoints)
                    {
                        CLLocationCoordinate2D coord = new CLLocationCoordinate2D(geoPoint.latitude, geoPoint.longitude);
                        pitStopCoordsList.Add(coord);
                    }
                    pitStopCoordsList.Add(new CLLocationCoordinate2D(pitStopRouteData.steps [i].endpointXY.latitude, pitStopRouteData.steps [i].endpointXY.longitude));
                }
                CLLocationCoordinate2D[] coordsArray = pitStopCoordsList.ToArray();

                mapView.RemoveOverlay(mapView.Overlays [0]);
                MKPolyline newOverlay = MKPolyline.FromCoordinates(coordsArray);
                mapView.AddOverlay(newOverlay);

                //demo accessing the title of the selected annotation
                Console.WriteLine("{0} was tapped", sampleAnnotation.Title);
            }
        }
        /// <summary>
        /// Posts the load subscriptions.
        /// </summary>
        /// <returns>The load subscriptions.</returns>
        public override IEnumerable <IDisposable> LoadSubscriptions()
        {
            yield return(ViewModel.WhenAnyValue(vm => vm.Feedbacks).BindTo <FeedbackListItemViewModel,
                                                                            FeedbackListItemTableViewCell>(_feedbackTableView, 80, cell => cell.Initialize()));

            yield return(ViewModel.WhenAnyValue(vm => vm.Infos)
                         .Select((IReactiveList <TetrixViewModelBase> list) =>
            {
                return list.GroupBy(model => (float)model.Height)
                .Select(typeGroup =>
                {
                    var collection = new ReactiveList <TetrixViewModelBase>();
                    collection.AddRange(typeGroup);

                    return new TableSectionInformation <TetrixViewModelBase, BaseTableViewCell>(collection, (model) =>
                    {
                        var cellIndentifier = "";

                        TypeSwitch.On(model)
                        .Case((HeaderListItemViewModel m) => cellIndentifier = HeaderTableViewCell.Key)
                        .Case((ContactListItemViewModel m) => cellIndentifier = ContactTableViewCell.Key);

                        return new NSString(cellIndentifier);
                    }, typeGroup.Key, cell => cell.Initialize());
                }).ToList();
            }).BindTo(_infoTableView));

            yield return(this.WhenAnyValue(v => v._tableSource.ElementSelected)
                         .Subscribe(x =>
            {
                // when ever this value is updated we want to make sure we only ever have
                // the latest subscription
                _serialDisposable.Disposable = x.Subscribe(vm => ViewModel.SelectFeedbackAsync());
            }));

            yield return(this.WhenAnyValue(v => v._infoTableSource.ElementSelected)
                         .Subscribe(x =>
            {
                // when ever this value is updated we want to make sure we only ever have
                // the latest subscription
                _serialDisposable.Disposable = x.Subscribe(vm => ViewModel.SelectContactAsync());
            }));

            yield return(Observable.FromEventPattern <PathUpdateEventArgs>(ViewModel, "PathUpdate")
                         .Window(() => Observable.Interval(TimeSpan.FromSeconds(2)))
                         .SelectMany(x => x.Take(1))
                         .SubscribeOn(ViewModel.Scheduler)
                         .Subscribe(e =>
            {
                var pathArgs = e.EventArgs;

                var latDif = pathArgs.StartCoordinate.Latitude - pathArgs.EndCoordinate.Latitude;
                var lonDif = pathArgs.StartCoordinate.Longitude - pathArgs.EndCoordinate.Longitude;
                var midLat = latDif / 2 + pathArgs.EndCoordinate.Latitude;
                var midLon = lonDif / 2 + pathArgs.EndCoordinate.Longitude;

                double dist = Math.Sqrt(latDif * latDif + lonDif * lonDif) * 90;

                var polyline = new List <CLLocationCoordinate2D>();

                foreach (var pathPoint in pathArgs.Path)
                {
                    polyline.Add(new CLLocationCoordinate2D(pathPoint.Latitude,
                                                            pathPoint.Longitude));
                }

                // Must update the UI on the main thread
                // set map center
                var mapCenter = new CLLocationCoordinate2D(midLat, midLon);
                var mapRegion = MKCoordinateRegion.FromDistance(mapCenter, dist * 2000, dist * 2000);

                // if _mkPolyLine not null, remove then recreate and re add
                if (_mkPolyLine != null)
                {
                    _mapView.RemoveOverlay(_mkPolyLine);
                    _mkPolyLine?.Dispose();
                }

                _mkPolyLine = MKPolyline.FromCoordinates(polyline.ToArray());

                _mapView.CenterCoordinate = mapCenter;
                _mapView.Region = mapRegion;

                // add map overlay for path
                _mapView.AddOverlay(_mkPolyLine);
            }));

            yield return(ViewModel.WhenAnyValue(vm => vm.LocationLoading)
                         .SubscribeOn(ViewModel.Scheduler)
                         .Subscribe(loading =>
            {
                if (loading)
                {
                    _progressView.StartAnimating();
                }
                else
                {
                    _progressView.StopAnimating();
                }
            }));
        }