示例#1
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);
        }
        public void Update()
        {
            MapPos position = Projection.FromWgs84(new MapPos(Longitude, Latitude));

            if (!FoundUser)
            {
                MapView.SetFocusPos(position, 0);
                MapView.SetZoom(17, 0);
                FoundUser = true;
            }

            var builder = new PolygonStyleBuilder();

            builder.Color = LightTransparentAppleBlue;

            var borderBuilder = new LineStyleBuilder();

            borderBuilder.Color = DarkTransparentAppleBlue;
            borderBuilder.Width = 1;

            MapPosVector points = GetCirclePoints(Longitude, Latitude, Accuracy);

            if (accuracyMarker == null)
            {
                accuracyMarker = new Polygon(points, new MapPosVectorVector(), builder.BuildStyle());
                source.Add(accuracyMarker);
            }
            else
            {
                accuracyMarker.Style    = builder.BuildStyle();
                accuracyMarker.Geometry = new PolygonGeometry(points);
            }

            if (userMarker == null)
            {
                var markerBuilder = new PointStyleBuilder();
                markerBuilder.Color = DarkTransparentAppleBlue;
                markerBuilder.Size  = 16.0f;

                userMarker = new Point(position, markerBuilder.BuildStyle());
                source.Add(userMarker);
            }
            else
            {
                userMarker.SetPos(position);
            }
        }
        public void ShowAt(double latitude, double longitude, float accuracy)
        {
            var positiion = projection.FromWgs84(new MapPos(longitude, latitude));

            if (focus)
            {
                map.FocusPos = positiion;
                map.Zoom     = 16;
            }

            var builder = new PolygonStyleBuilder();

            // Light transparent apple blue
            builder.Color = new Carto.Graphics.Color(14, 122, 254, 70);
            var borderBuilder = new LineStyleBuilder();

            // Dark transparent apple blue
            borderBuilder.Color = new Carto.Graphics.Color(14, 122, 254, 150);
            borderBuilder.Width = 1;
            builder.LineStyle   = borderBuilder.BuildStyle();

            var points = GetCirclePoints(latitude, longitude, accuracy);

            if (accuracyMarker == null)
            {
                var holes = new MapPosVectorVector();
                accuracyMarker = new Polygon(points, holes, builder.BuildStyle());
                source.Add(accuracyMarker);
            }
            else
            {
                accuracyMarker.Style    = builder.BuildStyle();
                accuracyMarker.Geometry = new PolygonGeometry(points);
            }

            if (userMarker == null)
            {
                var pointBuilder = new PointStyleBuilder();
                // Apple blue
                pointBuilder.Color = new Carto.Graphics.Color(14, 122, 254, 255);
                pointBuilder.Size  = 16.0f;

                userMarker = new Point(positiion, pointBuilder.BuildStyle());
                source.Add(userMarker);
            }
        }
        public static void AddPolygon(this LocalVectorDataSource source, MapPosVector positions)
        {
            PolygonStyleBuilder builder = new PolygonStyleBuilder();

            builder.Color = new Color(0, 255, 0, 255);

            Polygon polygon = new Polygon(positions, builder.BuildStyle());

            source.Add(polygon);
        }
示例#5
0
        public static void Add2DPolygon(LocalVectorDataSource source, Projection projection)
        {
            LineStyleBuilder lineBuilder = new LineStyleBuilder();

            lineBuilder.Color = new Color(0, 0, 0, 255);             // Black
            lineBuilder.Width = 1.0f;

            // Create polygon style and poses
            PolygonStyleBuilder polygonBuilder = new PolygonStyleBuilder();

            polygonBuilder.Color     = new Color(255, 0, 0, 255);         // Red
            polygonBuilder.LineStyle = lineBuilder.BuildStyle();

            MapPosVector polygonPoses = new MapPosVector();

            polygonPoses.Add(projection.FromWgs84(new MapPos(24.650930, 59.421659)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.657453, 59.416354)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.661187, 59.414607)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.667667, 59.418123)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.665736, 59.421703)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.661444, 59.421245)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.660199, 59.420677)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.656552, 59.420175)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.654010, 59.421472)));

            // Create 2 polygon holes
            MapPosVector holePoses1 = new MapPosVector();

            holePoses1.Add(projection.FromWgs84(new MapPos(24.658409, 59.420522)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.662207, 59.418896)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.662207, 59.417411)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.659524, 59.417171)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.657615, 59.419834)));

            MapPosVector holePoses2 = new MapPosVector();

            holePoses2.Add(projection.FromWgs84(new MapPos(24.665640, 59.421243)));
            holePoses2.Add(projection.FromWgs84(new MapPos(24.668923, 59.419463)));
            holePoses2.Add(projection.FromWgs84(new MapPos(24.662893, 59.419365)));

            MapPosVectorVector polygonHoles = new MapPosVectorVector();

            polygonHoles.Add(holePoses1);
            polygonHoles.Add(holePoses2);

            // Add polygon
            Polygon polygon = new Polygon(polygonPoses, polygonHoles, polygonBuilder.BuildStyle());

            polygon.SetMetaDataElement("ClickText", new Variant("Polygon"));
            source.Add(polygon);
        }
示例#6
0
        public static void Add2DPolygon(LocalVectorDataSource source, Projection projection)
        {
            LineStyleBuilder lineBuilder = new LineStyleBuilder();
            lineBuilder.Color = new Color(0, 0, 0, 255); // Black
            lineBuilder.Width = 1.0f;

            // Create polygon style and poses
            PolygonStyleBuilder polygonBuilder = new PolygonStyleBuilder();
            polygonBuilder.Color = new Color(255, 0, 0, 255); // Red
            polygonBuilder.LineStyle = lineBuilder.BuildStyle();

            MapPosVector polygonPoses = new MapPosVector();
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.650930, 59.421659)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.657453, 59.416354)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.661187, 59.414607)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.667667, 59.418123)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.665736, 59.421703)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.661444, 59.421245)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.660199, 59.420677)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.656552, 59.420175)));
            polygonPoses.Add(projection.FromWgs84(new MapPos(24.654010, 59.421472)));

            // Create 2 polygon holes
            MapPosVector holePoses1 = new MapPosVector();
            holePoses1.Add(projection.FromWgs84(new MapPos(24.658409, 59.420522)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.662207, 59.418896)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.662207, 59.417411)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.659524, 59.417171)));
            holePoses1.Add(projection.FromWgs84(new MapPos(24.657615, 59.419834)));

            MapPosVector holePoses2 = new MapPosVector();
            holePoses2.Add(projection.FromWgs84(new MapPos(24.665640, 59.421243)));
            holePoses2.Add(projection.FromWgs84(new MapPos(24.668923, 59.419463)));
            holePoses2.Add(projection.FromWgs84(new MapPos(24.662893, 59.419365)));

            MapPosVectorVector polygonHoles = new MapPosVectorVector();
            polygonHoles.Add(holePoses1);
            polygonHoles.Add(holePoses2);

            // Add polygon
            Polygon polygon = new Polygon(polygonPoses, polygonHoles, polygonBuilder.BuildStyle());
            polygon.SetMetaDataElement("ClickText", new Variant("Polygon"));
            source.Add(polygon);
        }
        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);
        }
示例#9
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);
        }