Example #1
0
        public static void InitializeMapsService(this MapView map, string username, string mapname, bool isVector, Action success = null)
        {
            CartoMapsService service = new CartoMapsService();

            service.Username = username;

            service.DefaultVectorLayerMode = isVector;

            System.Threading.Tasks.Task.Run(delegate
            {
                LayerVector layers = service.BuildNamedMap(mapname, new StringVariantMap());

                // NB! This update priority only works for the map tpl_a108ee2b_6699_43bc_aa71_3b0bc962acf9 (TorqueActivity)
                // It may make loading worse or even break it when tried with other maps
                layers[0].UpdatePriority = 2;
                layers[1].UpdatePriority = 1;
                layers[2].UpdatePriority = 0;

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

                if (success != null)
                {
                    success();
                }
            });
        }
        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);
        }
Example #3
0
        public static void ConfigureNamedVectorLayers(this MapView map, string name)
        {
            System.Threading.Tasks.Task.Run(delegate
            {
                CartoMapsService service = new CartoMapsService();
                service.Username         = "******";

                // Use VectorLayers
                service.DefaultVectorLayerMode = true;

                LayerVector layers = service.BuildNamedMap(name, new StringVariantMap());

                for (int i = 0; i < layers.Count; i++)
                {
                    map.Layers.Add(layers[i]);
                }
            });
        }
Example #4
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);
        }
Example #5
0
        public static void ConfigureNamedVectorLayers(this MapView map, string username, string mapname, Action <VectorTileLayer> complete)
        {
            System.Threading.Tasks.Task.Run(delegate
            {
                CartoMapsService service = new CartoMapsService();
                service.Username         = username;

                // Use VectorLayers
                service.DefaultVectorLayerMode = true;

                VectorTileLayer layer;

                LayerVector layers = service.BuildNamedMap(mapname, new StringVariantMap());
                // Only grab the second layer in the list.
                // The first is the base map and the last is a text layer
                layer = (VectorTileLayer)layers[1];

                complete(layer);
            });
        }
        public static void ConfigureNamedVectorLayers(this MapView map, string name, Action complete)
        {
            System.Threading.Tasks.Task.Run(delegate
            {
                CartoMapsService service = new CartoMapsService();
                service.Username = "******";

                // Use VectorLayers
                service.DefaultVectorLayerMode = true;

                LayerVector layers = service.BuildNamedMap(name, new StringVariantMap());

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

                complete();
            });
        }
        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);
                }
            });
        }
Example #8
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]);
                }
            });
        }