示例#1
0
        private static void DrawPolygons()
        {
            MapEvent(null, new MapEventArgs(0, 100, "Calling polygons..."));
            var polygons     = d.getObjects(day, 3);
            var overlayLayer = new VectorLayer(dataSourcePolygons);

            overlayLayer.VisibleZoomRange = new MapRange(16, 24);
            mapView.Layers.Add(overlayLayer);
            VectorElementVector v     = new VectorElementVector();
            VectorElementVector vText = new VectorElementVector();
            int i = 0;

            foreach (var obj in polygons)
            {
                //Define coordinates of outer ring
                MapPosVector polygonPoses = new MapPosVector();
                foreach (var pnt in obj.polygonList.coordinates[0])
                {
                    polygonPoses.Add(projection.FromWgs84(new MapPos(pnt[0], pnt[1])));
                }
                Polygon polygon = new Polygon(polygonPoses, Styles.GetDefaultPolygonStyle().BuildStyle());
                v.Add(polygon);
                if (i == 0)
                {
                    mapView.FocusPos = projection.FromWgs84(new MapPos(obj.polygonList.coordinates[0][0][0], obj.polygonList.coordinates[0][0][1]));
                }
                MapEvent(null, new MapEventArgs(i, polygons.Count, "Drawing polygons..."));
                i++;
            }
            dataSourcePolygons.RemoveAll(dataSourcePolygons.GetAll());
            dataSourcePolygons.AddAll(v);
        }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStylePositron);

            // read json from assets and add to map
            string json;

            using (System.IO.StreamReader sr = new System.IO.StreamReader(Assets.Open("cities15000.geojson")))
            {
                json = sr.ReadToEnd();
            }

            // Initialize a local vector data source
            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            ClusteredVectorLayer layer = new ClusteredVectorLayer(source, new MyClusterElementBuilder(this));

            layer.MinimumClusterDistance = 50;

            new System.Threading.Thread((obj) =>
            {
                // Create a basic style, as the ClusterElementBuilder will set the real style
                var markerStyleBuilder  = new MarkerStyleBuilder();
                markerStyleBuilder.Size = 14;
                MarkerStyle style       = markerStyleBuilder.BuildStyle();

                // Read GeoJSON, parse it using SDK GeoJSON parser
                GeoJSONGeometryReader reader = new GeoJSONGeometryReader();

                // Set target projection to base (mercator)
                reader.TargetProjection = BaseProjection;
                Alert("Starting load from .geojson");

                // Read features from local asset
                FeatureCollection features = reader.ReadFeatureCollection(json);
                Alert("Finished load from .geojson");

                VectorElementVector elements = new VectorElementVector();

                for (int i = 0; i < features.FeatureCount; i++)
                {
                    // This data set features point geometry,
                    // however, it can also be LineGeometry or PolygonGeometry
                    PointGeometry geometry = (PointGeometry)features.GetFeature(i).Geometry;
                    elements.Add(new Marker(geometry, style));
                }

                source.AddAll(elements);
                Alert("Clustering started. Please wait...");

                // Add the clustered vector layer to the map
                MapView.Layers.Add(layer);
            }).Start();
        }
