示例#1
0
        /// <summary>
        /// Rotate the specified rotation.
        /// </summary>
        /// <param name="rotation">Rotation.</param>
        private void Rotate(UIRotationGestureRecognizer rotation)
        {
            RectangleF rect = this.Frame;

            if (this.MapAllowTilt &&
                rect.Width > 0)
            {
                this.StopCurrentAnimation();
                if (rotation.State == UIGestureRecognizerState.Ended)
                {
                    this.NotifyMovementByInvoke();;

                    _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.NotifyMovementByInvoke();
                }
            }
        }
示例#2
0
        /// <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()));
            }
        }
示例#3
0
        /// <summary>
        /// Creates a view.
        /// </summary>
        /// <returns></returns>
        public View2D CreateView()
        {
            try
            {
                if (this.Map != null && this.Map.Projection != null && this.MapCenter != null)
                { // only create a view when a map is set and a valid mapcenter is present.
                    float height = this.SurfaceHeight / _bufferFactor;
                    float width  = this.SurfaceWidth / _bufferFactor;

                    // calculate the center/zoom in scene coordinates.
                    var sceneCenter     = this.Map.Projection.ToPixel(this.MapCenter.Latitude, this.MapCenter.Longitude);
                    var sceneZoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                    // create the view for this control.
                    return(View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                             width, height, sceneZoomFactor,
                                             _invertX, _invertY, this.MapTilt));
                }
            }
            catch (Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface.CreateView()", TraceEventType.Critical,
                                                string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
            return(null);
        }
        /// <summary>
        /// Returns the size in pixels.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="view"></param>
        /// <param name="sizeInPixels"></param>
        /// <returns></returns>
        protected override double FromPixels(Target2DWrapper <GraphicsDevice> target,
                                             View2D view, double sizeInPixels)
        {
            double scaleX = target.Width / view.Width;

            return(sizeInPixels / scaleX);
        }
示例#5
0
 /// <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>
 public override IEnumerable <Primitive2D> Get(float zoomFactor, View2D view)
 {
     return(_primitives.Where((primitive) =>
     {
         return primitive.IsVisibleIn(view, zoomFactor);
     }));
 }
        /// <summary>
        /// Returns all objects visible for the given parameters.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        /// <returns></returns>
        public IEnumerable <Primitive2D> Get(View2D view, float zoomFactor)
        {
            ISpatialIndexReadonly <Primitive2D> sceneAtZoom = _rTrees[0];

            // find the part of this scene containing the objects for the requested zoom.
            for (int idx = 1; idx < _zoomFactors.Length; idx++)
            {
                if (zoomFactor <= _zoomFactors[idx])
                {
                    sceneAtZoom = _rTrees[idx];
                }
                else
                {
                    break;
                }
            }

            if (sceneAtZoom != null)
            {
                var primitives = new SortedSet <Primitive2D>(LayerComparer.GetInstance());
                foreach (var primitive in sceneAtZoom.Get(view.OuterBox))
                {
                    primitives.Add(primitive);
                }
                return(primitives);
            }
            return(new List <Primitive2D>());
        }
示例#7
0
        /// <summary>
        /// Draws the view within the specified rectangle.
        /// </summary>
        /// <param name="rect">Rect.</param>
        public override void Draw(System.Drawing.RectangleF rect)
        {
            _rect = rect;
            base.Draw(rect);

            lock (_bufferSynchronisation)
            {
                // recreate the view.
                View2D view       = this.CreateView(this.Frame);
                float  zoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

                // call the canvas renderer.
                CGContext context = UIGraphics.GetCurrentContext();

                if (context != null)
                {
                    context.InterpolationQuality = CGInterpolationQuality.None;
                    context.SetShouldAntialias(false);
                    context.SetBlendMode(CGBlendMode.Copy);
                    context.SetAlpha(1);

                    long afterViewChanged      = DateTime.Now.Ticks;
                    CGContextRenderer renderer = new CGContextRenderer(1);
                    renderer.Render(
                        new CGContextWrapper(context, this.Frame),
                        view,
                        zoomFactor,
                        new Primitive2D[] { _onScreenBuffer });
                    long afterRendering = DateTime.Now.Ticks;
                }
            }
        }
