protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.texture_view_map); TextureView textureView = (TextureView)FindViewById(Resource.Id.texture_view); mapView = new GLMapView(this, textureView); mapView.LoadStyle(Assets, "DefaultStyle.bundle"); mapView.SetScaleRulerStyle(GLUnits.SI, GLMapPlacement.BottomCenter, new MapPoint(10, 10), 200); mapView.SetAttributionPosition(GLMapPlacement.TopCenter); }
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(); }); }); }