示例#3
0
        private static void DrawForests()
        {
            MapEvent(null, new MapEventArgs(0, 100, "Calling type landuse forest ..."));
            var forests      = d.getObjects(day, 3, 472);
            var overlayLayer = new VectorLayer(dataSourceForests);

            overlayLayer.VisibleZoomRange = new MapRange(6, 24);
            mapView.Layers.Add(overlayLayer);
            var overlayLayerText = new VectorLayer(dataSourceForestsText);

            overlayLayerText.VisibleZoomRange = new MapRange(17, 24);
            mapView.Layers.Add(overlayLayerText);
            VectorElementVector v     = new VectorElementVector();
            VectorElementVector vText = new VectorElementVector();
            int i = 0;

            foreach (var obj in forests)
            {
                //Define coordinates of outer ring
                MapPosVector polygonPoses = new MapPosVector();
                foreach (var pnt in obj.polygonList.coordinates[0])
                {
                    polygonPoses.Add(projection.FromWgs84(new MapPos(pnt[0], pnt[1])));
                }
                Polygon polygon = new Polygon(polygonPoses, Styles.GetDefaultForestStyle().BuildStyle());
                //polygon.SetMetaDataElement("ClickText", obj.name);
                v.Add(polygon);
                if (i == 0)
                {
                    mapView.FocusPos = projection.FromWgs84(new MapPos(obj.polygonList.coordinates[0][0][0], obj.polygonList.coordinates[0][0][1]));
                }
                var textpopup1 = new Text(projection.FromWgs84(new MapPos(obj.polygonList.coordinates[0][0][0], obj.polygonList.coordinates[0][0][1])),
                                          Styles.GetDefaultTextStyle().BuildStyle(),
                                          obj.name);
                vText.Add(textpopup1);
                MapEvent(null, new MapEventArgs(i, forests.Count, "Drawing Type landuse forest..."));
                i++;
            }
            dataSourceForests.RemoveAll(dataSourceForests.GetAll());
            dataSourceForests.AddAll(v);
            dataSourceForestsText.RemoveAll(dataSourceForestsText.GetAll());
            dataSourceForestsText.AddAll(vText);
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // Add default base layer
            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStylePositron);

            // Initialize a local vector data source
            LocalVectorDataSource source = new LocalVectorDataSource(BaseProjection);

            // Initialize a vector layer with the previous data source
            var layer = new ClusteredVectorLayer(source, new MyClusterElementBuilder());

            // Default is 100. A good value depends on data
            layer.MinimumClusterDistance = 50;

            // read json from assets and add to map
            string json = System.IO.File.ReadAllText(AssetUtils.CalculateResourcePath("cities15000.geojson"));

            // Create a basic style, as the ClusterElementBuilder will set the real style
            var markerStyleBuilder = new MarkerStyleBuilder();

            markerStyleBuilder.Size = 14;
            MarkerStyle style = markerStyleBuilder.BuildStyle();

            // Read GeoJSON, parse it using SDK GeoJSON parser
            GeoJSONGeometryReader reader = new GeoJSONGeometryReader();

            // Set target projection to base (mercator)
            reader.TargetProjection = BaseProjection;

            // Read features from local asset
            FeatureCollection features = reader.ReadFeatureCollection(json);

            VectorElementVector elements = new VectorElementVector();

            for (int i = 0; i < features.FeatureCount; i++)
            {
                // This data set features point geometry,
                // however, it can also be LineGeometry or PolygonGeometry
                PointGeometry geometry = (PointGeometry)features.GetFeature(i).Geometry;
                elements.Add(new Marker(geometry, style));
            }

            // Add the clustered vector layer to the map
            source.AddAll(elements);

            MapView.Layers.Add(layer);
        }
示例#5
0
        private static void DrawTrunks()
        {
            MapEvent(null, new MapEventArgs(0, 100, "Calling type trunk..."));
            var trunks       = d.getObjects(day, 2, 557);
            var overlayLayer = new VectorLayer(dataSourceTrunks);

            overlayLayer.VisibleZoomRange = new MapRange(6, 24);
            mapView.Layers.Add(overlayLayer);
            var overlayLayer2 = new VectorLayer(dataSourceTrunks2);

            overlayLayer2.VisibleZoomRange = new MapRange(9, 24);
            mapView.Layers.Add(overlayLayer2);
            var overlayLayerText = new VectorLayer(dataSourceTrunksText);

            overlayLayerText.VisibleZoomRange = new MapRange(17, 24);
            mapView.Layers.Add(overlayLayerText);
            VectorElementVector v     = new VectorElementVector();
            VectorElementVector v2    = new VectorElementVector();
            VectorElementVector vText = new VectorElementVector();

            mapView.FocusPos = projection.FromWgs84(new MapPos(trunks[0].lineList.coordinates[0][0], trunks[0].lineList.coordinates[0][1]));
            int i = 0;

            foreach (var obj in trunks)
            {
                var linePoses = new MapPosVector();
                foreach (var pnt in obj.lineList.coordinates)
                {
                    linePoses.Add(projection.FromWgs84(new MapPos(pnt[0], pnt[1])));
                }
                var line = new Line(linePoses, Styles.GetTrunkStyle1().BuildStyle());
                v.Add(line);
                var line2 = new Line(linePoses, Styles.GetTrunkStyle2().BuildStyle());
                v2.Add(line2);
                var textpopup1 = new Text(projection.FromWgs84(new MapPos(obj.lineList.coordinates[0][0], obj.lineList.coordinates[0][1])),
                                          Styles.GetDefaultTextStyle().BuildStyle(),
                                          obj.name);
                vText.Add(textpopup1);
                MapEvent(null, new MapEventArgs(i, trunks.Count, "Drawing type trunk..."));
                i++;
            }
            dataSourceTrunks.RemoveAll(dataSourceTrunks.GetAll());
            dataSourceTrunks.AddAll(v);
            dataSourceTrunks2.RemoveAll(dataSourceTrunks2.GetAll());
            dataSourceTrunks2.AddAll(v2);
            dataSourceTrunksText.RemoveAll(dataSourceTrunksText.GetAll());
            dataSourceTrunksText.AddAll(vText);
        }