示例#8
0
        public void View2DTestCreateFromXYDifference()
        {
            double x, y;
            var    view = View2D.CreateFrom(0, 0, 400, 200, 1, false, false);

            // test result.
            Assert.AreEqual(view.LeftTop[0], -200);
            Assert.AreEqual(view.RightTop[0], 200);
            Assert.AreEqual(view.RightBottom[1], -100);
            Assert.AreEqual(view.RightTop[1], 100);
            Assert.IsTrue(view.Contains(0, 0));
            var fromMatrix = view.CreateFromViewPort(2000, 1000);

            // var topLeft = view.FromViewPort(2000, 1000, 0, 0);
            fromMatrix.Apply(0, 0, out x, out y);
            Assert.AreEqual(x, -200);
            Assert.AreEqual(y, -100);
            // var bottomRight = view.FromViewPort(2000, 1000, 2000, 1000);
            fromMatrix.Apply(2000, 1000, out x, out y);
            Assert.AreEqual(x, 200);
            Assert.AreEqual(y, 100);

            var toMatrix = view.CreateToViewPort(2000, 1000);

            // var viewTopLeft = view.ToViewPort(2000, 1000, view.LeftTop[0], view.RightTop[1]);
            toMatrix.Apply(view.LeftTop[0], view.RightTop[1], out x, out y);
            Assert.AreEqual(0, x);
            Assert.AreEqual(1000, y);
            // var viewBottomRight = view.ToViewPort(2000, 1000, view.RightBottom[0], view.RightBottom[1]);
            toMatrix.Apply(view.RightBottom[0], view.RightBottom[1], out x, out y);
            Assert.AreEqual(2000, x);
            Assert.AreEqual(0, y);
        }
示例#9
0
        /// <summary>
        /// Returns all primitives 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)
        {
            var primitives = new List <Primitive2D>();

            lock (_cache)
            {
                foreach (var tile in _cache)
                {
                    if (tile.Value.IsVisibleIn(view, zoomFactor))
                    {
                        Image2D temp;
                        var     minZoom = _projection.ToZoomFactor(tile.Key.Zoom - _zoomMinOffset);
                        var     maxZoom = _projection.ToZoomFactor(tile.Key.Zoom + (1 - _zoomMinOffset));
                        if (zoomFactor < maxZoom && zoomFactor > minZoom)
                        {
                            _cache.TryGet(tile.Key, out temp);
                            primitives.Add(tile.Value);
                        }
                    }
                }
            }

            primitives.Sort(this);
            return(primitives);
        }
示例#10
0
        /// <summary>
        /// Notifies that there was movement.
        /// </summary>
        private void NotifyMovement()
        {
            //// invalidate the current view.
            //this.Invalidate();

            // notify map layout of changes.
            if (this.Width > 0 && this.Height > 0)
            {
                // create the view.
                View2D view = _renderer.Create(this.Width, this.Height,
                                               this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                               this.MapCenter, false, true);

                _mapView.NotifyMapChange(this.Width, this.Height, view, this.Map.Projection);

                this.SetOrtho(view);
                //// build the layers list.
                //var layers = new List<ILayer>();
                //for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                //{
                //    // get the layer.
                //    layers.Add(this.Map[layerIdx]);
                //}

                //_renderer.Render(_target,
                //     layers,
                //     view);
            }
        }
示例#11
0
 /// <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);
 }
