protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AddBaseLayer(CartoBaseMapStyle.CartoBasemapStyleGray);

            // You need to change these according to your DB
            string sql      = "select * from table_46g";
            string cartoCSS = "#table_46g {raster-opacity: 0.5;}";

            string config = JsonUtils.GetRasterLayerConfigJson(sql, cartoCSS).ToString();

            // Use the Maps service to configure layers. Note that this must be done
            // in a separate thread on Android, as Maps API requires connecting to server
            // which is not allowed in main thread.

            CartoMapsService mapsService = new CartoMapsService();

            mapsService.Username = "******";

            // Use raster layers, not vector layers
            mapsService.DefaultVectorLayerMode = false;

            System.Threading.Tasks.Task.Run(delegate
            {
                try
                {
                    LayerVector layers = mapsService.BuildMap(Variant.FromString(config));
                    for (int i = 0; i < layers.Count; i++)
                    {
                        MapView.Layers.Add(layers[i]);
                    }
                }
                catch (IOException e)
                {
                    Carto.Utils.Log.Debug("EXCEPTION: Exception: " + e);
                }
            });

            // Zoom map to the content area
            MapPos hiiumaa = BaseProjection.FromWgs84(new MapPos(22.7478235498916, 58.8330577553785));

            MapView.SetFocusPos(hiiumaa, 0);
            MapView.SetZoom(11, 0);
        }
示例#2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AddOnlineBaseLayer(CartoBaseMapStyle.CartoBasemapStyleGray);

            // You need to change these according to your DB
            string sql      = "select * from table_46g";
            string cartoCSS = "#table_46g { raster-opacity: 0.5; }";
            string config   = JsonUtils.GetRasterLayerConfigJson(sql, cartoCSS).ToString();

            CartoMapsService mapsService = new CartoMapsService();

            mapsService.Username = "******";

            // Use raster layers, not vector layers
            mapsService.DefaultVectorLayerMode = false;

            // Use the Maps service to configure layers.
            // Note that Maps API requires connecting to server,
            // which shouldn't be done on the main thread

            InvokeInBackground(delegate
            {
                try
                {
                    LayerVector layers = mapsService.BuildMap(Variant.FromString(config));
                    for (int i = 0; i < layers.Count; i++)
                    {
                        MapView.Layers.Add(layers[i]);
                    }
                }
                catch (IOException e)
                {
                    Carto.Utils.Log.Debug("EXCEPTION: Exception: " + e);
                }
            });

            // Zoom map to the content area
            MapPos hiiumaa = BaseProjection.FromWgs84(new MapPos(22.7478235498916, 58.8330577553785));

            MapView.SetFocusPos(hiiumaa, 0);
            MapView.SetZoom(10, 0);
        }
        public static void ConfigureUTFGridLayers(MapView MapView, JsonValue config)
        {
            // Use the Maps service to configure layers.
            // Note that this must be done in a separate thread on Android,
            // as Maps API requires connecting to server which is not nice to do in main thread.

            System.Threading.Tasks.Task.Run(delegate
            {
                CartoMapsService service = new CartoMapsService();
                service.Username         = "******";

                // Use VectorLayers
                service.DefaultVectorLayerMode = true;
                service.Interactive            = true;

                try
                {
                    LayerVector layers = service.BuildMap(Variant.FromString(config.ToString()));

                    LocalVectorDataSource overlaySource = new LocalVectorDataSource(MapView.Options.BaseProjection);
                    VectorLayer overlayLayer            = new VectorLayer(overlaySource);

                    MapView.Layers.Add(overlayLayer);

                    for (int i = 0; i < layers.Count; i++)
                    {
                        TileLayer layer = (TileLayer)layers[i];

                        MyUTFGridEventListener lisener = new MyUTFGridEventListener(overlaySource);
                        layer.UTFGridEventListener     = lisener;

                        MapView.Layers.Add(layer);
                    }
                }
                catch (Exception e)
                {
                    Carto.Utils.Log.Debug("UTFGrid Exception: " + e.Message);
                }
            });
        }
示例#4
0
        public static void ConfigureAnonymousVectorLayers(this MapView map, JsonValue config)
        {
            // Use the Maps service to configure layers.
            // Note that this must be done in a separate thread on Android,
            // as Maps API requires connecting to server which is not nice to do in main thread.

            System.Threading.Tasks.Task.Run(delegate
            {
                CartoMapsService service = new CartoMapsService();
                service.Username         = "******";

                // Use VectorLayers
                service.DefaultVectorLayerMode = true;
                service.Interactive            = true;

                LayerVector layers = service.BuildMap(Variant.FromString(config.ToString()));

                for (int i = 0; i < layers.Count; i++)
                {
                    map.Layers.Add(layers[i]);
                }
            });
        }
        public static void ConfigureAnonymousVectorLayers(this MapView map, JsonValue config)
        {
            // Use the Maps service to configure layers.
            // Note that this must be done in a separate thread on Android,
            // as Maps API requires connecting to server which is not nice to do in main thread.

            System.Threading.Tasks.Task.Run(delegate
            {
                CartoMapsService service = new CartoMapsService();
                service.Username = "******";

                // Use VectorLayers
                service.DefaultVectorLayerMode = true;
                service.Interactive = true;

                LayerVector layers = service.BuildMap(Variant.FromString(config.ToString()));

                for (int i = 0; i < layers.Count; i++)
                {
                    map.Layers.Add(layers[i]);
                }
            });
        }