本文整理汇总了C#中OsmSharp.UI.Renderer.View2D类的典型用法代码示例。如果您正苦于以下问题:C# View2D类的具体用法?C# View2D怎么用?C# View2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
View2D类属于OsmSharp.UI.Renderer命名空间,在下文中一共展示了View2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
/// <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);
});
}
示例2: Rotate
/// <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);
}
}
}
示例3: NotifyMapChangeToControl
/// <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);
}
}
}
示例4: Get
/// <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);
}
示例5: ViewChanged
/// <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);
}
示例6: EnsureViewWithinBoundingBox
/// <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);
}
示例7: TriggerRendering
/// <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);
// }
// }
}
示例8: MapChanged
/// <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()));
}
}
示例9: SetLayout
/// <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);
示例10: BuildScene
/// <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);
}
}
示例11: ViewChanged
/// <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);
}
示例12: SetLayout
/// <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;
}
示例13: NotifyMapChangeToMarkers
/// <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);
}
}
示例14: Change
/// <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();
}
}
}
示例15: NotifyMapChangeToControl
/// <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);
}
}