示例#12
0
        public Bitmap Render(int x, int y, int zoom, double width, int tileSize)
        {
            const double magicMaster = 9105.7453358554949742220244056229;

            var    zoomRate     = (float)(magicMaster * width);
            int    tiles        = 1 << zoom;
            double tileGeoWidth = width / tiles;

            double movex = tiles == 1 ? 0 : tileGeoWidth * (tiles / 2 - x) - tileGeoWidth / 2;
            double movey = tiles == 1 ? 0 : tileGeoWidth * (tiles / 2 - y) - tileGeoWidth / 2;

            var center = new GeoCoordinate(movey, -movex);

            double baseZoomFactor = 100f * ((double)tileSize / zoomRate);

            float zoomFactor = Convert.ToSingle(baseZoomFactor * tiles);

            var      image  = new Bitmap(tileSize, tileSize);
            Graphics target = Graphics.FromImage(image);

            target.SmoothingMode      = SmoothingMode.HighQuality;
            target.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            target.CompositingQuality = CompositingQuality.HighQuality;
            target.InterpolationMode  = InterpolationMode.HighQualityBicubic;

            target.FillRectangle(Brushes.Red, 0, 0, tileSize, tileSize);
            View2D visibleView = Renderer.Create(tileSize, tileSize, Map, zoomFactor, center, false, true);

            Map.ViewChanged(zoomFactor, center, visibleView, visibleView);
            Renderer.Render(target, Map, visibleView, visibleView, zoomFactor);

            target.Dispose();
            return(image);
        }
示例#13
0
        /// <summary>
        /// Notifies change.
        /// </summary>
        public void TriggerRendering(bool force)
        {
            // notify map layout of changes.
            if (this.Width > 0 && this.Height > 0)
            {
                // create the view.
                View2D view = _renderer.Create(this.Width, this.Height,
                                               this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                               this.MapCenter, false, true);

                // notify the map that the view has changed.
                this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                     view);

                _mapView.NotifyMapChange(this.Width, this.Height, view, this.Map.Projection);

                this.SetOrtho(view);

                // build the layers list.
                var layers = new List <Layer>();
                for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
                {
                    // get the layer.
                    layers.Add(this.Map[layerIdx]);
                }

                _renderer.Render(_target,
                                 layers,
                                 view,
                                 (float)this.Map.Projection.ToZoomFactor(this.MapZoom));
            }
        }
示例#14
0
        /// <summary>
        /// Draws the view within the specified rectangle.
        /// </summary>
        /// <param name="rect">Rect.</param>
        public override void Draw(System.Drawing.RectangleF rect)
        {
            _rect = rect;
            base.Draw(rect);

            lock (_cachedScene) {
                // recreate the view.
                //View2D view = this.CreateView (_rect);
                View2D view = this.CreateView(this.Frame);

                // call the canvas renderer.
                CGContext context = UIGraphics.GetCurrentContext();

                if (context != null)
                {
                    context.InterpolationQuality = CGInterpolationQuality.None;
                    context.SetShouldAntialias(false);
                    context.SetBlendMode(CGBlendMode.Copy);
                    context.SetAlpha(1);

                    long afterViewChanged      = DateTime.Now.Ticks;
                    CGContextRenderer renderer = new CGContextRenderer(1);
//					renderer.Render (new CGContextWrapper (context, _rect),
                    //					                _cachedScene, view);
                    renderer.Render(new CGContextWrapper(context, this.Frame),
                                    _cachedScene, view);
                    long afterRendering = DateTime.Now.Ticks;
                }
            }
        }
示例#15
0
        /// <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.
            if (_scene2DSimple == null)
            {
                _scene2DSimple = new Scene2DSimple();
            }
            _scene2DSimple.Clear();

            // get from the index.
            this.Scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value;
            lock (_sync) {
                _index.Get(_scene2DSimple, view, zoomFactor);
            }
        }
示例#16
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);
            }
        }
示例#17
0
        /// <summary>
        /// Called when the tap gesture recognizer detects a double tap.
        /// </summary>
        /// <param name="tap">Tap.</param>
        private void DoubleTap(UITapGestureRecognizer tap)
        {
            //RectangleF2D rect = _rect;
            RectangleF rect = this.Frame;

            if (rect.Width > 0 && rect.Height > 0)
            {
                this.StopCurrentAnimation();

                View2D        view             = this.CreateView(rect);
                PointF        location         = tap.LocationInView(this);
                double[]      sceneCoordinates = view.FromViewPort(rect.Width, rect.Height, location.X, location.Y);
                GeoCoordinate geoLocation      = this.Map.Projection.ToGeoCoordinates(sceneCoordinates [0], sceneCoordinates [1]);

                if (this.DoubleMapTapEvent != null)
                {
                    this.DoubleMapTapEvent(geoLocation);
                }
                else
                {
                    // minimum zoom.
                    float tapRequestZoom = (float)System.Math.Max(_mapZoom + 1, 19);
                    _doubleTapAnimator.Start(geoLocation, tapRequestZoom, new TimeSpan(0, 0, 1));
                }
            }
        }
