Exemplo n.º 1
0
		protected override void OnAttached()
		{
			var mapView = Control as MapView;
			if(mapView == null)
				return;

			behavior = (MapExtensionBehavior) (Element as Map)?.Behaviors?.FirstOrDefault(x =>
				x is MapExtensionBehavior);
			if(behavior == null)
				return;
			

			var zoomButton = mapView.FindViewById(1); // ズームボタン LinearLayout
			if(zoomButton != null)
			{
				zoomButton.Visibility = Android.Views.ViewStates.Invisible;
			}

			var locationButton = mapView.FindViewById(2); // 現在位置ボタン ImageView
			if(locationButton != null)
			{
				locationButton.Visibility = Android.Views.ViewStates.Invisible;
			}

			var callback = new OnMapReadyCallback();
			callback.MapReady += (sender, e) => {
				googleMap = callback.GoogleMap;

				googleMap.MyLocationChange += GoogleMap_MyLocationChange;
				// なぜかCameraChangeにハンドラを追加するとXF.Maps.Map.VisibleRegionが更新されなくなる
//				googleMap.CameraChange += GoogleMap_CameraChange;

				var point = new LatLng(
					XFAedSearch.Droid.Helpers.Settings.Latitude,
					XFAedSearch.Droid.Helpers.Settings.Longitude);
				googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(point,
					XFAedSearch.Droid.Helpers.Settings.ZoomLevel));

				googleMap.SetOnMapLoadedCallback(new MapLoadedCallback {
					OnMapLoadedAction = () => MapLoaded?.Invoke(this, new EventArgs())
				});
			};
			mapView.GetMapAsync(callback);

		}
Exemplo n.º 2
0
		protected override void OnAttached()
		{
			mapView = Control as MKMapView;
			if(mapView == null)
				return;

			behavior = (MapExtensionBehavior) (Element as Map)?.Behaviors?.FirstOrDefault(x =>
				x is MapExtensionBehavior);
			if(behavior == null)
				return;

//			tapGesture = new UITapGestureRecognizer(() => 
//			{
//				Console.WriteLine("MapViewTapped");
//				MapTapped?.Invoke(this, new EventArgs());
//			})
//			{
//				NumberOfTapsRequired = 1,
//
//			};
//			mapView.AddGestureRecognizer(tapGesture);

			mapView.DidUpdateUserLocation += DidUpdateUserLocation;

			// iOSのMapLoadedは新しいエリアを読み込んだ時に発火する(Androidとは違うっぽい)
//			mapView.MapLoaded += MapView_MapLoaded;


//			mapView.OverlayRenderer = (mapView, overlay) =>
//			{
//				if(polygonRenderer == null)
//				{
//					polygonRenderer = new MKPolygonRenderer (overlay as MKPolygon);
//					polygonRenderer.FillColor = UIKit.UIColor.Blue;
//					polygonRenderer.StrokeColor = UIKit.UIColor.Red;
//				}
//				return polygonRenderer;
//			};
		}
Exemplo n.º 3
0
		protected override void OnDetached()
		{
			mapView.DidUpdateUserLocation -= DidUpdateUserLocation;
			mapView.MapLoaded -= MapView_MapLoaded;

//			mapView.RemoveGestureRecognizer(tapGesture);
//			tapGesture.Dispose();
//			tapGesture = null;

			mapView = null;
			behavior = null;
			polygon?.Dispose();
			polygon = null;
			polygonRenderer?.Dispose();
			polygonRenderer = null;
		}