Beispiel #1
0
        protected override Marker CreateNativeItem(Pin item)
        {
            MarkerOptions options = new MarkerOptions()
                                    .InvokePosition(item.Coordinate.ToNative())
                                    .InvokeTitle(item.Title);

            if (item.Animate)
            {
                options.InvokeAnimateType(MarkerOptions.MarkerAnimateType.Grow);
            }

            options.Draggable(item.Draggable);
            options.Flat(!item.Enabled3D);

            BitmapDescriptor bitmap = item.Image?.ToNative();

            if (null == bitmap)
            {
                throw new Exception("必须提供一个图标");
            }
            options.InvokeIcon(bitmap);

            Marker marker = (Marker)NativeMap.Map.AddOverlay(options);

            item.NativeObject = marker;

            return(marker);
        }
Beispiel #2
0
        protected override Marker CreateNativeItem(Pin item)
        {
            //var options = new MarkerOptions().InvokePosition(item.Coordinate.ToNative()).InvokeTitle(item.Title);

            MarkerOptions options = new MarkerOptions().InvokePosition(item.Coordinate.ToNative());

            if (item.Animate)
            {
                options.InvokeAnimateType(MarkerOptions.MarkerAnimateType.Grow);
            }

            options.Draggable(item.Draggable);
            options.Flat(!item.Enabled3D);

            BitmapDescriptor bitmap = BitmapDescriptorFactory.FromResource(Resource.Drawable.water_drop);

            //BitmapDescriptor bitmap = item.Image?.ToNative();
            if (null == bitmap)
            {
                throw new Exception("必须提供一个图标");
            }
            //var nbitmap = ScaleBitmap(bitmap.Bitmap, 0.5f);
            //TextOptions textOptions = new TextOptions();
            //textOptions.InvokeText(item.Title);
            //textOptions.InvokePosition(item.Coordinate.ToNative());

            options.InvokeIcon(bitmap);

            //Marker marker = (Marker)NativeMap.Map.AddOverlay(textOptions);
            Marker marker = (Marker)NativeMap.Map.AddOverlay(options);

            marker.Scale      = 0.5f;
            marker.Title      = item.Title;
            item.NativeObject = marker;

            return(marker);
        }
Beispiel #3
0
        public void OnMapReady(GoogleMap map)
        {
            map.MyLocationButtonClick += (s, a) =>
            {
                if (_myLocationMarker != null)
                {
                    var point = _myLocationMarker.Position.ToGeoPoint();
                    this.MapViewModel.UpdateMapCenterCommand.Execute(new Tuple <GeoPoint, bool>(point, true));
                }
            };

            var locationProvider = Mvx.Resolve <ILocationService>();

            var lastLocation = locationProvider.GetLastLocation();

            if (!lastLocation.Equals(GeoPoint.Empty))
            {
                var myLocationMarkerOptions = new MarkerOptions();
                myLocationMarkerOptions.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.my_location));
                myLocationMarkerOptions.Flat(true);
                myLocationMarkerOptions.SetPosition(lastLocation.ToLatLng());
                _myLocationMarker = map.AddMarker(myLocationMarkerOptions);
            }

            locationProvider.LocationUpdated += this.OnLocationUpdated;
            map.SetLocationSource(locationProvider as ILocationSource);

            if (_mapViewWrapper == null)
            {
                _mapViewWrapper = new MonoDroidGoogleMapsView(map);
                _mapViewWrapper.MarkerClicked += (s, a) =>
                {
                    if (this.MapViewModel != null)
                    {
                        var routeStopVM = _routeStopMarkerManager.GetDataForMarker <RouteStopMapViewModel>(a.Marker);
                        if (routeStopVM != null)
                        {
                            this.MapViewModel.SelectRouteStopCommand.Execute(routeStopVM.Model.Id);
                        }
                        else
                        {
                            var vehicleVM = _vehicleMarkerManager.GetDataForMarker <VehicleViewModel>(a.Marker);
                            if (vehicleVM != null)
                            {
                                this.MapViewModel.SelectVehicleCommand.Execute(vehicleVM.VehicleId);
                            }
                        }
                    }
                };

                _mapViewWrapper.MapClicked += (s, a) =>
                {
                    this.RaiseMapClickedEvent();
                    this.MapViewModel.ClearSelectionCommand.Execute();
                };

                _mapViewWrapper.CameraLocationChanged += (s, a) => this.MapViewModel.UpdateMapCenterCommand.Execute(new Tuple <GeoPoint, bool>(a.Location, false));
            }

            if (_vehicleMarkerManager == null)
            {
                _vehicleMarkerManager = new VehicleMarkerManager(_mapViewWrapper, this.MapViewModel.MapVehiclesViewModel);
            }

            if (_routeStopMarkerManager == null)
            {
                _routeStopMarkerManager = new RouteStopMarkerManager(_mapViewWrapper, this.MapViewModel.MapRouteStopsViewModel);
            }

            if (_mapLocationManager == null)
            {
                _mapLocationManager = new MapLocationManager(_mapViewWrapper);
            }

            var set = this.CreateBindingSet <MapView, MapViewModel>();

            set.Bind(map)
            .For(m => m.MyLocationEnabled)
            .To(vm => vm.DetectedArea);

            set.Bind(_mapLocationManager)
            .For(m => m.Location)
            .To(vm => vm.MapCenter);

            set.Bind(_mapViewWrapper)
            .For(m => m.Zoom)
            .To(vm => vm.Zoom);

            set.Bind(_mapViewWrapper)
            .For(m => m.VisibleRegion)
            .To(vm => vm.VisibleRegion);

            set.Apply();

            (this.ViewModel as MapViewModel).Zoom = map.CameraPosition.Zoom;
        }