示例#18
0
文件: MapView.cs 项目: rolo2012/ui
 /// <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();
 }
示例#19
0
 /// <summary>
 /// A way for the surface to complain that it is invalid.
 /// </summary>
 public override void Invalidate()
 {
     lock (this)
     {
         _latestTriggeredView = null;
     }
 }
示例#20
0
        /// <summary>
        /// Transforms the target using the specified view.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="view">View.</param>
        protected override void Transform(Target2DWrapper <CGContextWrapper> target, View2D view)
        {
            _view   = view;
            _target = target;

            _scaleX = (float)(target.Width / view.Width);
        }
        /// <summary>
        /// Fills the given simple scene with objects inside the given view and for the given zoomFactor.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            // check what is in the non-simplified scene.
            IScene2DPrimitivesSource simpleSource = this.GetNonSimplifiedStream();

            simpleSource.Get(scene, view, zoomFactor);

            // check what index this zoomfactor is for.
            int idx = this.SearchForScene(zoomFactor);

            if (idx >= 0)
            {     // the index was found.
                if (!_loadedScenes.TryGetValue(idx, out simpleSource))
                { // the scene was not found.
                    long position = _index.SceneIndexes[idx];
                    _stream.Seek(position, SeekOrigin.Begin);
                    LimitedStream stream = new LimitedStream(_stream);
                    //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
                    //simpleSource = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
                    OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
                        new Styled.Scene2DStyledSerializer();
                    simpleSource = serializer.Deserialize(stream, true);
                    _loadedScenes.Add(idx, simpleSource);
                }
                simpleSource.Get(scene, view, zoomFactor);

                OsmSharp.Logging.Log.TraceEvent("Scene2DLayeredSource", System.Diagnostics.TraceEventType.Verbose,
                                                string.Format("Deserialized from scene at zoom {0} and idx {1}.", zoomFactor, idx));
            }
        }
示例#22
0
        /// <summary>
        /// Raises the mousemove event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            var currentCoordinates = new double[] { e.X, e.Y };

            if (this.MapAllowPan &&
                e.Button == MouseButtons.Left &&
                _draggingCoordinates != null)
            {
                var delta = new double[] { _draggingCoordinates[0] - currentCoordinates[0],
                                           (_draggingCoordinates[1] - currentCoordinates[1]) };

                var newCenter = new double[] { this.Width / 2.0f + delta[0], this.Height / 2.0f + delta[1] };

                this.MapCenter = _oldCenter;

                View2D view = _renderer.Create(this.Width, this.Height, this.Map,
                                               (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, false, true);

                double x, y;
                var    fromMatrix = view.CreateFromViewPort(this.Width, this.Height);
                fromMatrix.Apply(newCenter[0], newCenter[1], out x, out y);

                // project to new center.
                this.MapCenter = this.Map.Projection.ToGeoCoordinates(x, y);

                // notify the map.
                this.QueueNotifyMapViewChanged();
            }
            this.RaiseOnMapMouseMove(e);
        }
示例#23
0
        /// <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]);

            // set the new location depending on the size of the image and the alignment parameter.
            double leftMargin = locationPixel[0];
            double topMargin  = locationPixel[1];

            leftMargin = locationPixel[0] - (this.LayoutParameters as FrameLayout.LayoutParams).Width / 2.0;

            switch (_alignment)
            {
            case MapMarkerAlignmentType.Center:
                topMargin = locationPixel[1] - (this.LayoutParameters as FrameLayout.LayoutParams).Height / 2.0;
                break;

            case MapMarkerAlignmentType.CenterTop:
                break;

            case MapMarkerAlignmentType.CenterBottom:
                topMargin = locationPixel[1] - (this.LayoutParameters as FrameLayout.LayoutParams).Height;
                break;
            }

            (this.LayoutParameters as FrameLayout.LayoutParams).LeftMargin = (int)leftMargin;
            (this.LayoutParameters as FrameLayout.LayoutParams).TopMargin  = (int)topMargin;
            return(true);
        }
