Beispiel #1
0
        public override bool OnUTFGridClicked(UTFGridClickInfo clickInfo)
        {
            if (vectorDataSource == null)
            {
                vectorDataSource = (LocalVectorDataSource)vectorLayer.DataSource;
            }

            // Clear previous popups
            vectorDataSource.Clear();

            // Multiple vector elements can be clicked at the same time, we only care about the one
            // Check the type of vector element
            BalloonPopup             clickPopup   = null;
            BalloonPopupStyleBuilder styleBuilder = new BalloonPopupStyleBuilder();

            // Configure style
            styleBuilder.LeftMargins  = new BalloonPopupMargins(0, 0, 0, 0);
            styleBuilder.TitleMargins = new BalloonPopupMargins(6, 3, 6, 3);

            // Make sure this label is shown on top all other labels
            styleBuilder.PlacementPriority = 10;

            // Show clicked element variant as JSON string
            string desc = clickInfo.ElementInfo.ToString();

            clickPopup = new BalloonPopup(clickInfo.ClickPos, styleBuilder.BuildStyle(), "", desc);

            vectorDataSource.Add(clickPopup);

            return(true);
        }
Beispiel #2
0
        public override bool OnVectorTileClicked(VectorTileClickInfo clickInfo)
        {
            LocalVectorDataSource source = (LocalVectorDataSource)layer.DataSource;

            source.Clear();

            Color color = new Color(0, 100, 200, 150);

            Feature  feature  = clickInfo.Feature;
            Geometry geometry = feature.Geometry;

            PointStyleBuilder pointBuilder = new PointStyleBuilder();

            pointBuilder.Color = color;

            LineStyleBuilder lineBuilder = new LineStyleBuilder();

            lineBuilder.Color = color;

            PolygonStyleBuilder polygonBuilder = new PolygonStyleBuilder();

            polygonBuilder.Color = color;

            if (geometry is PointGeometry)
            {
                source.Add(new Point((PointGeometry)geometry, pointBuilder.BuildStyle()));
            }
            else if (geometry is LineGeometry)
            {
                source.Add(new Line((LineGeometry)geometry, lineBuilder.BuildStyle()));
            }
            else if (geometry is PolygonGeometry)
            {
                source.Add(new Polygon((PolygonGeometry)geometry, polygonBuilder.BuildStyle()));
            }
            else if (geometry is MultiGeometry)
            {
                GeometryCollectionStyleBuilder collectionBuilder = new GeometryCollectionStyleBuilder();
                collectionBuilder.PointStyle   = pointBuilder.BuildStyle();
                collectionBuilder.LineStyle    = lineBuilder.BuildStyle();
                collectionBuilder.PolygonStyle = polygonBuilder.BuildStyle();

                source.Add(new GeometryCollection((MultiGeometry)geometry, collectionBuilder.BuildStyle()));
            }

            BalloonPopupStyleBuilder builder = new BalloonPopupStyleBuilder();

            /// Set a higher placement priority so it would always be visible
            builder.PlacementPriority = 10;

            string message = feature.Properties.ToString();

            BalloonPopup popup = new BalloonPopup(clickInfo.ClickPos, builder.BuildStyle(), "Click", message);

            source.Add(popup);

            return(true);
        }
Beispiel #3
0
        public void Show(RoutingResult result, Color lineColor)
        {
            routeDataSource.Clear();

            startMarker.Visible = false;

            Line line = CreatePolyline(startMarker.Geometry.CenterPos, stopMarker.Geometry.CenterPos, result, lineColor);

            routeDataSource.Add(line);

            // Add instruction markers
            RoutingInstructionVector instructions = result.Instructions;

            for (int i = 0; i < instructions.Count; i++)
            {
                RoutingInstruction instruction = instructions[i];
                MapPos             position    = result.Points[instruction.PointIndex];
                CreateRoutePoint(position, instruction, routeDataSource);
            }
        }