示例#6
0
        private static void DrawPoints()
        {
            //MessageBox content to be rendered
            MapEvent(null, new MapEventArgs(0, 100, "Calling points"));
            //Objects are pulled from SQLite database
            var points = d.getObjects(day, 1);
            //Layers and the ZoomLevels where they should be visible are created (Zoomlevels range from 0 to 24)
            var overlayLayer = new VectorLayer(dataSourcePoints);

            overlayLayer.VisibleZoomRange = new MapRange(17, 24);
            mapView.Layers.Add(overlayLayer);
            var overlayLayerText = new VectorLayer(dataSourcePointsText);

            overlayLayerText.VisibleZoomRange = new MapRange(17, 24);
            mapView.Layers.Add(overlayLayerText);
            VectorElementVector v     = new VectorElementVector();
            VectorElementVector vText = new VectorElementVector();

            mapView.FocusPos = projection.FromWgs84(new MapPos(points[0].pointList.coordinates[0],
                                                               points[0].pointList.coordinates[1]));
            int i = 0;

            //Objects are drawn on layer
            foreach (var obj in points)
            {
                if (i > 500)
                {
                    continue;
                }
                var pt = new Point(
                    projection.FromWgs84(new MapPos(obj.pointList.coordinates[0],
                                                    obj.pointList.coordinates[1])), Styles.GetDefaultPointStyle().BuildStyle());
                v.Add(pt);
                var textpopup1 = new Text(
                    projection.FromWgs84(new MapPos(obj.pointList.coordinates[0], obj.pointList.coordinates[1])),
                    Styles.GetDefaultTextStyle().BuildStyle(),
                    obj.name);
                vText.Add(textpopup1);
                MapEvent(null, new MapEventArgs(i, points.Count, "Drawing points"));
                i++;
            }
            //Layers are cleared of old data and written with new data
            dataSourcePoints.RemoveAll(dataSourcePoints.GetAll());
            dataSourcePoints.AddAll(v);
            dataSourcePointsText.RemoveAll(dataSourcePointsText.GetAll());
            dataSourcePointsText.AddAll(vText);
        }
示例#7
0
        private static void DrawRivers()
        {
            MapEvent(null, new MapEventArgs(0, 100, "Calling type waterway river..."));
            var rivers       = d.getObjects(day, 2, 744);
            var overlayLayer = new VectorLayer(dataSourceRivers);

            overlayLayer.VisibleZoomRange = new MapRange(9, 24);
            mapView.Layers.Add(overlayLayer);
            var overlayLayerText = new VectorLayer(dataSourceRiversText);

            overlayLayerText.VisibleZoomRange = new MapRange(17, 24);
            mapView.Layers.Add(overlayLayerText);
            VectorElementVector v     = new VectorElementVector();
            VectorElementVector vText = new VectorElementVector();
            int i = 0;

            foreach (var obj in rivers)
            {
                var linePoses = new MapPosVector();
                foreach (var pnt in obj.lineList.coordinates)
                {
                    linePoses.Add(projection.FromWgs84(new MapPos(pnt[0], pnt[1])));
                }
                var line = new Line(linePoses, Styles.GetRiverStyle().BuildStyle());
                v.Add(line);
                if (i == 0)
                {
                    mapView.FocusPos = projection.FromWgs84(new MapPos(obj.lineList.coordinates[0][0], obj.lineList.coordinates[0][1]));
                }
                var textpopup1 = new Text(projection.FromWgs84(new MapPos(obj.lineList.coordinates[0][0], obj.lineList.coordinates[0][1])),
                                          Styles.GetDefaultTextStyle().BuildStyle(),
                                          obj.name);
                vText.Add(textpopup1);
                MapEvent(null, new MapEventArgs(i, rivers.Count, "Drawing type waterway river..."));
                i++;
            }
            dataSourceRivers.RemoveAll(dataSourceRivers.GetAll());
            dataSourceRivers.AddAll(v);
            dataSourceRiversText.RemoveAll(dataSourceRiversText.GetAll());
            dataSourceRiversText.AddAll(vText);
        }