示例#24
0
        /// <summary>
        /// Triggers rendering.
        /// </summary>
        public void TriggerRendering(bool force)
        {
            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();
        }
示例#25
0
        /// <summary>
        /// Notifies that there was movement.
        /// </summary>
        private void NotifyMovement()
        {
            try
            {
                // invalidate the current view.
                this.Invalidate();

                // notify map layout of changes.
                if (this.SurfaceWidth > 0 && this.SurfaceHeight > 0)
                {
                    // create the current view.
                    View2D view = this.CreateView();

                    // notify map change to reposition markers.
                    _mapView.NotifyMapChange(this.SurfaceWidth, this.SurfaceHeight, view, this.Map.Projection);

                    // notify listener.
                    _listener.NotifyChange(view, this.MapZoom);
                }
            }
            catch (Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("MapViewSurface", TraceEventType.Critical,
                                                string.Format("An unhandled exception occured:{0}", ex.ToString()));
            }
        }
示例#26
0
        /// <summary>
        /// Raises the draw event.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        protected override void OnDraw(global::Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            // set the height/width.
            if (_surfaceHeight != canvas.Height ||
                _surfaceWidth != canvas.Width)
            {
                _surfaceHeight = canvas.Height;
                _surfaceWidth  = canvas.Width;

                // trigger rendering.
                this.TriggerRendering();
            }

            // render only the cached scene.
            canvas.DrawColor(new global::Android.Graphics.Color(_backgroundColor));
            View2D view       = this.CreateView();
            float  zoomFactor = (float)this.Map.Projection.ToZoomFactor(this.MapZoom);

            _renderer.SceneRenderer.Render(
                canvas,
                view,
                zoomFactor,
                new Primitive2D[] { _onScreenBuffer });
        }
示例#27
0
 /// <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>
 public void ViewChanged(float zoomFactor, GeoCoordinate center, View2D view)
 {
     foreach (var layer in _layers)
     {
         layer.ViewChanged(this, zoomFactor, center, view);
     }
 }
示例#28
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
                };
            }
        }
示例#29
0
        /// <summary>
        /// Raises the layout event.
        /// </summary>
        /// <param name="changed">If set to <c>true</c> changed.</param>
        /// <param name="left">Left.</param>
        ///( <param name="top">Top.</param>
        /// <param name="right">Right.</param>
        /// <param name="bottom">Bottom.</param>
        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            _target.Width  = this.Width;
            _target.Height = this.Height;

            // create the view.
            View2D view = _renderer.Create(this.Width, this.Height,
                                           this.Map, (float)this.Map.Projection.ToZoomFactor(this.MapZoom),
                                           this.MapCenter, false, true);

            this.SetOrtho(view);

            // notify the map that the view has changed.
            this.Map.ViewChanged((float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter,
                                 view);

            // build the layers list.
            var layers = new List <Layer>();

            for (int layerIdx = 0; layerIdx < this.Map.LayerCount; layerIdx++)
            {
                // get the layer.
                layers.Add(this.Map[layerIdx]);
            }

            _renderer.Render(_target,
                             layers,
                             view,
                             (float)this.Map.Projection.ToZoomFactor(this.MapZoom));
        }
示例#30
0
        /// <summary>
        /// Raises the mousemove event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (e.Button == MouseButtons.Left &&
                _draggingCoordinates != null)
            {
                var currentCoordinates = new double[] { e.X, e.Y };
                var delta = new double[] { _draggingCoordinates[0] - currentCoordinates[0],
                                           (_draggingCoordinates[1] - currentCoordinates[1]) };

                var newCenter = new double[] { this.Width / 2.0f + delta[0], this.Height / 2.0f + delta[1] };

                this.Center = _oldCenter;

                View2D view = _renderer.Create(this.Width, this.Height, this.Map,
                                               (float)this.Map.Projection.ToZoomFactor(this.ZoomLevel), this.Center, false, true);

                double[] sceneCenter = view.FromViewPort(this.Width, this.Height,
                                                         newCenter[0], newCenter[1]);

                // project to new center.
                this.Center = this.Map.Projection.ToGeoCoordinates(sceneCenter[0], sceneCenter[1]);

                // notify the map.
                this.QueueNotifyMapViewChanged();
            }
        }
        /// <summary>
        /// Adds all primitives inside the given box for the given zoom.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            // get all primitives.
            IEnumerable<Scene2DEntry> entries =
                _index.Get(view.OuterBox);

            foreach (var scene2DEntry in entries)
            {
                scene.AddPrimitive(scene2DEntry.Layer, scene2DEntry.Id, scene2DEntry.Scene2DPrimitive);
            }
        }
