Exemplo n.º 1
0
 private void NativeMapOnCameraIdle(object sender, EventArgs e)
 {
     if (previousCameraPostion == null || Math.Abs(previousCameraPostion.Zoom - NativeMap.CameraPosition.Zoom) > 0.001)
     {
         previousCameraPostion = NativeMap.CameraPosition;
     }
 }
        public void OnCameraChange(GCameraPosition pos)
        {
            UpdateVisibleRegion(pos.Target);
            var camera = pos.ToXamarinForms();

            Map.CameraPosition = camera;
            Map.SendCameraChanged(camera);
        }
        public new void OnCameraChange(CameraPosition position)
        {
            // 156543.03392 * Math.cos(latLng.lat() * Math.PI / 180) / Math.pow(2, zoom)
            //			var radius = 156543.03392 * System.Math.Cos(position.Target.Latitude * System.Math.PI / 180) / System.Math.Pow(2, position.Zoom);

            var bounds = this.NativeMap.Projection.VisibleRegion.LatLngBounds;

            var radiusInMeters = GeoHelper.GetDistance (bounds.Northeast.Latitude, bounds.Northeast.Longitude, bounds.Southwest.Latitude, bounds.Southwest.Longitude, true);

            var span = MapSpan.FromCenterAndRadius (
                           new Position (bounds.Center.Latitude, bounds.Center.Longitude),
                           Distance.FromMeters (radiusInMeters));
            //				.WithZoom (position.Zoom);

            this.Map.VisibleRegion = span;
        }
Exemplo n.º 4
0
        private void UpdatePosition(CameraPosition pos)
        {
            // if any marker is shown, don't invoke camera change
            var northWest = NativeMap.Projection.FromScreenLocation(new Android.Graphics.Point(0, 0)).ToPosition();
            var center = pos.Target.ToPosition();
            var distanceInDegrees = northWest.DistanceFrom(center);

            var bound = new MapSpan(new Position(center.Latitude, center.Longitude),
                            distanceInDegrees.Latitude * 2, distanceInDegrees.Longitude * 2);
            OnCameraChange(bound, pos);

            MessagingCenter.Send<IMapRenderer, MapMessage>(this, MapMessage.RendererMessage, new ViewChangeMessage(MapEx) { Span = bound, ZoomLevel = pos.Zoom });
        }
Exemplo n.º 5
0
 protected virtual void OnCameraChange(MapSpan span, CameraPosition pos)
 {
 }
Exemplo n.º 6
0
		void HandlePaneStateChanged (InfoPane.State state)
		{
			var time = Resources.GetInteger (Android.Resource.Integer.ConfigShortAnimTime);
			var enabled = state != InfoPane.State.FullyOpened;
			mapFragment.Map.UiSettings.ScrollGesturesEnabled = enabled;
			mapFragment.Map.UiSettings.ZoomGesturesEnabled = enabled;
			if (state == InfoPane.State.FullyOpened && currentShownMarker != null) {
				oldPosition = mapFragment.Map.CameraPosition;
				var destX = mapFragment.Width / 2;
				var destY = (mapFragment.Height - pane.Height) / 2;
				var currentPoint = mapFragment.Map.Projection.ToScreenLocation (currentShownMarker.Position);
				var scroll = CameraUpdateFactory.ScrollBy (- destX + currentPoint.X, - destY + currentPoint.Y);
				mapFragment.Map.AnimateCamera (scroll, time, null);
			} else if (oldPosition != null) {
				mapFragment.Map.AnimateCamera (CameraUpdateFactory.NewCameraPosition (oldPosition), time, null);
				oldPosition = null;
			}
		}
Exemplo n.º 7
0
		public void OnCameraChange (CameraPosition pos)
		{
			UpdateVisibleRegion (pos.Target);
		}
Exemplo n.º 8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.mountainMap);
            //settings database getting records
            InitializeLocationManager();
            DBItineraryRepository dbr = new DBItineraryRepository();

            var terrain        = "terrain";
            var terrainValue   = "1";
            var normal         = "normal";
            var normalValue    = "0";
            var satellite      = "satellite";
            var satelliteValue = "0";
            var hybrid         = "toiletries";
            var hybridValue    = "0";

            try
            {
                var terrainResult = dbr.GetRecordSettings(terrain);
                terrainValue = terrainResult;
                var normalResult = dbr.GetRecordSettings(normal);
                normalValue = normalResult;
                var satelliteResult = dbr.GetRecordSettings(satellite);
                satelliteValue = satelliteResult;
                var hybridResult = dbr.GetRecordSettings(hybrid);
                hybridValue = hybridResult;
            }
            catch (Exception ex)
            {
            }

            MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
            GoogleMap   map     = mapFrag.Map;

            map.SetOnInfoWindowClickListener(this);

            // position
            LatLng locations = new LatLng(13, 122);

            CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
            builder.Target(locations);
            builder.Zoom(6);
            CameraPosition cameraPosition = builder.Build();
            CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            if (map != null)
            {
                map.Clear();
                map.MapType = GoogleMap.MapTypeTerrain;

                if (terrainValue == "1")
                {
                    map.MapType = GoogleMap.MapTypeTerrain;
                }
                else if (normalValue == "1")
                {
                    map.MapType = GoogleMap.MapTypeNormal;
                }
                else if (satelliteValue == "1")
                {
                    map.MapType = GoogleMap.MapTypeSatellite;
                }
                else if (hybridValue == "1")
                {
                    map.MapType = GoogleMap.MapTypeHybrid;
                }

                map.UiSettings.ZoomControlsEnabled = true;
                map.UiSettings.CompassEnabled      = true;
                map.MoveCamera(cameraUpdate);

                mountainsRepository = new MountainsService();
                mMountains          = mountainsRepository.GetAllMountains();

                foreach (Mountain item in mMountains)
                {
                    marker = map.AddMarker(new MarkerOptions()
                                           .SetPosition(new LatLng(item.Lat, item.Lng))
                                           .SetTitle(item.MtName)
                                           .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueYellow)));
                }
            }
        }
Exemplo n.º 9
0
        public void SetViewPoint(CameraPosition cameraPosition, bool animated)
        {
            // As explained here: https://stackoverflow.com/a/14167568
            // This is the way of intializing the map position
            // CameraPosition cameraPosition = new CameraPosition.Builder().Target(latlng).Zoom(zoom).Build();

            if (animated)
            {
                _map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(cameraPosition));
            }
            else
            {
                _map.MoveCamera(CameraUpdateFactory.NewCameraPosition(cameraPosition));
            }
        }