Beispiel #4
0
        public void Show(RoutingResult result)
        {
            routeDataSource.Clear();
            routeInstructionSource.Clear();

            var  color = new Color(0, 122, 255, 225);
            Line line  = CreatePolyline(result, color);

            routeDataSource.Add(line);

            // Add instruction markers
            RoutingInstructionVector instructions = result.Instructions;

            if (ShowTurns)
            {
                for (int i = 0; i < instructions.Count; i++)
                {
                    RoutingInstruction instruction = instructions[i];
                    MapPos             position    = result.Points[instruction.PointIndex];
                    CreateRoutePoint(position, instruction, routeInstructionSource);
                }
            }
        }
Beispiel #5
0
        public void ShowRoute(MapPos startPos, MapPos stopPos)
        {
            Log.Debug("calculating path " + startPos + " to " + stopPos);

            if (!offlinePackageReady)
            {
                RunOnUiThread(() =>
                {
                    string message = "Offline package is not ready, using online routing";
                    Toast.MakeText(ApplicationContext, message, ToastLength.Long).Show();
                });
            }

            if (!shortestPathRunning)
            {
                shortestPathRunning = true;
                long timeStart;

                // run routing in background
                Task.Run(() =>
                {
                    timeStart          = Java.Lang.JavaSystem.CurrentTimeMillis();
                    MapPosVector poses = new MapPosVector();

                    poses.Add(startPos);
                    poses.Add(stopPos);

                    RoutingRequest request = new RoutingRequest(BaseProjection, poses);
                    RoutingResult result;

                    if (offlinePackageReady)
                    {
                        result = offlineRoutingService.CalculateRoute(request);
                    }
                    else
                    {
                        result = onlineRoutingService.CalculateRoute(request);
                    }

                    // Now update response in UI thread
                    RunOnUiThread(() =>
                    {
                        if (result == null)
                        {
                            Alert("Routing failed");
                            shortestPathRunning = false;
                            return;
                        }

                        string distance    = "The route is " + (int)(result.TotalDistance / 100) / 10f + "km";
                        string time        = "(" + result.TotalTime.ConvertFromSecondsToHours() + ")";
                        string calculation = "| Calculation: " + (Java.Lang.JavaSystem.CurrentTimeMillis() - timeStart) + " ms";

                        Alert(distance + time + calculation);

                        routeDataSource.Clear();

                        startMarker.Visible = false;

                        Line line = CreatePolyline(startMarker.Geometry.CenterPos, stopMarker.Geometry.CenterPos, result);
                        routeDataSource.Add(line);

                        // Add instruction markers
                        RoutingInstructionVector instructions = result.Instructions;

                        for (int i = 0; i < instructions.Count; i++)
                        {
                            RoutingInstruction instruction = instructions[i];
                            MapPos position = result.Points[instruction.PointIndex];
                            CreateRoutePoint(position, instruction, routeDataSource);
                        }

                        shortestPathRunning = false;
                    });
                });
            }
        }
        public static void ShowResult(this LocalVectorDataSource source, MapView map, GeocodingResult result, string title, string description, bool goToPosition)
        {
            source.Clear();

            var builder = new BalloonPopupStyleBuilder();

            builder.LeftMargins  = new BalloonPopupMargins(0, 0, 0, 0);
            builder.TitleMargins = new BalloonPopupMargins(6, 3, 6, 3);
            builder.CornerRadius = 5;
            // Make sure this label is shown on top of all other labels
            builder.PlacementPriority = 10;

            FeatureCollection collection = result.FeatureCollection;
            int count = collection.FeatureCount;

            MapPos   position = new MapPos();
            Geometry geometry;

            for (int i = 0; i < count; i++)
            {
                geometry = collection.GetFeature(i).Geometry;
                var color = new Carto.Graphics.Color(0, 100, 200, 150);

                var pointBuilder = new PointStyleBuilder();
                pointBuilder.Color = color;

                var lineBuilder = new LineStyleBuilder();
                lineBuilder.Color = color;

                var polygonBuilder = new PolygonStyleBuilder();
                polygonBuilder.Color = color;

                VectorElement element = null;

                if (geometry is PointGeometry)
                {
                    element = new Point(geometry as PointGeometry, pointBuilder.BuildStyle());
                }
                else if (geometry is LineGeometry)
                {
                    element = new Line(geometry as LineGeometry, lineBuilder.BuildStyle());
                }
                else if (geometry is PolygonGeometry)
                {
                    element = new Polygon(geometry as PolygonGeometry, polygonBuilder.BuildStyle());
                }
                else if (geometry is MultiGeometry)
                {
                    var collectionBuilder = new GeometryCollectionStyleBuilder();
                    collectionBuilder.PointStyle   = pointBuilder.BuildStyle();
                    collectionBuilder.LineStyle    = lineBuilder.BuildStyle();
                    collectionBuilder.PolygonStyle = polygonBuilder.BuildStyle();

                    element = new GeometryCollection(geometry as MultiGeometry, collectionBuilder.BuildStyle());
                }

                if (element != null)
                {
                    position = geometry.CenterPos;
                    source.Add(element);
                }
            }

            if (goToPosition)
            {
                map.SetFocusPos(position, 1.0f);
                map.SetZoom(16, 1.0f);
            }

            var popup = new BalloonPopup(position, builder.BuildStyle(), title, description);

            source.Add(popup);
        }
        public override bool OnVectorTileClicked(Carto.Ui.VectorTileClickInfo clickInfo)
        {
            source.Clear();

            Color color = new Color(0, 100, 200, 150);

            Feature  feature  = clickInfo.Feature;
            Geometry geometry = feature.Geometry;

            PointStyleBuilder pointBuilder = new PointStyleBuilder();

            pointBuilder.Color = color;

            LineStyleBuilder lineBuilder = new LineStyleBuilder();

            lineBuilder.Color = color;

            PolygonStyleBuilder polygonBuilder = new PolygonStyleBuilder();

            polygonBuilder.Color = color;

            if (geometry is PointGeometry)
            {
                source.Add(new Point((PointGeometry)geometry, pointBuilder.BuildStyle()));
            }
            else if (geometry is LineGeometry)
            {
                source.Add(new Line((LineGeometry)geometry, lineBuilder.BuildStyle()));
            }
            else if (geometry is PolygonGeometry)
            {
                source.Add(new Polygon((PolygonGeometry)geometry, polygonBuilder.BuildStyle()));
            }
            else if (geometry is MultiGeometry)
            {
                GeometryCollectionStyleBuilder collectionBuilder = new GeometryCollectionStyleBuilder();
                collectionBuilder.PointStyle   = pointBuilder.BuildStyle();
                collectionBuilder.LineStyle    = lineBuilder.BuildStyle();
                collectionBuilder.PolygonStyle = polygonBuilder.BuildStyle();

                source.Add(new GeometryCollection((MultiGeometry)geometry, collectionBuilder.BuildStyle()));
            }

            BalloonPopupStyleBuilder builder = new BalloonPopupStyleBuilder();

            // Set a higher placement priority so it would always be visible
            builder.PlacementPriority = 10;

            string id = clickInfo.FeatureId.ToString();

            string name = "Info (id: " + id + ")";

            if (feature.Properties.GetObjectElement("name").String != "null")
            {
                name += " about " + feature.Properties.GetObjectElement("name").String;
            }

            string description = feature.Properties.ToString();

            BalloonPopup popup = new BalloonPopup(clickInfo.ClickPos, builder.BuildStyle(), name, description);

            source.Add(popup);

            return(true);
        }