示例#32
0
        /// <summary>
        /// Returns true if the object is visible on the view.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="view">View.</param>
        /// <param name="zoom"></param>
        public override bool IsVisibleIn(View2D view, float zoom)
        {
            if (this.MinZoom > zoom || this.MaxZoom < zoom)
            { // outside of zoom bounds!
                return false;
            }

            return _bounds.Overlaps(view.OuterBox);
        }
示例#33
0
        /// <summary>
        /// Fills the given simple scene with objects inside the given view and for the given zoomFactor.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            lock (_stream) { // make sure there is only synchonous access to the stream.
                // check what is in the non-simplified scene.
                IScene2DPrimitivesSource simpleSource = this.GetNonSimplifiedStream ();
                simpleSource.Get (scene, view, zoomFactor);

                // check what index this zoomfactor is for.
                int idx = this.SearchForScene (zoomFactor);
                if (idx >= 0) { // the index was found.
                    if (!_loadedScenes.TryGetValue (idx, out simpleSource)) { // the scene was not found.
                        long position = _index.SceneIndexes [idx];
                        _stream.Seek (position, SeekOrigin.Begin);
                        LimitedStream stream = new LimitedStream (_stream);
                        //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
                        //simpleSource = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
                        OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
                            new Styled.Scene2DStyledSerializer ();
                        simpleSource = serializer.Deserialize (stream, true);
                        _loadedScenes.Add (idx, simpleSource);
                    }
                    simpleSource.Get (scene, view, zoomFactor);

                    OsmSharp.Logging.Log.TraceEvent ("Scene2DLayeredSource", System.Diagnostics.TraceEventType.Verbose,
                        string.Format ("Deserialized from scene at zoom {0} and idx {1} synchronized.", zoomFactor, idx));
                }
            }
        }
示例#34
0
文件: Polygon2D.cs 项目: JoeCooper/ui
 /// <summary>
 /// Returns true if the object is visible on the view.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="view">View.</param>
 public override bool IsVisibleIn(View2D view)
 {
     if (view.OverlapsWithBox(MinX, MinY, MaxX, MaxY))
     {
         return true; // maybe a better hittest?
     }
     return false;
 }
示例#35
0
文件: Icon2D.cs 项目: JoeCooper/ui
        /// <summary>
        /// Returns true if the object is visible in the given view.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="view">View.</param>
        /// <param name="zoom"></param>
        public override bool IsVisibleIn(View2D view, float zoom)
        {
            if (this.MinZoom > zoom || this.MaxZoom < zoom)
            { // outside of zoom bounds!
                return false;
            }

            return this.IsVisibleIn(view);
        }
