/// <summary> /// Renders the given scene on the given target for the given view. /// </summary> /// <param name="orginalTarget"></param> /// <param name="scene">Scene.</param> /// <param name="view">View.</param> public bool Render(TTarget orginalTarget, Scene2D scene, View2D view) { var scenes = new List <Scene2D>(); scenes.Add(scene); return(this.Render(orginalTarget, scenes, view)); }
/// <summary> /// Returns all objects in this scene that are visible for the given parameters. /// </summary> /// <param name="zoomFactor"></param> /// <param name="view"></param> /// <returns></returns> internal override IEnumerable<Primitive2D> Get(float zoomFactor, View2D view) { return _primitives.Where((primitive) => { return primitive.IsVisibleIn(view, zoomFactor); }); }
/// <summary> /// Creates a new instance of the <see cref="OsmSharp.UI.Renderer.View2D"/> class. /// </summary> /// <returns>The from bounds.</returns> /// <param name="top">Top.</param> /// <param name="left">Left.</param> /// <param name="bottom">Bottom.</param> /// <param name="right">Right.</param> public static View2D CreateFromBounds(double top, double left, double bottom, double right) { double width; bool xInverted; double centerX = (left + right) / 2.0; if (left > right) { xInverted = true; width = left - right; } else { width = right - left; xInverted = false; } double height; bool yInverted; double centerY = (top + bottom) / 2.0; if (bottom > top) { yInverted = true; height = bottom - top; } else { yInverted = false; height = top - bottom; } return(View2D.CreateFromCenterAndSize(width, height, centerX, centerY, xInverted, yInverted)); }
/// <summary> /// Creates a view based on a center location a zoomfactor and the size of the current viewport. /// </summary> /// <param name="centerX"></param> /// <param name="centerY"></param> /// <param name="pixelsWidth"></param> /// <param name="pixelsHeight"></param> /// <param name="zoomFactor"></param> /// <param name="xInverted"></param> /// <param name="yInverted"></param> /// <param name="angleY"></param> /// <returns></returns> public static View2D CreateFrom(double centerX, double centerY, double pixelsWidth, double pixelsHeight, double zoomFactor, bool xInverted, bool yInverted, Degree angleY) { double realZoom = zoomFactor; double width = pixelsWidth / realZoom; double height = pixelsHeight / realZoom; return(View2D.CreateFromCenterAndSize(width, height, centerX, centerY, xInverted, yInverted, angleY)); }
/// <summary> /// Renders the given scene on the given target for the given view. /// </summary> /// <param name="orginalTarget"></param> /// <param name="scenes">Scene.</param> /// <param name="view">View.</param> public bool Render(TTarget orginalTarget, List <Scene2D> scenes, View2D view) { this.SetRunning(true); if (view == null) { throw new ArgumentNullException("view"); } if (scenes == null) { throw new ArgumentNullException("scenes"); } if (orginalTarget == null) { throw new ArgumentNullException("orginalTarget"); } // create the target wrapper. Target2DWrapper <TTarget> target = this.CreateTarget2DWrapper(orginalTarget); // the on before render event. this.OnBeforeRender(target, scenes, view); // transform the target coordinates or notify the target of the // view coordinate system. this.Transform(target, view); // draw the backcolor. this.DrawBackColor(target, scenes[0].BackColor); bool complete = true; foreach (var scene in scenes) { // render the primitives. complete = complete && this.RenderPrimitives(target, scene, view); if (!complete) { break; } } // the on after render event. this.OnAfterRender(target, scenes, view); // build a cached version. _cachedScene = this.BuildSceneCache(target, _cachedScene, scenes, view); this.SetRunning(false); return(complete); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="OsmSharp.UI.Renderer.View2D"/>. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="OsmSharp.UI.Renderer.View2D"/>.</param> /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current /// <see cref="OsmSharp.UI.Renderer.View2D"/>; otherwise, <c>false</c>.</returns> public override bool Equals(object obj) { View2D view = obj as View2D; if (view != null) { return(view.Rectangle.Equals( this.Rectangle)); } return(false); }
/// <summary> /// Renders the given scene on the given target for the given view. /// </summary> /// <param name="orginalTarget">The target to render to.</param> /// <param name="primitives">The primitives to render.</param> /// <param name="view">The current view.</param> /// <param name="zoomFactor">The current zoom factor.</param> /// <param name="backcolor">The backcolor.</param> public bool Render(TTarget orginalTarget, View2D view, float zoomFactor, IEnumerable <Primitive2D> primitives, int?backcolor) { try { this.SetRunning(true); if (view == null) { throw new ArgumentNullException("view"); } if (primitives == null) { throw new ArgumentNullException("primitives"); } if (orginalTarget == null) { throw new ArgumentNullException("orginalTarget"); } // create the target wrapper. Target2DWrapper <TTarget> target = this.CreateTarget2DWrapper(orginalTarget); // the on before render event. this.OnBeforeRender(target, view); // transform the target coordinates or notify the target of the // view coordinate system. this.Transform(target, view); // render the backcolor. if (backcolor.HasValue) { this.DrawBackColor(target, backcolor.Value); } // render the primitives. bool complete = this.RenderPrimitives(target, view, zoomFactor, primitives); // the on after render event. this.OnAfterRender(target, view); this.SetRunning(false); return(complete); } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("Renderer2D", OsmSharp.Logging.TraceEventType.Error, ex.Message); this.SetRunning(false); throw ex; } }
/// <summary> /// Renders the cached scene on the given target for the given view. /// </summary> /// <param name="orginalTarget"></param> /// <param name="view"></param> public bool RenderCache(TTarget orginalTarget, View2D view) { try { if (_cachedScene != null) { this.SetRunning(true); if (view == null) { throw new ArgumentNullException("view"); } if (orginalTarget == null) { throw new ArgumentNullException("orginalTarget"); } // create the target wrapper. Target2DWrapper <TTarget> target = this.CreateTarget2DWrapper(orginalTarget); // transform the target coordinates or notify the target of the // view coordinate system. this.Transform(target, view); // draw the backcolor. this.DrawBackColor(target, _cachedScene.BackColor); // render the primitives. bool complete = this.RenderPrimitives(target, _cachedScene, view); this.SetRunning(false); return(complete); } return(true); } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("Renderer2D", System.Diagnostics.TraceEventType.Error, ex.Message); this.SetRunning(false); throw ex; } return(false); }
/// <summary> /// Notifies the map change. /// </summary> /// <param name="pixelsWidth"></param> /// <param name="pixelsHeight"></param> /// <param name="view"></param> /// <param name="projection"></param> /// <param name="mapControl"></param> internal void NotifyMapChangeToControl(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection, MapControl mapControl) { if (mapControl != null && mapControl.Handle != IntPtr.Zero) { //this.RemoveView(mapControl.BaseView); if (mapControl.SetLayout (pixelsWidth, pixelsHeight, view, projection)) { //this.AddView(mapControl.BaseView, mapControl.BaseView.LayoutParameters); UpdateViewLayout (mapControl.BaseView, mapControl.LayoutParams); } } }
/// <summary> /// Called when the view on the map containing this layer has changed. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> public void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view) { this.BuildScene(map, zoomFactor, center, view); }
/// <summary> /// Returns all the object from this layer visible for the given parameters. /// </summary> /// <param name="zoomFactor"></param> /// <param name="view"></param> /// <returns></returns> protected internal override IEnumerable<Primitive2D> Get(float zoomFactor, View2D view) { return _scene.Get(view, zoomFactor); }
/// <summary> /// Render the current complete scene. /// </summary> void Render() { try { //if (Monitor.TryEnter(_cacheRenderer, 10)) lock(_cacheRenderer) { try { // use object var rect = _rect; // create the view. var size = (float)System.Math.Max(_rect.Width, _rect.Height); var view = _cacheRenderer.Create((int)(size * _extra), (int)(size * _extra), this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, _invertX, _invertY, this.MapTilt); if (rect.Width == 0) { // only render if a proper size is known. return; } // calculate width/height. var imageWidth = (int)(size * _extra * _scaleFactor); var imageHeight = (int)(size * _extra * _scaleFactor); // create a new bitmap context. var space = CGColorSpace.CreateDeviceRGB(); int bytesPerPixel = 4; int bytesPerRow = bytesPerPixel * imageWidth; int bitsPerComponent = 8; // get old image if available. var image = new CGBitmapContext(null, imageWidth, imageHeight, bitsPerComponent, bytesPerRow, space, // kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Big); long before = DateTime.Now.Ticks; // build the layers list. var layers = new List<Layer>(); for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++) { layers.Add(this.Map[layerIdx]); } // add the internal layer. try { image.SetFillColor(1, 1, 1, 1); image.FillRect(new CGRect( 0, 0, imageWidth, imageHeight)); // notify the map that the view has changed. var normalView = _cacheRenderer.Create((float)_rect.Width, (float)_rect.Height, this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, _invertX, _invertY, this.MapTilt); this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, normalView, view); long afterViewChanged = DateTime.Now.Ticks; OsmSharp.Logging.Log.TraceEvent("OsmSharp.iOS.UI.MapView", TraceEventType.Information, "View change took: {0}ms @ zoom level {1}", (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom); float zoomFactor = this.MapZoom; float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom); // does the rendering. bool complete = _cacheRenderer.Render(new CGContextWrapper(image, new CGRect(0, 0, (int)(size * _extra), (int)(size * _extra))), _map.Projection, layers, view, sceneZoomFactor); long afterRendering = DateTime.Now.Ticks; if (complete) { // there was no cancellation, the rendering completely finished. lock (_bufferSynchronisation) { if (_onScreenBuffer != null && _onScreenBuffer.NativeImage != null) { // on screen buffer. _onScreenBuffer.NativeImage.Dispose(); } // add the newly rendered image again. _onScreenBuffer = new ImageTilted2D(view.Rectangle, new NativeImage(image.ToImage()), float.MinValue, float.MaxValue); // store the previous view. _previouslyRenderedView = view; } // make sure this view knows that there is a new rendering. this.InvokeOnMainThread(SetNeedsDisplay); } long after = DateTime.Now.Ticks; if(complete) { // notify invalidation listener about a succesfull rendering. OsmSharp.Logging.Log.TraceEvent("OsmSharp.iOS.UI.MapView", TraceEventType.Information, "Rendering succesfull after {0}ms.", new TimeSpan(after - before).TotalMilliseconds); _listener.NotifyRenderSuccess(view, zoomFactor, (int)new TimeSpan(after - before).TotalMilliseconds); } else { // rendering incomplete. OsmSharp.Logging.Log.TraceEvent("OsmSharp.iOS.UI.MapView", TraceEventType.Information, "Rendering cancelled.", new TimeSpan(after - before).TotalMilliseconds); } } finally { } } finally { // make sure the object lock is release. Monitor.Exit(_cacheRenderer); } } } catch (Exception) { _cacheRenderer.Reset(); } }
/// <summary> /// Utility method for ensuring a view stays within a bounding box of geo coordinated. /// </summary> /// <param name="center">The map center we want to move to.</param> /// <param name="boundingBox">A GeoCoordinateBox defining the bounding box.</param> /// <param name="view" The current view.</param> /// <returns>Returns a center geo coordinate that is corrected so the view stays within the bounding box.</returns> public GeoCoordinate EnsureViewWithinBoundingBox(GeoCoordinate center, GeoCoordinateBox boundingBox, View2D view) { double[] mapCenterSceneCoords = this.Projection.ToPixel(center); var toViewPort = view.CreateToViewPort(view.Width, view.Height); double mapCenterPixelsX, mapCenterPixelsY; toViewPort.Apply(mapCenterSceneCoords[0], mapCenterSceneCoords[1], out mapCenterPixelsX, out mapCenterPixelsY); //double[] mapCenterPixels = view.ToViewPort(view.Width, view.Height, mapCenterSceneCoords[0], mapCenterSceneCoords[1]); var fromViewPort = view.CreateFromViewPort(view.Height, view.Width); double leftScene, topScene, rightScene, bottomScene; fromViewPort.Apply(mapCenterPixelsX - (view.Width) / 2.0, mapCenterPixelsY - (view.Height) / 2.0, out leftScene, out topScene); //double[] topLeftSceneCoordinates = view.FromViewPort(view.Width, // view.Height, // mapCenterPixels[0] - (view.Width) / 2.0, // mapCenterPixels[1] - (view.Height) / 2.0); GeoCoordinate topLeft = this.Projection.ToGeoCoordinates(leftScene, topScene); //GeoCoordinate topLeft = this.Projection.ToGeoCoordinates(topLeftSceneCoordinates[0], topLeftSceneCoordinates[1]); fromViewPort.Apply(mapCenterPixelsX + (view.Width) / 2.0, mapCenterPixelsY + (view.Height) / 2.0, out rightScene, out bottomScene); //double[] bottomRightSceneCoordinates = view.FromViewPort(view.Width, // view.Height, // mapCenterPixels[0] + (view.Width) / 2.0, // mapCenterPixels[1] + (view.Height) / 2.0); GeoCoordinate bottomRight = this.Projection.ToGeoCoordinates(rightScene, bottomScene); // Early exit when the view is inside the box. if (boundingBox.Contains(topLeft) && boundingBox.Contains(bottomRight)) return center; double viewNorth = topLeft.Latitude; double viewEast = bottomRight.Longitude; double viewSouth = bottomRight.Latitude; double viewWest = topLeft.Longitude; double boxNorth = boundingBox.MaxLat; double boxEast = boundingBox.MaxLon; double boxSouth = boundingBox.MinLat; double boxWest = boundingBox.MinLon; //TODO: Check if the view acrually fits the bounding box, if not resize the view. // Correct all view bounds if neccecary. if (viewNorth > boxNorth) { viewSouth -= viewNorth - boxNorth; viewNorth = boxNorth; } if (viewEast > boxEast) { viewWest -= viewEast - boxEast; viewEast = boxEast; } if (viewSouth < boxSouth) { viewNorth += boxSouth - viewSouth; viewSouth = boxSouth; } if (viewWest < boxWest) { viewEast += boxWest - viewWest; viewWest = boxWest; } // Compute and return corrected map center return new GeoCoordinate(viewSouth + (viewNorth - viewSouth) / 2.0f, viewWest + (viewEast - viewWest) / 2.0f); }
/// <summary> /// Notifies the map change. /// </summary> /// <param name="pixelWidth"></param> /// <param name="pixelsHeight"></param> /// <param name="view"></param> /// <param name="projection"></param> /// <param name="mapMarker"></param> internal void NotifyMapChangeToControl(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection, MapControl mapMarker) { if (mapMarker != null) { mapMarker.SetLayout(pixelsWidth, pixelsHeight, view, projection); } }
/// <summary> /// Notifies change /// </summary> internal void TriggerRendering(bool force) { if (_rect.Width == 0) { return; } OsmSharp.Logging.Log.TraceEvent("MapView.TriggerRendering", TraceEventType.Information, "Rendering triggered!"); // if (Monitor.TryEnter(_cacheRenderer, 300)) // { // entered the exclusive lock area. try { // create the view that would be use for rendering. float size = (float)System.Math.Max(_rect.Width, _rect.Height); View2D view = _cacheRenderer.Create((int)(size * _extra), (int)(size * _extra), this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, _invertX, _invertY, this.MapTilt); // ... and compare to the previous rendered view. if (_previouslyRenderedView != null && view.Equals(_previouslyRenderedView) && !force) { _listener.NotifyRenderSuccess(view, this.MapZoom, 0); return; } _previouslyRenderedView = view; // end existing rendering thread. if (_renderingThread != null && _renderingThread.IsAlive) { if (_cacheRenderer.IsRunning) { _cacheRenderer.CancelAndWait(); } } // start new rendering thread. _renderingThread = new Thread(new ThreadStart(Render)); _renderingThread.Start(); OsmSharp.Logging.Log.TraceEvent("MapView.TriggerRendering", TraceEventType.Information, "Rendering thread started!"); } catch { OsmSharp.Logging.Log.TraceEvent("MapView.TriggerRendering", TraceEventType.Information, "Exception Occured: Rendering thread not started!"); } // finally // { // Monitor.Exit(_cacheRenderer); // } // } }
/// <summary> /// Transforms the target using the specified view. /// </summary> /// <param name="target"></param> /// <param name="view">View.</param> protected abstract void Transform(Target2DWrapper <TTarget> target, View2D view);
/// <summary> /// Renders the given scene on the given target for the given view. /// </summary> /// <param name="orginalTarget"></param> /// <param name="scenes">Scene.</param> /// <param name="view">View.</param> public bool Render(TTarget orginalTarget, List <Scene2D> scenes, View2D view) { try { if (scenes == null || scenes.Count == 0) { // there is nothing to render! return(true); } this.SetRunning(true); if (view == null) { throw new ArgumentNullException("view"); } if (scenes == null) { throw new ArgumentNullException("scenes"); } if (orginalTarget == null) { throw new ArgumentNullException("orginalTarget"); } // create the target wrapper. Target2DWrapper <TTarget> target = this.CreateTarget2DWrapper(orginalTarget); // the on before render event. this.OnBeforeRender(target, scenes, view); // transform the target coordinates or notify the target of the // view coordinate system. this.Transform(target, view); // draw the backcolor. this.DrawBackColor(target, scenes[0].BackColor); bool complete = true; foreach (var scene in scenes) { // render the primitives. complete = complete && this.RenderPrimitives(target, scene, view); if (!complete) { break; } } // the on after render event. this.OnAfterRender(target, scenes, view); // build a cached version. _cachedScene = this.BuildSceneCache(target, _cachedScene, scenes, view); this.SetRunning(false); return(complete); } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("Renderer2D", System.Diagnostics.TraceEventType.Error, ex.Message); this.SetRunning(false); throw ex; } return(false); }
internal override IEnumerable<Renderer.Primitives.Primitive2D> Get(float zoomFactor, View2D view) { throw new System.NotImplementedException(); }
/// <summary> /// Called after rendering is finished or was stopped. /// </summary> /// <param name="target"></param> /// <param name="view"></param> protected virtual void OnAfterRender(Target2DWrapper <TTarget> target, View2D view) { }
/// <summary> /// Renders the primities for the given scene. /// </summary> /// <param name="target"></param> /// <param name="scene"></param> /// <param name="view"></param> private bool RenderPrimitives(Target2DWrapper <TTarget> target, Scene2D scene, View2D view) { // TODO: calculate zoom. float zoom = (float)view.CalculateZoom(target.Width, target.Height); // loop over all primitives in the scene. foreach (Scene2DPrimitive scenePrimitive in scene.Get(view, zoom)) { // the primitive is visible. IScene2DPrimitive primitive = scenePrimitive.Primitive; if (_cancelFlag) { return(false); // stop rendering on cancel and return false for an incomplete rendering. } if (primitive is Point2D) { var point = (Point2D)(primitive); this.DrawPoint(target, point.X, point.Y, point.Color, this.FromPixels(target, view, point.Size)); } else if (primitive is Line2D) { var line = (Line2D)(primitive); this.DrawLine(target, line.X, line.Y, line.Color, this.FromPixels(target, view, line.Width), line.LineJoin, line.Dashes); } else if (primitive is Polygon2D) { var polygon = (Polygon2D)(primitive); this.DrawPolygon(target, polygon.X, polygon.Y, polygon.Color, this.FromPixels(target, view, polygon.Width), polygon.Fill); } else if (primitive is Icon2D) { var icon = (Icon2D)(primitive); this.DrawIcon(target, icon.X, icon.Y, icon.Image); } else if (primitive is Image2D) { var image = (Image2D)(primitive); image.Tag = this.DrawImage(target, image.Left, image.Top, image.Right, image.Bottom, image.ImageData, image.Tag); } else if (primitive is Text2D) { var text = (Text2D)(primitive); this.DrawText(target, text.X, text.Y, text.Text, text.Color, this.FromPixels(target, view, text.Size), text.HaloColor, text.HaloRadius, text.Font); } else if (primitive is LineText2D) { var lineText = (LineText2D)(primitive); this.DrawLineText(target, lineText.X, lineText.Y, lineText.Text, lineText.Color, this.FromPixels(target, view, lineText.Size), lineText.HaloColor, lineText.HaloRadius, lineText.Font); } } return(true); }
/// <summary> /// Called after rendering stops. /// </summary> /// <param name="target"></param> /// <param name="scenes"></param> /// <param name="view"></param> protected virtual void OnAfterRender(Target2DWrapper <TTarget> target, List <Scene2D> scenes, View2D view) { }
/// <summary> /// Creates a view based on a center location a zoomfactor and the size of the current viewport. /// </summary> /// <param name="centerX"></param> /// <param name="centerY"></param> /// <param name="pixelsWidth"></param> /// <param name="pixelsHeight"></param> /// <param name="zoomFactor"></param> /// <param name="xInverted"></param> /// <param name="yInverted"></param> /// <param name="angleY"></param> /// <returns></returns> public static View2D CreateFrom(double centerX, double centerY, double pixelsWidth, double pixelsHeight, double zoomFactor, bool xInverted, bool yInverted) { return(View2D.CreateFrom(centerX, centerY, pixelsWidth, pixelsHeight, zoomFactor, xInverted, yInverted, 0)); }
/// <summary> /// Creates a new instance of the <see cref="OsmSharp.UI.Renderer.View2D"/> class. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="centerX"></param> /// <param name="centerY"></param> /// <param name="directionX"></param> /// <param name="directionY"></param> /// <param name="angleY"></param> /// <returns></returns> public static View2D CreateFromCenterAndSize(double width, double height, double centerX, double centerY, bool directionX, bool directionY) { return(View2D.CreateFromCenterAndSize(width, height, centerX, centerY, directionX, directionY, 0)); }
/// <summary> /// Builds the current cached scene. /// </summary> /// <param name="target"></param> /// <param name="currentCache"></param> /// <param name="currentScenes"></param> /// <param name="view"></param> protected virtual Scene2D BuildSceneCache(Target2DWrapper <TTarget> target, Scene2D currentCache, List <Scene2D> currentScenes, View2D view) { return(null); }
/// <summary> /// Builds the scene. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> private void BuildScene(Map map, float zoomFactor, GeoCoordinate center, View2D view) { // get the indexed object at this zoom. HashSet<ArcId> interpretedObjects; if (!_interpretedObjects.TryGetValue ((int)zoomFactor, out interpretedObjects)) { interpretedObjects = new HashSet<ArcId> (); _interpretedObjects.Add ((int)zoomFactor, interpretedObjects); } // build the boundingbox. var viewBox = view.OuterBox; var box = new GeoCoordinateBox (map.Projection.ToGeoCoordinates (viewBox.Min [0], viewBox.Min [1]), map.Projection.ToGeoCoordinates (viewBox.Max [0], viewBox.Max [1])); foreach (var requestedBox in _requestedBoxes) { if (requestedBox.Contains (box)) { return; } } _requestedBoxes.Add (box); //// set the scene backcolor. //SimpleColor? color = _styleInterpreter.GetCanvasColor (); //_scene.BackColor = color.HasValue // ? color.Value.Value // : SimpleColor.FromArgb (0, 255, 255, 255).Value; // get data. foreach (var arc in _dataSource.GetArcs(box)) { // translate each object into scene object. var arcId = new ArcId () { Vertex1 = arc.Key, Vertex2 = arc.Value.Key }; if (!interpretedObjects.Contains (arcId)) { interpretedObjects.Add (arcId); // create nodes. float latitude, longitude; _dataSource.GetVertex (arcId.Vertex1, out latitude, out longitude); var node1 = CompleteNode.Create (arcId.Vertex1); node1.Coordinate = new GeoCoordinate (latitude, longitude); _dataSource.GetVertex (arcId.Vertex2, out latitude, out longitude); var node2 = CompleteNode.Create (arcId.Vertex2); node2.Coordinate = new GeoCoordinate (latitude, longitude); // create way. var way = CompleteWay.Create (-1); if (arc.Value.Value.Forward) { way.Nodes.Add (node1); way.Nodes.Add (node2); } else { way.Nodes.Add (node2); way.Nodes.Add (node1); } way.Tags.AddOrReplace (_dataSource.TagsIndex.Get (arc.Value.Value.Tags)); _styleInterpreter.Translate (_scene, map.Projection, way); interpretedObjects.Add (arcId); } } }
/// <summary> /// Rotate the specified rotation. /// </summary> /// <param name="rotation">Rotation.</param> private void Rotate(UIRotationGestureRecognizer rotation) { //RectangleF2D rect = _rect; RectangleF rect = this.Frame; if (this.MapAllowTilt && rect.Width > 0) { this.StopCurrentAnimation(); if (rotation.State == UIGestureRecognizerState.Ended) { // View2D rotatedView = _mapViewBefore.RotateAroundCenter ((Radian)rotation.Rotation); // _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; // PointF2D sceneCenter = rotatedView.Rectangle.Center; // _mapCenter = this.Map.Projection.ToGeoCoordinates ( // sceneCenter [0], sceneCenter [1]); this.Change(true); _mapViewBefore = null; } else if (rotation.State == UIGestureRecognizerState.Began) { _mapViewBefore = this.CreateView(rect); } else { //_mapViewBefore = this.CreateView (_rect); View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; _mapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter[0], sceneCenter[1]); this.InvokeOnMainThread(InvalidateMap); } } }
/// <summary> /// Renders the primities for the given scene. /// </summary> /// <param name="target"></param> /// <param name="view"></param> /// <param name="zoomFactor"></param> /// <param name="primitives"></param> private bool RenderPrimitives(Target2DWrapper <TTarget> target, View2D view, float zoomFactor, IEnumerable <Primitive2D> primitives) { try { // calculate current simplification epsilon. double epsilon = Scene2D.CalculateSimplificationEpsilon(new WebMercator(), zoomFactor); // loop over all primitives in the scene. int simplifiedLines = 0; int droppedLines = 0; foreach (Primitive2D primitive in primitives) { // the primitive is visible. if (_cancelFlag) { return(false); // stop rendering on cancel and return false for an incomplete rendering. } if (primitive == null) { continue; } double[] x, y; switch (primitive.Primitive2DType) { case Primitive2DType.Line2D: Line2D line = (Line2D)primitive; x = line.X; y = line.Y; if (x.Length > 4 && line.MaxZoom > zoomFactor * 2 && line.MaxZoom < 512) { // try and simplify. double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y }, epsilon); if (simplified[0].Length < line.X.Length) { simplifiedLines++; x = simplified[0]; y = simplified[1]; } double distance = epsilon * 2; if (simplified[0].Length == 2) { // check if the simplified version is smaller than epsilon. distance = System.Math.Sqrt( System.Math.Pow((simplified[0][0] - simplified[0][1]), 2) + System.Math.Pow((simplified[1][0] - simplified[1][1]), 2)); } if (distance < epsilon) { droppedLines++; continue; } } this.DrawLine(target, x, y, line.Color, this.FromPixels(target, view, line.Width), line.LineJoin, line.Dashes); break; case Primitive2DType.Polygon2D: Polygon2D polygon = (Polygon2D)primitive; x = polygon.X; y = polygon.Y; //if (x.Length > 4 && polygon.MaxZoom > zoomFactor * 2 && polygon.MaxZoom < 512) //{ // try and simplify. // double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y }, // epsilon); // if (simplified[0].Length < polygon.X.Length) // { // simplifiedLines++; // x = simplified[0]; // y = simplified[1]; // } // double distance = epsilon * 2; // if (simplified[0].Length == 2) // { // check if the simplified version is smaller than epsilon. // distance = System.Math.Sqrt( // System.Math.Pow((simplified[0][0] - simplified[0][1]), 2) + // System.Math.Pow((simplified[1][0] - simplified[1][1]), 2)); // } // //if (distance < epsilon) // //{ // // droppedLines++; // // continue; // //} //} this.DrawPolygon(target, x, y, polygon.Color, this.FromPixels(target, view, polygon.Width), polygon.Fill); break; case Primitive2DType.LineText2D: LineText2D lineText = (LineText2D)primitive; this.DrawLineText(target, lineText.X, lineText.Y, lineText.Text, lineText.Color, this.FromPixels(target, view, lineText.Size), lineText.HaloColor, lineText.HaloRadius, lineText.Font); break; case Primitive2DType.Point2D: Point2D point = (Point2D)primitive; this.DrawPoint(target, point.X, point.Y, point.Color, this.FromPixels(target, view, point.Size)); break; case Primitive2DType.Icon2D: Icon2D icon = (Icon2D)primitive; this.DrawIcon(target, icon.X, icon.Y, icon.Image); break; case Primitive2DType.ImageTilted2D: ImageTilted2D imageTilted = (ImageTilted2D)primitive; this.DrawImage(target, imageTilted.Bounds, imageTilted.NativeImage); break; case Primitive2DType.Image2D: Image2D image = (Image2D)primitive; this.DrawImage(target, image.Left, image.Top, image.Right, image.Bottom, image.NativeImage); break; case Primitive2DType.Text2D: Text2D text = (Text2D)primitive; this.DrawText(target, text.X, text.Y, text.Text, text.Color, this.FromPixels(target, view, text.Size), text.HaloColor, text.HaloRadius, text.Font); break; } } return(true); } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("Renderer2D", OsmSharp.Logging.TraceEventType.Error, ex.Message); throw ex; } }
/// <summary> /// Notifies change /// </summary> /// <param name="touch">If set to <c>true</c> change was trigger by touch.</param> internal void Change(bool touch) { if (_rect.Width == 0) { return; } lock (_cacheRenderer) { // create the view that would be use for rendering. View2D view = _cacheRenderer.Create((int)(_rect.Width * _extra), (int)(_rect.Height * _extra), this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, _invertX, _invertY, this.MapTilt); // ... and compare to the previous rendered view. if (_previousRenderedZoom != null && view.Equals(_previousRenderedZoom)) { return; } _previousRenderedZoom = view; // end existing rendering thread. if (_renderingThread != null && _renderingThread.IsAlive) { if (_cacheRenderer.IsRunning) { _cacheRenderer.CancelAndWait(); } } // start new rendering thread. _renderingThread = new Thread(new ThreadStart(Render)); _renderingThread.Start(); // raise touched event. if (touch) { this.RaiseMapTouched(); } } }
/// <summary> /// Returns the size in pixels. /// </summary> /// <returns>The pixels.</returns> /// <param name="target"></param> /// <param name="view">View.</param> /// <param name="sizeInPixels">Size in pixels.</param> protected abstract double FromPixels(Target2DWrapper <TTarget> target, View2D view, double sizeInPixels);
/// <summary> /// Notifies the map change to markers. /// </summary> /// <param name="pixelsWidth">Pixels width.</param> /// <param name="pixelsHeight">Pixels height.</param> /// <param name="view">View.</param> /// <param name="projection">Projection.</param> internal void NotifyMapChangeToMarkers(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection) { foreach (MapMarker marker in _markers) { this.NotifyMapChangeToMarker(pixelsWidth, pixelsHeight, view, projection, marker); } }
/// <summary> /// Renders the given scene on the given target for the given view. /// </summary> /// <param name="orginalTarget">The target to render to.</param> /// <param name="primitives">The primitives to render.</param> /// <param name="view">The current view.</param> /// <param name="zoomFactor">The current zoom factor.</param> public bool Render(TTarget orginalTarget, View2D view, float zoomFactor, IEnumerable <Primitive2D> primitives) { return(this.Render(orginalTarget, view, zoomFactor, primitives, null)); }
/// <summary> /// Sets the layout. /// </summary> /// <param name="pixelsWidth">Pixels width.</param> /// <param name="pixelsHeight">Pixels height.</param> /// <param name="view">View.</param> /// <param name="projection">Projection.</param> internal bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection) { double[] projected = projection.ToPixel (this.Location); double[] locationPixel = view.ToViewPort (pixelsWidth, pixelsHeight, projected [0], projected [1]); // if (locationPixel [0] > 0 && locationPixel [0] < pixelsWidth && // locationPixel [1] > 0 && locationPixel [1] < pixelsHeight) { // set the new location depending on the size of the image and the alignment parameter. double leftMargin = locationPixel [0];// - this.Bitmap.Size.Width / 2.0; double topMargin = locationPixel [1]; switch (_alignment) { case MapMarkerAlignmentType.CenterTop: topMargin = locationPixel [1] + this.Image.Size.Height / 2.0; break; case MapMarkerAlignmentType.CenterBottom: topMargin = locationPixel [1] - this.Image.Size.Height / 2.0; break; } this.Center = new System.Drawing.PointF ((float)leftMargin, (float)topMargin); return true; // } // return false; }
/// <summary> /// Notifies a map change. /// </summary> /// <param name="pixelsWidth"></param> /// <param name="pixelsHeight"></param> /// <param name="view"></param> /// <param name="projection"></param> public void NotifyMapChange(double pixelsWidth, double pixelsHeight, View2D view, Math.Geo.Projections.IProjection projection) { }
/// <summary> /// Called when the view on the map containing this layer has changed. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> /// <param name="extraView"></param> protected internal override void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view, View2D extraView) { this.BuildScene(map, zoomFactor, center, extraView); }
/// <summary> /// Notifies the map change to markers. /// </summary> /// <param name="pixelsWidth">Pixels width.</param> /// <param name="pixelsHeight">Pixels height.</param> /// <param name="view">View.</param> /// <param name="projection">Projection.</param> internal void NotifyMapChangeToControls(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection) { this.NotifyOnBeforeSetLayout(); foreach (var marker in _markers) { this.NotifyMapChangeToControl(pixelsWidth, pixelsHeight, view, projection, marker); } foreach (var control in _controls) { this.NotifyMapChangeToControl(pixelsWidth, pixelsHeight, view, projection, control); } this.NotifyOnAfterSetLayout(); }
/// <summary> /// Builds the scene. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> private void BuildScene(Map map, float zoomFactor, GeoCoordinate center, View2D view) { // build the boundingbox. var viewBox = view.OuterBox; var box = new GeoCoordinateBox(map.Projection.ToGeoCoordinates(viewBox.Min[0], viewBox.Min[1]), map.Projection.ToGeoCoordinates(viewBox.Max[0], viewBox.Max[1])); var zoomLevel = (int)map.Projection.ToZoomLevel(zoomFactor); if (_lastBox != null && _lastBox.Contains(box) && zoomLevel == _lastZoom) { return; } _lastBox = box; _lastZoom = zoomLevel; lock (_index) { _primitives = _index.Get(view, zoomFactor); } }
/// <summary> /// Handles the changed event. /// </summary> private void MapChanged() { OsmSharp.Logging.Log.TraceEvent("MapView.MapChanged", Logging.TraceEventType.Information, "Map changed called."); if (_listener != null) { _listener.Invalidate(); } _previouslyRenderedView = null; _triggeredNotifyMovement = false; _previouslyRenderedView = null; //_cacheRenderer.CancelAndWait (); //this.NotifyMovementByInvoke(); (this as IMapView).Invalidate (); //this.TriggerRendering (true); }
/// <summary> /// Sets layout. /// </summary> /// <param name="pixelsWidth"></param> /// <param name="pixelsHeight"></param> /// <param name="view"></param> /// <param name="projection"></param> /// <param name="afterLayout"></param> /// <returns></returns> internal abstract bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection);
/// <summary> /// Rotate the specified rotation. /// </summary> /// <param name="rotation">Rotation.</param> private void Rotate(UIRotationGestureRecognizer rotation) { CGRect rect = this.Frame; if (this.MapAllowTilt && rect.Width > 0 && this.Map != null) { this.StopCurrentAnimation(); if (rotation.State == UIGestureRecognizerState.Ended) { this.NotifyMovementByInvoke();; _mapViewBefore = null; // raise map touched event. this.RaiseMapTouched(); this.RaiseMapTouchedUp(); } else if (rotation.State == UIGestureRecognizerState.Began) { this.RaiseMapTouchedDown(); _mapViewBefore = this.CreateView(rect); } else { //_mapViewBefore = this.CreateView (_rect); View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)(float)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; this.MapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter[0], sceneCenter[1]); this.NotifyMovementByInvoke(); // raise map move event. this.RaiseMapMove(); } } }
/// <summary> /// Called when the map reports it has changed. /// </summary> void MapChanged() { try { if (!_renderingSuspended) { // rendering is not suspended! // notify map layout of changes. if (this.SurfaceWidth > 0 && this.SurfaceHeight > 0) { // create the current view. View2D view = this.CreateView(); // notify listener. if (view != null) { // only notify listener if there is a view. _listener.NotifyChange(view, this.MapZoom); } } _previouslyRenderedView = null; _previouslyChangedView = null; } } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical, string.Format("An unhandled exception occured:{0}", ex.ToString())); } }
/// <summary> /// The view on this map has changed. Maybe the layers need to load new data, they need to be notified. /// </summary> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> /// <param name="extraView"></param> public void ViewChanged(float zoomFactor, GeoCoordinate center, View2D view, View2D extraView) { var zoomLevel = (float)this.Projection.ToZoomLevel(zoomFactor); lock (_layers) { foreach (var layer in _layers) { if (layer.IsLayerVisibleFor(zoomLevel)) { layer.ViewChanged(this, zoomFactor, center, view, extraView); } } } }
/// <summary> /// Renders the current complete scene. /// </summary> private void Render() { try { if (_renderingSuspended) { // no rendering when rendering is suspended. return; } if (_cacheRenderer.IsRunning) { // cancel previous render. _cacheRenderer.CancelAndWait(); } // make sure only on thread at the same time is using the renderer. lock (_cacheRenderer) { this.Map.ViewChangedCancel(); // build the layers list. var layers = new List<Layer>(); for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++) { // get the layer. if (this.Map[layerIdx].IsVisible) { layers.Add(this.Map[layerIdx]); } } // add the internal layers. layers.Add(_makerLayer); if (this.SurfaceHeight == 0) { // the surface has no height yet. Impossible to render like this. return; } // get old image if available. NativeImage image = null; if (_offScreenBuffer != null) { // get the native image from the off-screen buffer. image = _offScreenBuffer.NativeImage as NativeImage; } // resize image if needed. float sizeX = this.SurfaceWidth; float sizeY = this.SurfaceHeight; //if(this.MapAllowTilt) //{ // when rotation is allowed make sure a square is rendered. // sizeX = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight); // sizeY = System.Math.Max(this.SurfaceWidth, this.SurfaceHeight); //} // float size = System.Math.Max(this.SurfaceHeight, this.SurfaceWidth); if (image == null || image.Image.Width != (int)(sizeX * _extra) || image.Image.Height != (int)(sizeY * _extra)) { // create a bitmap and render there. if (image != null) { // make sure to dispose the old image. image.Dispose(); } image = new NativeImage(global::Android.Graphics.Bitmap.CreateBitmap((int)(sizeX * _extra), (int)(sizeY * _extra), global::Android.Graphics.Bitmap.Config.Argb8888)); } // create and reset the canvas. using (var canvas = new global::Android.Graphics.Canvas(image.Image)) { canvas.DrawColor(new global::Android.Graphics.Color( SimpleColor.FromKnownColor(KnownColor.White).Value)); // create the view. double[] sceneCenter = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude); float mapZoom = this.MapZoom; float sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom); // create the view for this control. float scaledNormalWidth = image.Image.Width / _bufferFactor; float scaledNormalHeight = image.Image.Height / _bufferFactor; var view = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1], scaledNormalWidth * _extra, scaledNormalHeight * _extra, sceneZoomFactor, _invertX, _invertY, this.MapTilt); long before = DateTime.Now.Ticks; OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information, "Rendering Start"); // notify the map that the view has changed. if (_previouslyChangedView == null || !_previouslyChangedView.Equals(view)) { // report change once! var normalView = View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1], scaledNormalWidth, scaledNormalHeight, sceneZoomFactor, _invertX, _invertY, this.MapTilt); this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, normalView, view); _previouslyChangedView = view; long afterViewChanged = DateTime.Now.Ticks; OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information, "View change took: {0}ms @ zoom level {1}", (new TimeSpan(afterViewChanged - before).TotalMilliseconds), this.MapZoom); } // does the rendering. _cacheRenderer.Density = this.MapScaleFactor; bool complete = _cacheRenderer.Render(canvas, _map.Projection, layers, view, (float)this.Map.Projection.ToZoomFactor(this.MapZoom)); long afterRendering = DateTime.Now.Ticks; OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", TraceEventType.Information, "Rendering took: {0}ms @ zoom level {1} and {2}", (new TimeSpan(afterRendering - before).TotalMilliseconds), this.MapZoom, this.MapCenter); if (complete) { // there was no cancellation, the rendering completely finished. // add the result to the scene cache. // add the newly rendered image again. if (_offScreenBuffer == null) { // create the offscreen buffer first. _offScreenBuffer = new ImageTilted2D(view.Rectangle, image, float.MinValue, float.MaxValue); } else { // augment the previous buffer. _offScreenBuffer.Bounds = view.Rectangle; _offScreenBuffer.NativeImage = image; } var temp = _onScreenBuffer; _onScreenBuffer = _offScreenBuffer; _offScreenBuffer = temp; } long after = DateTime.Now.Ticks; if (complete) { // report a successful render to listener. _listener.NotifyRenderSuccess(view, mapZoom, (int)new TimeSpan(after - before).TotalMilliseconds); } } } // notify the the current surface of the new rendering. this.PostInvalidate(); } catch (Exception ex) { // exceptions can be thrown when the mapview is disposed while rendering. // don't worry too much about these, the mapview is garbage anyway. OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical, string.Format("An unhandled exception occured:{0}", ex.ToString())); } }
/// <summary> /// Builds the scene. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> private void BuildScene(Map map, float zoomFactor, GeoCoordinate center, View2D view) { // build the boundingbox. var viewBox = view.OuterBox; var box = new GeoCoordinateBox (map.Projection.ToGeoCoordinates (viewBox.Min [0], viewBox.Min [1]), map.Projection.ToGeoCoordinates (viewBox.Max [0], viewBox.Max [1])); var zoomLevel = (int)map.Projection.ToZoomLevel (zoomFactor); if (_lastBox != null && _lastBox.Contains (box) && zoomLevel == _lastZoom) { return; } _lastBox = box; _lastZoom = zoomLevel; // reset the scene. _scene2DSimple = new Scene2DSimple(); // get from the index. this.Scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value; lock (_sync) { _index.Get (_scene2DSimple, view, zoomFactor); } }
/// <summary> /// Sets the map view. /// </summary> /// <param name="center">Center.</param> /// <param name="mapTilt">Map tilt.</param> /// <param name="mapZoom">Map zoom.</param> public void SetMapView(GeoCoordinate center, Degree mapTilt, float mapZoom) { //this.MapCenter = center; if (this.Width == 0 || this.MapBoundingBox == null) { _mapCenter = center; } else { _mapCenter = this.Map.EnsureViewWithinBoundingBox(center, this.MapBoundingBox, this.CurrentView); } //this.MapTilt = mapTilt; _mapTilt = mapTilt; //this.MapZoom = mapZoom; if (mapZoom > this.MapMaxZoomLevel) { _mapZoomLevel = this.MapMaxZoomLevel; } else if (mapZoom < this.MapMinZoomLevel) { _mapZoomLevel = this.MapMinZoomLevel; } else { _mapZoomLevel = mapZoom; } _previouslyRenderedView = null; _previouslyChangedView = null; (this.Context as Activity).RunOnUiThread(NotifyMovement); }
/// <summary> /// Called when the view on the map has changed. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> /// <param name="extraView"></param> protected internal override void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view, View2D extraView) { // all data is preloaded for now. // when displaying huge amounts of GPX-data use another approach. }
/// <summary> /// Triggers rendering. /// </summary> public void TriggerRendering(bool force) { try { if (this.SurfaceWidth == 0) { // nothing to render yet! return; } // create the view that would be use for rendering. View2D view = _cacheRenderer.Create((int)(this.SurfaceWidth * _extra), (int)(this.SurfaceHeight * _extra), this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, _invertX, _invertY, this.MapTilt); // ... and compare to the previous rendered view. if (!force && _previouslyRenderedView != null && view.Equals(_previouslyRenderedView)) { return; } _previouslyRenderedView = view; // end existing rendering thread. if (_renderingThread != null && _renderingThread.IsAlive) { if (_cacheRenderer.IsRunning) { this.Map.ViewChangedCancel(); _cacheRenderer.CancelAndWait(); } } // start new rendering thread. _renderingThread = new Thread(new ThreadStart(Render)); _renderingThread.Start(); } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical, string.Format("An unhandled exception occured:{0}", ex.ToString())); } }
/// <summary> /// Notifies the map change. /// </summary> /// <param name="pixelsWidth">Pixels width.</param> /// <param name="pixelsHeight">Pixels height.</param> /// <param name="view">View.</param> /// <param name="projection">Projection.</param> public void NotifyMapChange(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection) { this.NotifyOnBeforeSetLayout(); lock (_markers) { if (_markers != null) { foreach (var marker in _markers) { this.NotifyMapChangeToControl(pixelsWidth, pixelsHeight, view, projection, marker); } } } lock(_controls) { if(_controls != null) { foreach (var control in _controls) { this.NotifyMapChangeToControl(pixelsWidth, pixelsHeight, view, projection, control); } } } this.NotifyOnAfterSetLayout(); }
/// <summary> /// Called when the view on the map containing this layer has changed. /// </summary> /// <param name="map"></param> /// <param name="zoomFactor"></param> /// <param name="center"></param> /// <param name="view"></param> internal override void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view) { _interpretedObjects.Clear(); _requestedBoxes.Clear(); this.BuildScene(map, zoomFactor, center, view); }