Beispiel #8
0
 public void ClearPopups()
 {
     popupSource.Clear();
 }
        public void ShowRoute(MapPos startPos, MapPos stopPos)
        {
            Log.Debug("calculating path " + startPos + " to " + stopPos);

            if (!offlinePackageReady)
            {
                InvokeOnMainThread(() =>
                {
                    string message = "Offline package is not ready. Using online routing";
                    Alert(message);
                });
            }

            if (!shortestPathRunning)
            {
                shortestPathRunning = true;
                long timeStart;

                // run routing in background
                System.Threading.Tasks.Task.Run(delegate
                {
                    timeStart          = DateTime.Now.ToUnixTime();
                    MapPosVector poses = new MapPosVector {
                        startPos, stopPos
                    };

                    RoutingRequest request = new RoutingRequest(BaseProjection, poses);
                    RoutingResult result;

                    if (offlinePackageReady)
                    {
                        result = offlineRoutingService.CalculateRoute(request);
                    }
                    else
                    {
                        result = onlineRoutingService.CalculateRoute(request);
                    }

                    // Now update response in UI thread
                    InvokeOnMainThread(delegate
                    {
                        if (result == null)
                        {
                            Alert("Routing failed");
                            shortestPathRunning = false;
                            return;
                        }

                        routeDataSource.Clear();

                        startMarker.Visible = false;

                        Line line = CreatePolyline(startMarker.Geometry.CenterPos, stopMarker.Geometry.CenterPos, result);
                        routeDataSource.Add(line);

                        // Add instruction markers
                        RoutingInstructionVector instructions = result.Instructions;

                        for (int i = 0; i < instructions.Count; i++)
                        {
                            RoutingInstruction instruction = instructions[i];
                            MapPos position = result.Points[instruction.PointIndex];
                            CreateRoutePoint(position, instruction, routeDataSource);
                        }

                        string distance    = "The route is " + (int)(result.TotalDistance / 100) / 10f + "km";
                        string time        = " (" + result.TotalTime.ConvertFromSecondsToHours() + ") ";
                        string calculation = "| Calculation: " + (DateTime.Now.ToUnixTime() - timeStart) + " ms";

                        Alert(distance + time + calculation);

                        shortestPathRunning = false;
                    });
                });
            }
        }