示例#36
0
        private void buttonShootPhotons_Click( object sender, EventArgs e )
        {
            //////////////////////////////////////////////////////////////////////////
            // 1] Shoot the photons and store the result into the structured buffer
            m_CS_PhotonShooter.Use();

            m_SB_Random.SetInput( 0 );
            m_SB_PhaseQuantile.SetInput( 1 );
            m_SB_PhotonOut.SetOutput( 0 );

            m_CB_PhotonShooterInput.m.MaxScattering = 100;
            m_CB_PhotonShooterInput.m.InitialPosition = new float2( floatTrackbarControlPositionX.Value, floatTrackbarControlPositionZ.Value );	// Center of the cube side
            m_CB_PhotonShooterInput.m.InitialIncidence = new float2( floatTrackbarControlOrientationPhi.Value * (float) Math.PI / 180.0f, floatTrackbarControlOrientationTheta.Value * (float) Math.PI / 180.0f );			// Vertical incidence
            m_CB_PhotonShooterInput.m.CubeSize = floatTrackbarControlCubeSize.Value;	// Try a 100m thick cube
            //			m_CB_PhotonShooterInput.m.SigmaScattering = 0.5f;
            m_CB_PhotonShooterInput.m.SigmaScattering = 0.04523893421169302263386206471922f;	// re=6µm Gamma=2 N0=4e8   Sigma_t = N0 * PI * re²
            m_CB_PhotonShooterInput.m.FullSurface = (uint)(checkBoxFullSurface.Checked ? 1 : 0);
                                                    //	mean free path = 22.1048m

            int	BatchesCount = PHOTONS_COUNT / PHOTON_BATCH_SIZE;
            for ( int BatchIndex=0; BatchIndex < BatchesCount; BatchIndex++ )
            {
                m_CB_PhotonShooterInput.m.BatchIndex = (uint) BatchIndex;
                m_CB_PhotonShooterInput.UpdateData();

                m_CS_PhotonShooter.Dispatch( 1, 1, 1 );

                m_Device.Present( true );
                progressBar1.Value = progressBar1.Maximum * (1+BatchIndex) / BatchesCount;
                Application.DoEvents();
            }

            m_SB_PhotonOut.RemoveFromLastAssignedSlots();

            //////////////////////////////////////////////////////////////////////////
            // Splat photons
            m_Tex_Photons.RemoveFromLastAssignedSlots();
            m_Device.Clear( m_Tex_Photons, new float4( 0, 0, 0, 0 ) );

            m_SB_PhotonOut.SetInput( 0 );

            // Splat data
            m_CB_SplatPhoton.m.SplatSize = 2.0f * (2.0f / m_Tex_Photons.Width);
            m_CB_SplatPhoton.UpdateData();

            m_Device.SetRenderStates( RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.DISABLED, BLEND_STATE.ALPHA_BLEND );

            View2D[]	Views = new View2D[] {
                m_Tex_Photons.GetView( 0, 0, 6*0, 6 ),
                m_Tex_Photons.GetView( 0, 0, 6*1, 6 ),
                m_Tex_Photons.GetView( 0, 0, 6*2, 6 ),
            };
            m_Device.SetRenderTargets( m_Tex_Photons.Width, m_Tex_Photons.Height, Views, null );

            m_PS_PhotonSplatter.Use();
            m_Prim_Point.RenderInstanced( m_PS_PhotonSplatter, PHOTONS_COUNT );

            // Splat additive intensity
            m_CB_SplatPhoton.m.SplatSize = 8.0f * (2.0f / m_Tex_Photons.Width);
             			m_CB_SplatPhoton.m.SplatIntensity = 1000.0f / PHOTONS_COUNT;
            m_CB_SplatPhoton.UpdateData();

            m_Device.SetRenderStates( RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.DISABLED, BLEND_STATE.ADDITIVE );

            Views = new View2D[] { m_Tex_Photons.GetView( 0, 0, 6*3, 6 ) };
            m_Device.SetRenderTargets( m_Tex_Photons.Width, m_Tex_Photons.Height, Views, null );

            m_PS_PhotonSplatter_Intensity.Use();
            m_Prim_Point.RenderInstanced( m_PS_PhotonSplatter_Intensity, PHOTONS_COUNT );

            m_Tex_Photons.RemoveFromLastAssignedSlots();

            Render();
        }
示例#37
0
 /// <summary>
 /// Returns true if the object is visible on the view.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="view">View.</param>
 /// <param name="zoom"></param>
 public override bool IsVisibleIn(View2D view, float zoom)
 {
     // TODO: refine this visible check.
     return _bounds.Overlaps(view.OuterBox);
 }
示例#38
0
 /// <summary>
 /// Returns true if the object is visible on the view.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="view">View.</param>
 public override bool IsVisibleIn(View2D view)
 {
     return _bounds.Overlaps(view.OuterBox);
 }
示例#39
0
 /// <summary>
 /// Returns true if the object is visible in the view.
 /// </summary>
 /// <returns><c>true</c> if this instance is visible in the specified view; otherwise, <c>false</c>.</returns>
 /// <param name="view">The view.</param>
 public abstract bool IsVisibleIn(View2D view);
