Ejemplo n.º 1
0
        // Example how to calculate zoom level for some bbox
        internal virtual void zoomToBBox()
        {
            mapView.DoWhenSurfaceCreated(() =>
            {
                GLMapBBox bbox = new GLMapBBox();
                bbox.AddPoint(MapPoint.CreateFromGeoCoordinates(52.5037, 13.4102)); // Berlin
                bbox.AddPoint(MapPoint.CreateFromGeoCoordinates(53.9024, 27.5618)); // Minsk

                mapView.SetMapCenter(bbox.Center(), false);
                mapView.SetMapZoom(mapView.MapZoomForBBox(bbox, mapView.Width, mapView.Height), false);
            });
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        internal virtual void addMultiline()
        {
            MapPoint[] line1 = new MapPoint[5];
            line1[0] = MapPoint.CreateFromGeoCoordinates(53.8869, 27.7151); // Minsk
            line1[1] = MapPoint.CreateFromGeoCoordinates(50.4339, 30.5186); // Kiev
            line1[2] = MapPoint.CreateFromGeoCoordinates(52.2251, 21.0103); // Warsaw
            line1[3] = MapPoint.CreateFromGeoCoordinates(52.5037, 13.4102); // Berlin
            line1[4] = MapPoint.CreateFromGeoCoordinates(48.8505, 2.3343);  // Paris

            MapPoint[] line2 = new MapPoint[3];
            line2[0] = MapPoint.CreateFromGeoCoordinates(52.3690, 4.9021); // Amsterdam
            line2[1] = MapPoint.CreateFromGeoCoordinates(50.8263, 4.3458); // Brussel
            line2[2] = MapPoint.CreateFromGeoCoordinates(49.6072, 6.1296); // Luxembourg

            MapPoint[][]      multiline = new MapPoint[][] { line1, line2 };
            GLMapVectorObject obj       = GLMapVectorObject.CreateMultiline(multiline);

            // style applied to all lines added. Style is string with mapcss rules. Read more in manual.
            mapView.AddVectorObjectWithStyle(obj, GLMapVectorCascadeStyle.CreateStyle("line{width: 2pt;color:green;layer:100;}"), null);
        }
Ejemplo n.º 4
0
        internal virtual void offlineSearch()
        {
            GLSearchCategories categories = GetSearchCategories(Resources);

            GLSearchOffline searchOffline = new GLSearchOffline();

            searchOffline.SetCategories(categories);                                                          //Set categories to use for search
            searchOffline.SetCenter(MapPoint.CreateFromGeoCoordinates(42.4341, 19.26));                       //Set center of search
            searchOffline.SetLimit(20);                                                                       //Set maximum number of results. By default is is 100
            searchOffline.SetLocaleSettings(mapView.LocaleSettings);                                          //Locale settings to give bonus for results that match to user language

            GLSearchCategory[] category = categories.GetStartedWith(new string[] { "food" }, localeSettings); //find categories by name
            if (category.Length != 0)
            {
                searchOffline.AddCategoryFilter(category[0]); //Filter results by category
            }
            //searchOffline.addNameFilter("cali"); //Add filter by name

            searchOffline.Start(new GLMapSearchCompletionAnonymousInnerClassHelper(this));
        }
Ejemplo n.º 5
0
        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();
                });
            });
        }