Beispiel #10
0
        public override bool OnVectorTileClicked(VectorTileClickInfo clickInfo)
        {
            LocalVectorDataSource source = (LocalVectorDataSource)layer.DataSource;

            source.Clear();

            Color color = new Color(0, 100, 200, 150);

            Feature  feature  = clickInfo.Feature;
            Geometry geometry = feature.Geometry;

            PointStyleBuilder pointBuilder = new PointStyleBuilder();

            pointBuilder.Color = color;

            LineStyleBuilder lineBuilder = new LineStyleBuilder();

            lineBuilder.Color = color;

            PolygonStyleBuilder polygonBuilder = new PolygonStyleBuilder();

            polygonBuilder.Color = color;

            if (geometry is PointGeometry)
            {
                source.Add(new Point((PointGeometry)geometry, pointBuilder.BuildStyle()));
            }
            else if (geometry is LineGeometry)
            {
                source.Add(new Line((LineGeometry)geometry, lineBuilder.BuildStyle()));
            }
            else if (geometry is PolygonGeometry)
            {
                source.Add(new Polygon((PolygonGeometry)geometry, polygonBuilder.BuildStyle()));
            }
            else if (geometry is MultiGeometry)
            {
                GeometryCollectionStyleBuilder collectionBuilder = new GeometryCollectionStyleBuilder();
                collectionBuilder.PointStyle   = pointBuilder.BuildStyle();
                collectionBuilder.LineStyle    = lineBuilder.BuildStyle();
                collectionBuilder.PolygonStyle = polygonBuilder.BuildStyle();

                source.Add(new GeometryCollection((MultiGeometry)geometry, collectionBuilder.BuildStyle()));
            }

            BalloonPopupStyleBuilder builder = new BalloonPopupStyleBuilder();

            // Set a higher placement priority so it would always be visible
            builder.PlacementPriority = 10;

            string id          = clickInfo.FeatureId.ToString();
            string message     = "(Id: " + id + ") ";
            string name        = feature.Properties.GetObjectElement("name").String;
            string description = feature.Properties.GetObjectElement("description").String.ToMax200Characters();

            if (name.Equals("null"))
            {
                string facility = feature.Properties.GetObjectElement("facility").String;

                if (!facility.Equals("null"))
                {
                    message += facility;
                }
                else
                {
                    message += feature.Properties.ToString();
                }
            }
            else
            {
                message += name;

                if (!description.Equals("null"))
                {
                    message += "\n" + description;
                }
            }

            BalloonPopup popup = new BalloonPopup(clickInfo.ClickPos, builder.BuildStyle(), "", message);

            source.Add(popup);

            if (IsForce)
            {
                Console.WriteLine("Force touch");
                return(false);
            }

            Console.WriteLine("Non-force");
            return(true);
        }