Exemplo n.º 1
0
        /// <summary>
        /// Zoom to the given makers list.
        /// </summary>
        /// <param name="marker"></param>
        public void ZoomToMarkers(List <MapMarker> markers, double percentage)
        {
//            float height = _rect.Height;
//            float width = _rect.Width;
            float      width  = this.Frame.Width;
            float      height = this.Frame.Height;
            RectangleF rect   = this.Frame;

            if (width > 0)
            {
                PointF2D[] points = new PointF2D[markers.Count];
                for (int idx = 0; idx < markers.Count; idx++)
                {
                    points[idx] = new PointF2D(this.Map.Projection.ToPixel(markers[idx].Location));
                }
                View2D view = this.CreateView(rect);
//                View2D view = this.CreateView(this.Frame);
                View2D fittedView = view.Fit(points, percentage);

                float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom(
                                                                        width, height));
                GeoCoordinate center = this.Map.Projection.ToGeoCoordinates(
                    fittedView.Center[0], fittedView.Center[1]);

                _mapCenter   = center;
                this.MapZoom = zoom;

                this.Change(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Zooms to the given list of markers.
        /// </summary>
        /// <param name="markers"></param>
        /// <param name="percentage"></param>
        public void ZoomToMarkers(List <MapMarker> markers, double percentage)
        {
            float height = this.SurfaceHeight;
            float width  = this.SurfaceWidth;

            if (width > 0)
            {
                PointF2D[] points = new PointF2D[markers.Count];
                for (int idx = 0; idx < markers.Count; idx++)
                {
                    points [idx] = new PointF2D(this.Map.Projection.ToPixel(markers [idx].Location));
                }
                View2D view       = this.CreateView();
                View2D fittedView = view.Fit(points, percentage);

                float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom(
                                                                        width, height));
                GeoCoordinate center = this.Map.Projection.ToGeoCoordinates(
                    fittedView.Center [0], fittedView.Center [1]);

                this.SetMapView(center, this.MapTilt, zoom);
            }
            else
            {
                _latestZoomCall = new MapViewMarkerZoomEvent()
                {
                    Markers    = markers,
                    Percentage = percentage
                };
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="mapCSS"></param>
        /// <returns></returns>
        private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS)
        {
            // create projection.
            WebMercator projection = new WebMercator();

            double[] topLeft     = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1));
            double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1));

            // create view (this comes down to (1,1,-1,-1) for a size of 100x100).
            View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]);
            //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true);

            // create graphics
            Bitmap   rendering         = new Bitmap(100, 100);
            Graphics renderingGraphics = Graphics.FromImage(rendering);

            renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            renderingGraphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            renderingGraphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            renderingGraphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // create renderer.
            GraphicsRenderer2D     graphicsRenderer = new GraphicsRenderer2D();
            MapRenderer <Graphics> renderer         = new MapRenderer <Graphics>(graphicsRenderer);

            // create map.
            OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map();
            map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection));

            // notify the map that there was a view change!
            map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view);

            // ... and finally do the actual rendering.
            renderer.Render(Graphics.FromImage(rendering), map, view);

            //rendering.Save(@"c:\temp\rendering.bmp");

            return(rendering);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Zooms to the given list of markers.
        /// </summary>
        /// <param name="controls"></param>
        /// <param name="percentage"></param>
        public void ZoomToControls(List <MapControl> controls, double percentage)
        {
            try
            {
                float height = this.SurfaceHeight;
                float width  = this.SurfaceWidth;
                if (width > 0)
                {
                    PointF2D[] points = new PointF2D[controls.Count];
                    for (int idx = 0; idx < controls.Count; idx++)
                    {
                        points[idx] = new PointF2D(this.Map.Projection.ToPixel(controls[idx].Location));
                    }
                    View2D view       = this.CreateView();
                    View2D fittedView = view.Fit(points, percentage);

                    float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom(
                                                                            width, height));
                    GeoCoordinate center = this.Map.Projection.ToGeoCoordinates(
                        fittedView.Center[0], fittedView.Center[1]);

                    this.SetMapView(center, this.MapTilt, zoom);
                }
                else
                {
                    _latestZoomCall = new MapViewControlZoomEvent()
                    {
                        Controls   = controls,
                        Percentage = percentage
                    };
                }
            }
            catch (Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface.ZoomToMarkers", TraceEventType.Critical,
                                                string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Zooms to the given list of markers.
        /// </summary>
        /// <param name="markers"></param>
        public void ZoomToMarkers(List <MapMarker> markers, double percentage)
        {
            float height = this.LayoutParameters.Height;
            float width  = this.LayoutParameters.Width;

            if (width > 0)
            {
                PointF2D[] points = new PointF2D[markers.Count];
                for (int idx = 0; idx < markers.Count; idx++)
                {
                    points[idx] = markers[idx].Location;
                }
                View2D view       = this.CreateView();
                View2D fittedView = view.Fit(points);

                float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom(
                                                                        width, height));
                GeoCoordinate center = this.Map.Projection.ToGeoCoordinates(
                    view.Center[0], view.Center[1]);

                (this as IMapView).SetMapView(center, this.MapTilt, zoom);
            }
        }