internal virtual void updateMapDownloadButtonText()
        {
            if (btnDownloadMap.Visibility == ViewStates.Visible)
            {
                MapPoint center = mapView.MapCenter;

                mapToDownload = GLMapManager.MapAtPoint(center);

                if (mapToDownload != null)
                {
                    string text;
                    if (mapToDownload.State == GLMapInfoState.InProgress)
                    {
                        text = string.Format("Downloading {0} {1}%", mapToDownload.GetLocalizedName(localeSettings), (int)(mapToDownload.DownloadProgress * 100));
                    }
                    else
                    {
                        text = string.Format("Download {0}", mapToDownload.GetLocalizedName(localeSettings));
                    }
                    btnDownloadMap.Text = text;
                }
                else
                {
                    btnDownloadMap.Text = "Download maps";
                }
            }
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.download);

            listView = (ListView)FindViewById(Android.Resource.Id.List);
            RegisterForContextMenu(listView);
            IEnumerable <GLMapDownloadTask> tasks = GLMapManager.MapDownloadTasks;

            GLMapManager.AddStateListener((IStateListener)this);

            Intent i = Intent;

            center = new MapPoint(i.GetDoubleExtra("cx", 0.0), i.GetDoubleExtra("cy", 0.0));
            long collectionID = i.GetLongExtra("collectionID", 0);

            if (collectionID != 0)
            {
                GLMapInfo collection = GLMapManager.GetMapWithID(collectionID);
                if (collection != null)
                {
                    UpdateAllItems(collection.GetMaps());
                }
            }
            else
            {
                UpdateAllItems(GLMapManager.GetMaps());
                GLMapManager.UpdateMapList(this, new Runnable(() => UpdateAllItems(GLMapManager.GetMaps())));
            }
        }
Пример #3
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            GLMapManager.SharedManager().Init();
            GLMapManager.SharedManager().ApiKey = File.ReadAllText("./APIKey.txt");;

            return(true);
        }
 protected override void OnDestroy()
 {
     GLMapManager.RemoveStateListener(this);
     if (markerLayer != null)
     {
         markerLayer.Dispose();
         markerLayer = null;
     }
     base.OnDestroy();
 }
Пример #5
0
        public void UpdateAllItems(GLMapInfo[] maps)
        {
            if (maps == null)
            {
                return;
            }

            GLMapManager.SortMaps(maps, center);
            ListView listView = (ListView)FindViewById(Android.Resource.Id.List);

            listView.Adapter    = new MapsAdapter(maps, this, localeSettings);
            listView.ItemClick += (object sender, ItemClickEventArgs e) => {
                GLMapInfo info = (GLMapInfo)listView.Adapter.GetItem(e.Position);
                if (info.IsCollection)
                {
                    Intent intent = new Intent(this, typeof(DownloadActivity));
                    intent.PutExtra("collectionID", info.MapID);
                    intent.PutExtra("cx", center.X);
                    intent.PutExtra("cy", center.Y);
                    StartActivity(intent);
                }
                else
                {
                    GLMapDownloadTask task = GLMapManager.GetDownloadTask(info);
                    if (task != null)
                    {
                        task.Cancel();
                    }
                    else if (info.State != GLMapInfoState.Downloaded)
                    {
                        GLMapManager.CreateDownloadTask(info, this).Start();
                    }
                }
            };

            listView.ItemLongClick += (object sender, ItemLongClickEventArgs e) => {
                GLMapInfo      info  = ((MapsAdapter)this.listView.Adapter).Maps[e.Position];
                GLMapInfoState state = info.State;
                if (state == GLMapInfoState.Downloaded || state == GLMapInfoState.NeedResume || state == GLMapInfoState.NeedUpdate)
                {
                    selectedMap = info;
                    //return false;
                }
                else
                {
                    //return true;
                }
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.sample_select);

            if (!GLMapManager.Initialize(this, this.GetString(Resource.String.api_key), null))
            {
                //Error caching resources. Check free space for world database (~25MB)
            }

            String[] values = new String[] {
                "Open offline map",
                "Open embedd map",
                "Open online map",
                "Open online raster map",
                "GLMapView in TextureView",
                "Zoom to bbox",
                "Offline Search",
                "Markers",
                "Markers using mapcss",
                "Display single image",
                "Display image group",
                "Add multiline",
                "Add polygon",
                "Load GeoJSON",
                "Callback test",
                "Capture screen",
                "Fly to",
                "Style live reload",
                "Download Map",
                "SVG Test",
                "Crash NDK",
            };

            ArrayAdapter <string> adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, values);

            ListAdapter = adapter;
        }
