Exemplo n.º 1
0
        void DrawCircles(Point e)
        {
            if (circleOptionsInner == null)
            {
                circleOptionsInner = new CircleOptions().InvokeCenter(new LatLng(e.X, e.Y)).InvokeRadius(80).InvokeFillColor(Android.Graphics.Color.ParseColor("#0D15b8fe")).InvokeStrokeWidth(0);
                circleInner        = NativeMap.AddCircle(circleOptionsInner);
            }

            if (circleOptionsOuter == null)
            {
                circleOptionsOuter = new CircleOptions().InvokeCenter(new LatLng(e.X, e.Y)).InvokeRadius(350).InvokeFillColor(Android.Graphics.Color.ParseColor("#1A15b8fe")).InvokeStrokeWidth(0);
                circleOuter        = NativeMap.AddCircle(circleOptionsOuter);
            }

            if (firstLoad == true)
            {
                NativeMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(e.X, e.Y), 15.8f));
                var animation = new Animation(v => circleInner.Radius = v, 25, 200);
                animation.Commit(Xamarin.Forms.Application.Current.MainPage, "SimpleAnimation", 500, 2000, Easing.CubicOut, null, () => true);
                var fadeEffect = new Animation(v => circleInner.FillColor = Android.Graphics.Color.ParseColor(string.Format("#{0}15b8fe", ((int)(v < 0 ? 0 : v)).ToString("D2"))), 99, -20);
                fadeEffect.Commit(Xamarin.Forms.Application.Current.MainPage, "FadeAnimation", 500, 2000, Easing.Linear, null, () => true);
                firstLoad = false;
            }
            circleInner.Center = new LatLng(e.X, e.Y);
            circleOuter.Center = new LatLng(e.X, e.Y);
        }
Exemplo n.º 2
0
        private void UpdateRegion()
        {
            UpdateGoogleMap(formsMap =>
            {
                if (MapEx.Region == null)
                {
                    return;
                }

                var cameraUpdate = CameraUpdateFactory.NewLatLngBounds(MapEx.Region.ToLatLngBounds(), 0);
                NativeMap.MoveCamera(cameraUpdate);
            });
        }
Exemplo n.º 3
0
 /// <summary>
 /// Moves the camera directly to the given coordinates.
 /// </summary>
 /// <param name="lat">Latitude to move to.</param>
 /// <param name="lon">Longitude to move to.</param>
 public void MoveCameraTo(double lat, double lon)
 {
     try
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             if (KCApi.Properties.MapReady && KCApi.Properties.RenderReady && NativeMap != null)
             {
                 lock (nativeMapLock)
                 {
                     NativeMap.MoveCamera(CameraUpdateFactory.NewLatLng(new LatLng(lat, lon)));
                 }
             }
         });
     }
     catch (Exception e)
     {
         KCApi.OutputException(e);
     }
 }
Exemplo n.º 4
0
        void OnMarkerClicked(object sender, GoogleMap.MarkerClickEventArgs e)
        {
            CancelPinAnimation();

            customMap.OnSelect = true;
            var pintoadd   = new PinModel();
            var customView = e.Marker;

            System.Diagnostics.Debug.WriteLine("Position of marker: {0}, {1}", customView.Position.Latitude, customView.Position.Longitude);

            foreach (X.Models.PinModel pin in customMap.CustomPin)
            {
                System.Diagnostics.Debug.WriteLine("Custom pin position: {0}, {1}", pin.Position.Latitude, pin.Position.Longitude);
                System.Diagnostics.Debug.WriteLine("\tdLat = {0}", Math.Abs(pin.Position.Latitude - customView.Position.Latitude));
                System.Diagnostics.Debug.WriteLine("\tdLon = {0}", Math.Abs(pin.Position.Longitude - customView.Position.Longitude));
                if (customView.Snippet.Equals(pin.Id))
                {
                    pintoadd = pin;
                    break;
                }
            }
            VisibleRegion visibleRegion = NativeMap.Projection.VisibleRegion;

            NativeMap.Clear();
            marketList.Clear();

            //var dMeters = 0.004 * NativeMap.Projection.VisibleRegion.;
            //var dLat = dMeters / 111.11;
            var bounds = NativeMap.Projection.VisibleRegion.LatLngBounds;
            var dLat   = 0.01 * (bounds.Northeast.Latitude - bounds.Southwest.Latitude);

            LatLng latlng = new LatLng(pintoadd.Position.Latitude - dLat, pintoadd.Position.Longitude);

            NativeMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng));
            //pintoadd.Emojis.Clear();
            NativeMap.AddMarker(CreateMarker(pintoadd));
            customMap.showInfoBox(pintoadd.Id);
        }
Exemplo n.º 5
0
 protected virtual void OnMapMessage(Map map, MapMessage message)
 {
     if (message is ZoomMessage)
     {
         //var msg = (ZoomMessage)message;
         UpdateRegion();
     }
     else if (message is ProjectionMessage)
     {
         var msg       = (ProjectionMessage)message;
         var screenPos = NativeMap.Projection.ToScreenLocation(msg.Position.ToLatLng());
         msg.ScreenPosition = new Point(screenPos.X, screenPos.Y);
     }
     else if (message is MoveMessage)
     {
         var msg = (MoveMessage)message;
         UpdateGoogleMap(formsMap =>
         {
             var cameraUpdate = CameraUpdateFactory.NewLatLng(msg.Target.ToLatLng());
             NativeMap.MoveCamera(cameraUpdate);
         });
     }
 }
Exemplo n.º 6
0
        private void drawMarkers(int markerSize)
        {
            LatLngBounds.Builder bounds = new LatLngBounds.Builder();
            NativeMap.Clear();
            List <LatLng> latLngList = new List <LatLng>();

            foreach (var point in customMap.Points)
            {
                var latlng = new LatLng(point.Latitude, point.Longitude);
                latLngList.Add(latlng);

                /*var marker = new MarkerOptions();
                 * marker.Anchor(0.5f, 0.5f);
                 * marker.SetPosition(latlng);
                 * BitmapDescriptor pic = null;
                 * if (!string.IsNullOrEmpty(point.PathToPicture))
                 * {
                 *  Bitmap bm = BitmapFactory.DecodeFile(point.PathToPicture);
                 *  if (bm != null)
                 *  {
                 *      var croppedBitmap = getCroppedBitmap(bm, markerSize);
                 *      pic = BitmapDescriptorFactory.FromBitmap(croppedBitmap);
                 *      bm = null;
                 *      croppedBitmap = null;
                 *  }
                 * }
                 *
                 * if (pic == null)
                 * {
                 *  pic = BitmapDescriptorFactory.FromResource(Resource.Drawable.place_unknown);
                 * }
                 *
                 * marker.SetIcon(pic);
                 * NativeMap.AddMarker(marker);
                 * bounds.Include(latlng);*/
            }
            List <PatternItem> pattern_lines = new List <PatternItem>();

            pattern_lines.Add(new Gap(10));
            //pattern_lines.Add(new Dash(20));
            PolylineOptions lineOptions = new PolylineOptions();

            foreach (var point in latLngList)
            {
                lineOptions.Add(point);
            }
            //lineOptions.InvokePattern(pattern_lines);
            lineOptions.InvokeWidth(10);
            NativeMap.AddPolyline(lineOptions);
            if (customMap.Points.Count > 1)
            {
                try
                {
                    NativeMap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds.Build(), 100));
                }
                catch (Java.Lang.Exception)
                {
                }
            }
            bounds.Dispose();
        }