示例#40
0
        /// <summary>
        /// Gets all objects in this scene for the specified view.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="zoom"></param>
        public override IEnumerable<Scene2DPrimitive> Get(View2D view, float zoom)
        {
            var primitivesInView = new List<Scene2DPrimitive>();

            lock (_primitives)
            {
                foreach (var layer in _primitives)
                { // loop over all layers in order.
                    foreach (IScene2DPrimitive primitivePair in layer.Value)
                    { // loop over all primitives in order.
                        if (primitivePair.IsVisibleIn(view, zoom))
                        {
                            primitivesInView.Add(new Scene2DPrimitive()
                                { Layer = layer.Key, Primitive = primitivePair });
                        }
                    }
                }
            }
            return primitivesInView;
        }
示例#41
0
 /// <summary>
 /// Returns true if the object is visible in the view and for the given zoom factor.
 /// </summary>
 /// <returns><c>true</c> if this instance is visible in the specified view; otherwise, <c>false</c>.</returns>
 /// <param name="view">The view.</param>
 /// <param name="zoom">The zoom factor.</param>
 public abstract bool IsVisibleIn(View2D view, float zoom);
示例#42
0
        /// <summary>
        /// Returns true if the object is visible on the view.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="view">View.</param>
        /// <param name="zoom"></param>
        public bool IsVisibleIn(View2D view, float zoom)
        {
            if (this.MinZoom > zoom || this.MaxZoom < zoom)
            { // outside of zoom bounds!
                return false;
            }

            return view.Contains(this.X, this.Y);
        }
示例#43
0
        /// <summary>
        /// Returns true if the object is visible on the view.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="view">View.</param>
        /// <param name="zoom"></param>
        public override bool IsVisibleIn(View2D view, float zoom)
        {
            if (this.MinZoom > zoom || this.MaxZoom < zoom)
            { // outside of zoom bounds!
                return false;
            }

            return view.OverlapsWithBox(this.Left, this.Top, this.Right, this.Bottom);
        }
示例#44
0
        /// <summary>
        /// Returns true if the object is visible on the view.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="view">View.</param>
        /// <param name="zoom"></param>
        public bool IsVisibleIn(View2D view, float zoom)
        {
            if (this.MinZoom > zoom || this.MaxZoom < zoom)
            { // outside of zoom bounds!
                return false;
            }

            if (view.OverlapsWithBox (MinX, MinY, MaxX, MaxY)) {
                return true; // maybe a better hittest?
            }
            return false;
        }
示例#45
0
文件: Icon2D.cs 项目: JoeCooper/ui
 /// <summary>
 /// Returns true if the object is visible in the given view.
 /// </summary>
 /// <param name="view"></param>
 /// <returns></returns>
 public override bool IsVisibleIn(View2D view)
 {
     return view.Contains(this.X, this.Y);
 }
示例#46
0
文件: Image2D.cs 项目: JoeCooper/ui
 /// <summary>
 /// Returns true if the object is visible on the view.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="view">View.</param>
 /// 
 public override bool IsVisibleIn(View2D view)
 {
     return view.OverlapsWithBox(this.Left, this.Top, this.Right, this.Bottom);
 }
示例#47
0
 /// <summary>
 /// Gets all objects in this scene for the specified view.
 /// </summary>
 /// <param name="view">View.</param>
 /// <param name="zoom"></param>
 public override IEnumerable<Scene2DPrimitive> Get(View2D view, float zoom)
 {
     Scene2D scene = this.SearchForScene (zoom);
     List<IEnumerable<Scene2DPrimitive>> primitives = new List<IEnumerable<Scene2DPrimitive>>();
     primitives.Add(_nonSimplifiedScene.Get(view, zoom));
     if (scene != null) {
         primitives.Add(scene.Get (view, zoom));
     }
     return new Scene2DPrimitiveEnumerable(primitives);
 }
示例#48
0
 /// <summary>
 /// Gets all objects in this scene for the specified view sorted according to layer number.
 /// </summary>
 /// <param name="view">View.</param>
 /// <param name="zoom"></param>
 public abstract IEnumerable<Scene2DPrimitive> Get(View2D view, float zoom);