Пример #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            GLMapManager.SharedManager().TileDownloadingAllowed = true;

            mapView = new GLMapView();

            mapView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            mapView.ShowUserLocation = true;
            mapView.BackgroundColor  = UIColor.Red;

            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var cacheDir  = Path.Combine(documents, "RasterCache");

            Directory.CreateDirectory(cacheDir);

            var cache = Path.Combine(cacheDir, "os.cache");

            mapView.RasterSources = new GLMapRasterTileSource[] { new OSMTileSource(cache) };

            this.View.AddSubview(mapView);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.map);
            mapView = (GLMapView)FindViewById(Resource.Id.map_view);

            // Map list is updated, because download button depends on available map list and during first launch this list is empty
            GLMapManager.UpdateMapList(this, null);

            btnDownloadMap        = (Button)this.FindViewById(Resource.Id.button_dl_map);
            btnDownloadMap.Click += (object sender, EventArgs e) =>
            {
                if (mapToDownload != null)
                {
                    GLMapDownloadTask task = GLMapManager.GetDownloadTask(mapToDownload);
                    if (task != null)
                    {
                        task.Cancel();
                    }
                    else
                    {
                        GLMapManager.CreateDownloadTask(mapToDownload, this).Start();
                    }
                    updateMapDownloadButtonText();
                }
                else
                {
                    Intent i = new Intent(Application.Context, typeof(DownloadActivity));

                    MapPoint pt = mapView.MapCenter;
                    i.PutExtra("cx", pt.X);
                    i.PutExtra("cy", pt.Y);
                    Application.Context.StartActivity(i);
                }
            };

            GLMapManager.AddStateListener(this);

            localeSettings         = new GLMapLocaleSettings();
            mapView.LocaleSettings = localeSettings;
            mapView.LoadStyle(Assets, "DefaultStyle.bundle");
            mapView.SetUserLocationImages(mapView.ImageManager.Open("DefaultStyle.bundle/circle-new.svgpb", 1, 0), mapView.ImageManager.Open("DefaultStyle.bundle/arrow-new.svgpb", 1, 0));

            mapView.SetScaleRulerStyle(GLUnits.SI, GLMapPlacement.BottomCenter, new MapPoint(10, 10), 200);
            mapView.SetAttributionPosition(GLMapPlacement.TopCenter);

            CheckAndRequestLocationPermission();

            Bundle  b       = Intent.Extras;
            Samples example = (Samples)b.GetInt("example");

            switch (example)
            {
            case Samples.MAP_EMBEDD:
                if (!GLMapManager.AddMap(Assets, "Montenegro.vm", null))
                {
                    //Failed to unpack to caches. Check free space.
                }
                zoomToPoint();
                break;

            case Samples.MAP_ONLINE:
                GLMapManager.SetAllowedTileDownload(true);
                break;

            case Samples.MAP_ONLINE_RASTER:
                mapView.RasterTileSources = new GLMapRasterTileSource[] { new OSMTileSource(this) };
                break;

            case Samples.ZOOM_BBOX:
                zoomToBBox();
                break;

            case Samples.FLY_TO:
            {
                mapView.SetMapCenter(MapPoint.CreateFromGeoCoordinates(37.3257, -122.0353), false);
                mapView.SetMapZoom(14, false);

                Button btn = (Button)FindViewById(Resource.Id.button_action);
                btn.Visibility = ViewStates.Visible;
                btn.Text       = "Fly";
                btn.Click     += (object sender, EventArgs e) =>
                {
                    double min_lat = 33;
                    double max_lat = 48;
                    double min_lon = -118;
                    double max_lon = -85;

                    double lat = min_lat + (max_lat - min_lat) * new Random(1).NextDouble();
                    double lon = min_lon + (max_lon - min_lon) * new Random(2).NextDouble();

                    MapGeoPoint geoPoint = new MapGeoPoint(lat, lon);

                    mapView.FlyTo(geoPoint, 15, 0, 0);
                };
                GLMapManager.SetAllowedTileDownload(true);
                break;
            }

            case Samples.OFFLINE_SEARCH:
                GLMapManager.AddMap(Assets, "Montenegro.vm", null);
                zoomToPoint();
                offlineSearch();
                break;

            case Samples.MARKERS:
                mapView.LongClickable = true;

                gestureDetector = new GestureDetector(this, new SimpleOnGestureListenerAnonymousInnerClassHelper(this));

                mapView.SetOnTouchListener(new TouchListener(gestureDetector));

                addMarkers();
                GLMapManager.SetAllowedTileDownload(true);
                break;

            case Samples.MARKERS_MAPCSS:
                addMarkersWithMapcss();

                gestureDetector = new GestureDetector(this, new SimpleOnGestureListenerAnonymousInnerClassHelper2(this));

                mapView.SetOnTouchListener(new TouchListener(gestureDetector));

                GLMapManager.SetAllowedTileDownload(true);
                break;

            case Samples.MULTILINE:
                addMultiline();
                break;

            case Samples.POLYGON:
                addPolygon();
                break;

            case Samples.CAPTURE_SCREEN:
                zoomToPoint();
                captureScreen();
                break;

            case Samples.IMAGE_SINGLE:
            {
                Button btn = (Button)this.FindViewById(Resource.Id.button_action);
                btn.Visibility = ViewStates.Visible;
                delImage(btn, null);
                break;
            }

            case Samples.IMAGE_MULTI:
                mapView.LongClickable = true;

                gestureDetector = new GestureDetector(this, new SimpleOnGestureListenerAnonymousInnerClassHelper3(this));

                mapView.SetOnTouchListener(new TouchListener(gestureDetector));
                break;

            case Samples.GEO_JSON:
                loadGeoJSON();
                break;

            case Samples.STYLE_LIVE_RELOAD:
                styleLiveReload();
                break;
            }

            mapView.SetCenterTileStateChangedCallback(() =>
            {
                RunOnUiThread(() =>
                {
                    updateMapDownloadButton();
                });
            });

            mapView.SetMapDidMoveCallback(() =>
            {
                if (example == Samples.CALLBACK_TEST)
                {
                    Log.Warn("GLMapView", "Did move");
                }
                RunOnUiThread(() =>
                {
                    updateMapDownloadButtonText();
                });
            });
        }
Пример #9
0
 protected override void OnDestroy()
 {
     GLMapManager.RemoveStateListener((IStateListener)this);
     base.OnDestroy();
 }