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); }
internal virtual void zoomToPoint() { //New York //MapPoint pt = new MapPoint(-74.0059700 , 40.7142700 ); //Belarus //MapPoint pt = new MapPoint(27.56, 53.9); //; // Move map to the Montenegro capital MapPoint pt = MapPoint.CreateFromGeoCoordinates(42.4341, 19.26); GLMapView mapView = (GLMapView)this.FindViewById(Resource.Id.map_view); mapView.SetMapCenter(pt, false); mapView.SetMapZoom(16, false); }
protected override void OnListItemClick(ListView l, View v, int position, long id) { Intent i; if ((Samples)position == Samples.MAP_TEXTURE_VIEW) { i = new Intent(this, typeof(MapTextureViewActivity)); i.PutExtra("cx", 27.0); i.PutExtra("cy", 53.0); this.StartActivity(i); return; } if ((Samples)position == Samples.DOWNLOAD_MAP) { i = new Intent(this, typeof(DownloadActivity)); i.PutExtra("cx", 27.0); i.PutExtra("cy", 53.0); this.StartActivity(i); return; } if ((Samples)position == Samples.SVG_TEST) { i = new Intent(this, typeof(DisplayImageActivity)); this.StartActivity(i); return; } if ((Samples)position == Samples.CRASH_NDK) { GLMapView.CrashNDK2(); return; } i = new Intent(this, typeof(MapViewActivity)); Bundle b = new Bundle(); b.PutInt("example", position); i.PutExtras(b); this.StartActivity(i); }
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); }
void captureScreen() { GLMapView mapView = (GLMapView)this.FindViewById(Resource.Id.map_view); mapView.CaptureFrameWhenFinish(this); }
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(); }); }); }