/// <summary> /// Initialize this instance. /// </summary> void Initialize(MapView mapLayout) { _mapLayout = mapLayout; this.SetWillNotDraw(false); this.MapMinZoomLevel = 10; this.MapMaxZoomLevel = 20; _renderer = new MapRenderer <global::Android.Graphics.Canvas>( new CanvasRenderer2D()); // initialize the gesture detection. _gestureDetector = new GestureDetector( this); _scaleGestureDetector = new ScaleGestureDetector( this.Context, this); this.SetOnTouchListener(this); _makerLayer = new LayerPrimitives( new WebMercator()); // initialize all the caching stuff. //_previousCache = null; _cacheRenderer = new MapRenderer <global::Android.Graphics.Canvas>( new CanvasRenderer2D()); _scene = new Scene2DSimple(); _scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value; System.Threading.Timer timer = new Timer(InvalidateSimple, null, 0, 50); }
private void InitializeMap() { if (_mapSceneManager.Map != null) { foreach (var layer in _customLayers) { _mapSceneManager.Map.RemoveLayer(layer.Item2); } _mapSceneManager.Map.RemoveLayer(_canvas); } _isSuspendNotifyMapViewChanged = false; AdjustMapScene(); _mapSceneManager.Initialize(Map, MapCenter, MapZoom, MapTilt, RenderSize); if (_mapSceneManager.Map != null) { SuspendNotifyMapViewChanged(); foreach (var layer in _customLayers.OrderBy(l => l.Item1)) { _mapSceneManager.Map.AddLayer(layer.Item2); } _canvas = new LayerPrimitives(_mapSceneManager.Map.Projection); _mapSceneManager.Map.AddLayer(_canvas); ResumeNotifyMapViewChanged(); } }
/// <summary> /// Initialize implementation from IMapView. /// </summary> /// <param name="mapLayout"></param> void IMapViewSurface.Initialize(MapView mapLayout) { // create the Open GL 2D target. _target = new OpenGLTarget2D(); this.SetRenderer(_target); _mapView = mapLayout; this.SetWillNotDraw(false); this.MapMinZoomLevel = 10; this.MapMaxZoomLevel = 20; // create the renderer. _renderer = new MapRenderer <OpenGLTarget2D>( new OpenGLRenderer2D()); // initialize the gesture detection. this.SetOnTouchListener(this); _scaleGestureDetector = new ScaleGestureDetector( this.Context, this); _rotateGestureDetector = new RotateGestureDetector( this.Context, this); _moveGestureDetector = new MoveGestureDetector( this.Context, this); _tagGestureDetector = new TapGestureDetector( this.Context, this); _makerLayer = new LayerPrimitives( new WebMercator()); _scene = new Scene2D(new WebMercator(), 16); _scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value; }
/// <summary> /// Initialize implementation from IMapView. /// </summary> /// <param name="mapLayout"></param> void IMapViewSurface.Initialize(MapView mapLayout) { _mapView = mapLayout; this.SetWillNotDraw(false); this.MapMinZoomLevel = 10; this.MapMaxZoomLevel = 20; _renderer = new MapRenderer <global::Android.Graphics.Canvas>( new CanvasRenderer2D()); // initialize the gesture detection. this.SetOnTouchListener(this); _scaleGestureDetector = new ScaleGestureDetector( this.Context, this); _rotateGestureDetector = new RotateGestureDetector( this.Context, this); _moveGestureDetector = new MoveGestureDetector( this.Context, this); _tagGestureDetector = new TapGestureDetector( this.Context, this); _makerLayer = new LayerPrimitives( new WebMercator()); // initialize all the caching stuff. _backgroundColor = SimpleColor.FromKnownColor(KnownColor.White).Value; _cacheRenderer = new MapRenderer <global::Android.Graphics.Canvas>( new CanvasRenderer2D()); }
/// <summary> /// Raises the OnLoad event. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\static\default.mapcss").OpenRead(), new MapCSSDictionaryImageSource()); // initialize map. var map = new OsmSharp.UI.Map.Map(); //// initialize router. //_router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource( // new FileInfo(@"kempen.osm.pbf").OpenRead()), new OsmRoutingInterpreter()); var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] { 16, 14, 12, 10 })); var target = new StyleOsmStreamSceneTarget( mapCSSInterpreter, scene, new WebMercator()); var source = new XmlOsmStreamSource( new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead()); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); target.Pull(); //var merger = new Scene2DObjectMerger(); //scene = merger.BuildMergedScene(scene); map.AddLayer(new LayerScene(scene)); //var dataSource = MemoryDataSource.CreateFromXmlStream( // new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead()); //map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection)); //var layerTile = new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg", 200); //layerTile.MinZoom = 12; //layerTile.MaxZoom = 13; //map.AddLayer(layerTile); //map.AddLayer(new LayerScene( // Scene2D.Deserialize(new FileInfo(@"default.map").OpenRead(), // true))); // initialize route/points layer. _layerRoute = new LayerRoute(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerRoute); _layerPrimitives = new LayerPrimitives(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerPrimitives); // set control properties. this.mapControl1.Map = map; this.mapControl1.MapCenter = new GeoCoordinate(51.0167, 4.4914); // wechel this.mapControl1.MapZoom = 14; this.mapControl1.MapMouseClick += mapControl1_MapMouseClick; this.mapControl1.MapMouseMove += mapControl1_MapMouseMove; }
/// <summary> /// Raises the OnLoad event. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( new FileInfo(@"default.mapcss").OpenRead(), new MapCSSDictionaryImageSource()); // initialize map. var map = new OsmSharp.UI.Map.Map(); //// initialize router. //_router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource( // new FileInfo(@"kempen.osm.pbf").OpenRead()), new OsmRoutingInterpreter()); //Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List<float>(new float[] { // 16, 14, 12, 10 })); //StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget( // mapCSSInterpreter, scene, new WebMercator()); //FileInfo testFile = new FileInfo(@"kempen.osm.pbf"); //Stream stream = testFile.OpenRead(); //OsmStreamSource source = new PBFOsmStreamSource(stream); //OsmStreamFilterProgress progress = new OsmStreamFilterProgress(source); //target.RegisterSource(progress); //target.Pull(); //var merger = new Scene2DObjectMerger(); //scene = merger.BuildMergedScene(scene); //map.AddLayer(new LayerScene(scene)); //var dataSource = MemoryDataSource.CreateFromPBFStream( // new FileInfo(@"kempen-big.osm.pbf").OpenRead()); //map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection)); map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg", 200)); //map.AddLayer(new LayerScene( // Scene2D.Deserialize(new FileInfo(@"default.map").OpenRead(), // true))); // initialize route/points layer. _layerRoute = new LayerRoute(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerRoute); _layerPrimitives = new LayerPrimitives(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerPrimitives); // set control properties. this.mapControl1.Map = map; this.mapControl1.MapCenter = new GeoCoordinate(51.26371, 4.7854); // wechel this.mapControl1.MapZoom = 14; this.mapControl1.MapMouseClick += mapControl1_MapMouseClick; }
/// <summary> /// Initialize implementation from IMapView. /// </summary> /// <param name="mapLayout"></param> void IMapViewSurface.Initialize(MapView mapLayout) { this.MapAllowPan = true; this.MapAllowTilt = true; this.MapAllowZoom = true; // register default invalidation trigger. (this as IInvalidatableMapSurface).RegisterListener(new DefaultTrigger(this)); _mapView = mapLayout; this.SetWillNotDraw(false); // this.SetWillNotCacheDrawing(true); this.MapMinZoomLevel = 0; this.MapMaxZoomLevel = 20; // gets the system density. _density = global::Android.Content.Res.Resources.System.DisplayMetrics.Density; _bufferFactor = _density; // set default scale factor relative to density. // create the renderer. _renderer = new MapRenderer <global::Android.Graphics.Canvas>( new CanvasRenderer2D(1)); // initialize the gesture detection. this.SetOnTouchListener(this); _scaleGestureDetector = new ScaleGestureDetector( this.Context, this); _rotateGestureDetector = new RotateGestureDetector( this.Context, this); _moveGestureDetector = new MoveGestureDetector( this.Context, this); _tagGestureDetector = new TapGestureDetector( this.Context, this); _makerLayer = new LayerPrimitives( new WebMercator()); // initialize all the caching stuff. _backgroundColor = SimpleColor.FromKnownColor(KnownColor.White).Value; _cacheRenderer = new MapRenderer <global::Android.Graphics.Canvas>( new CanvasRenderer2D(1)); }
private void DrawUserIcon(GeoCoordinate coord, double accuracy) { // If there no coordiantes, we have nothing to do if (coord == null) { return; } if (layerAccuracy == null) { // Create layer for accuracy layerAccuracy = new LayerPrimitives(map.Projection); // Add new accuracy layer map.AddLayer(layerAccuracy); } if (layerUser == null) { // Create layer for user icon layerUser = new LayerPrimitives(map.Projection); // Add layer for user icon map.AddLayer(layerUser); } var repaintUserIcon = coord.Latitude != lastKnownPosition?.Latitude || coord.Longitude != lastKnownPosition?.Longitude; var repaintAccuracy = true; // Stop painting layerAccuracy.Pause(); layerUser.Pause(); if (repaintAccuracy) { layerAccuracy.Clear(); } if (repaintUserIcon) { layerUser.Clear(); } if (IsShowingUserInCenter) { mapView.MapCenter = coord; } if (repaintAccuracy) { var size = 2.2f + mapView.Density * (float)accuracy; layerAccuracy.AddPoint(coord, size > 40 ? 40 : size, SimpleColor.FromArgb(32, 0, 0, 255).Value); } if (repaintUserIcon) { layerUser.AddPoint(coord, mapView.Density * 2.2f, SimpleColor.FromKnownColor(KnownColor.Blue).Value); layerUser.AddPoint(coord, mapView.Density * 1.8f, SimpleColor.FromKnownColor(KnownColor.White).Value); layerUser.AddPoint(coord, mapView.Density * 1.2f, SimpleColor.FromKnownColor(KnownColor.Blue).Value); } layerAccuracy.Resume(); layerUser.Resume(); }
/// <summary> /// Initializes the View property. /// </summary> public override void LoadView() { base.LoadView(); // initialize OsmSharp native hooks. Native.Initialize(); // enable the loggging. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener(new OsmSharp.iOS.UI.Log.ConsoleTraceListener()); // initialize map. var map = new Map(); // add a tile layer. map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png")); // map.AddLayer(new LayerMBTile(SQLiteConnection.CreateFrom( // Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.iOS.UI.Sample.kempen.mbtiles"), "map"))); // add an online osm-data->mapCSS translation layer. //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // add a pre-processed vector data file. // var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( // "OsmSharp.iOS.UI.Sample.default.map"); // map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true))); var primitivesLayer = new LayerPrimitives(map.Projection); primitivesLayer.AddPoint(new GeoCoordinate(51.26371, 4.78601), 10, SimpleColor.FromKnownColor(KnownColor.Blue).Value); map.AddLayer(primitivesLayer); // // define dummy from and to points. var from = new GeoCoordinate(51.261203, 4.780760); var to = new GeoCoordinate(51.267797, 4.801362); // // // deserialize the pre-processed graph. // var routingSerializer = new CHEdgeDataDataSourceSerializer(false); // TagsCollectionBase metaData = null; // var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( // "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing"); // var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true); // // // initialize router. // _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); // // // resolve points. // RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from); // RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to); // // // calculate route. // Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); // RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter()); // _enumerator = route.GetRouteEnumerable(10).GetEnumerator(); // // // add a router layer. // _routeLayer = new LayerRoute(map.Projection); // _routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12); // map.AddLayer(_routeLayer); // define the mapview. _mapView = new MapView(); //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent); _mapView.MapAllowTilt = false; _mapView.Map = map; _mapView.MapMaxZoomLevel = 19; _mapView.MapMinZoomLevel = 0; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601); _mapView.MapZoom = 18; // add markers. // _mapView.AddMarker (from); _mapView.AddMarker(to); // add control. var textView = new UITextView(); textView.Text = "Hey, now there's text on top of the map! Yay!"; textView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f); var textViewControl = new MapControl <UITextView>(textView, from, MapControlAlignmentType.CenterBottom, 75, 75); _mapView.AddControl(textViewControl); // create the route tracker animator. // _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17); // // simulate a number of gps-location update along the calculated route. // Timer timer = new Timer(250); // timer.Elapsed += new ElapsedEventHandler(TimerHandler); // timer.Start(); View = _mapView; }
public MapControl() { _mapSceneManager = new MapSceneManager(); _mapSceneManager.RenderScene += OnRenderScene; _renderingScenes = new Stack <MapRenderingScene>(); _isSuspendNotifyMapViewChanged = false; _isReady = true; _customLayers = new List <Tuple <int, Layer> >(); _canvas = new LayerPrimitives(new WebMercator()); var notifyMapViewChanged = new CommandBinding(MapControlCommands.NotifyMapViewChanged); notifyMapViewChanged.Executed += (sender, args) => NotifyMapViewChanged(); notifyMapViewChanged.CanExecute += (sender, args) => args.CanExecute = true; CommandBindings.Add(notifyMapViewChanged); var zoomInBind = new CommandBinding(MapControlCommands.ZoomIn); zoomInBind.Executed += (sender, args) => ZoomIn(); zoomInBind.CanExecute += (sender, args) => args.CanExecute = true; CommandBindings.Add(zoomInBind); var zoomOutBind = new CommandBinding(MapControlCommands.ZoomOut); zoomOutBind.Executed += (sender, args) => ZoomOut(); zoomOutBind.CanExecute += (sender, args) => args.CanExecute = true; CommandBindings.Add(zoomOutBind); var showFullMapBind = new CommandBinding(MapControlCommands.ShowFullMap); showFullMapBind.Executed += (sender, args) => ShowFullMap(); showFullMapBind.CanExecute += (sender, args) => args.CanExecute = true; CommandBindings.Add(showFullMapBind); _mouseWeelTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) }; _mouseWeelTimer.Tick += (sender, args) => MouseWeelComplete(); _toolTip = new Popup { PlacementTarget = this, Placement = PlacementMode.Relative, AllowsTransparency = true }; _toolTip.MouseEnter += (sender, args) => { _toolTipHideTimer.Stop(); }; _toolTipShowTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) }; _toolTipShowTimer.Tick += (sender, args) => ShowToolTip(); _toolTipHideTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) }; _toolTipHideTimer.Tick += (sender, args) => HideToolTip(); MapMinZoomLevel = 0; MapMaxZoomLevel = 20; MapBoundingBox = MaxMapBoundingBox; }