Beispiel #1
1
 private void MapControl_MouseDown(object sender, MouseEventArgs e)
 {
     mousePosition = new Mapsui.Geometries.Point(e.X, e.Y);
 }
Beispiel #2
0
        public static XamlShapes.Shape RenderPoint(Point point, IStyle style, IViewport viewport,
                                                   BrushCache brushCache = null)
        {
            XamlShapes.Shape symbol;
            var matrix = XamlMedia.Matrix.Identity;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;

                if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle, symbolStyle.Opacity, symbolStyle.SymbolType);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle.BitmapId, symbolStyle.Opacity, brushCache);
                }
                matrix = CreatePointSymbolMatrix(viewport.Resolution, symbolStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle((style as VectorStyle) ?? new VectorStyle());
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }

            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(point, viewport));

            symbol.RenderTransform = new XamlMedia.MatrixTransform {
                Matrix = matrix
            };
            symbol.IsHitTestVisible = false;

            return(symbol);
        }
Beispiel #3
0
        public static XamlShapes.Shape RenderPoint(Point point, IStyle style, IViewport viewport,
            BrushCache brushCache = null)
        {
            XamlShapes.Shape symbol;
            var matrix = XamlMedia.Matrix.Identity;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;

                if (symbolStyle.BitmapId < 0)
                    symbol = CreateSymbolFromVectorStyle(symbolStyle, symbolStyle.Opacity, symbolStyle.SymbolType);
                else
                    symbol = CreateSymbolFromBitmap(symbolStyle.BitmapId, symbolStyle.Opacity, brushCache);
                matrix = CreatePointSymbolMatrix(viewport.Resolution, symbolStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle((style as VectorStyle) ?? new VectorStyle());
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }

            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(point, viewport));

            symbol.RenderTransform = new XamlMedia.MatrixTransform {Matrix = matrix};
            symbol.IsHitTestVisible = false;

            return symbol;
        }
Beispiel #4
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text
            labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Beispiel #5
0
        private static void RenderVectorPoint(Graphics graphics, Point point, IStyle style, IViewport viewport, StyleContext context)
        {
            var symbolStyle = ToSymbolStyle(style);

            if (symbolStyle.Fill == null)
            {
                return;
            }

            var symbolscale = symbolStyle.SymbolScale;
            var offset      = symbolStyle.SymbolOffset.ToGdi();
            var rotation    = symbolStyle.SymbolRotation;
            var dest        = ConvertPoint(viewport.WorldToScreen(point));

            var width  = symbolStyle.Width * symbolscale;
            var height = symbolStyle.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            DrawSymbol(graphics, symbolStyle, context);
            graphics.ResetTransform();
        }
Beispiel #6
0
        public void ZoomToBox(Mapsui.Geometries.Point beginPoint, Mapsui.Geometries.Point endPoint)
        {
            double x, y, resolution;
            var    width  = Math.Abs(endPoint.X - beginPoint.X);
            var    height = Math.Abs(endPoint.Y - beginPoint.Y);

            if (width <= 0)
            {
                return;
            }
            if (height <= 0)
            {
                return;
            }

            ZoomHelper.ZoomToBoudingbox(beginPoint.X, beginPoint.Y, endPoint.X, endPoint.Y, ActualWidth, out x, out y, out resolution);
            resolution = ZoomHelper.ClipToExtremes(map.Resolutions, resolution);

            viewport.Center     = new Mapsui.Geometries.Point(x, y);
            viewport.Resolution = resolution;

            toResolution = resolution;

            OnViewChanged(true, true);
            Redraw();
            ClearBBoxDrawing();
        }
Beispiel #7
0
        public static XamlShapes.Shape RenderPoint(Point point, IStyle style, IReadOnlyViewport viewport,
                                                   SymbolCache symbolCache)
        {
            XamlShapes.Shape symbol;
            var matrix = XamlMedia.Matrix.Identity;

            var symbolStyle = style as SymbolStyle;

            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle, symbolStyle.Opacity, symbolStyle.SymbolType, symbolCache, (float)viewport.Rotation);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle.BitmapId, symbolStyle.Opacity, symbolCache);
                }
                matrix = CreatePointSymbolMatrix(viewport.Resolution, viewport.Rotation, symbolStyle, symbol.Width, symbol.Height);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle((style as VectorStyle) ?? new VectorStyle(), symbolCache: symbolCache, rotate: (float)viewport.Rotation);
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }

            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(viewport, point));

            symbol.RenderTransform = new XamlMedia.MatrixTransform {
                Matrix = matrix
            };
            symbol.IsHitTestVisible = false;

            return(symbol);
        }
Beispiel #8
0
        private static CGAffineTransform CreateAffineTransform(double rotation, Point position)
        {
            var transformTranslate = CGAffineTransform.MakeTranslation((float)position.X, (float)position.Y);
            var transformRotate    = CGAffineTransform.MakeRotation((float)(rotation * RadiansPerDegree));
            var transform          = transformRotate * transformTranslate;

            return(transform);
        }
 public static void Pan(Viewport transform, Point currentMap, Point previousMap)
 {
   Point current = transform.ScreenToWorld(currentMap.X, currentMap.Y);
   Point previous = transform.ScreenToWorld(previousMap.X, previousMap.Y);
   double diffX = previous.X - current.X;
   double diffY = previous.Y - current.Y;
   transform.Center = new Point(transform.CenterX + diffX, transform.CenterY + diffY);
 }
Beispiel #10
0
        private void MyMapControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Point screenPosition = e.GetPosition(MyMapControl);

            Mapsui.Geometries.Point earthPosition = MyMapControl.Map.Viewport.ScreenToWorld(screenPosition.X, screenPosition.Y);
            Mapsui.Geometries.Point worldPosition = CurrentConvertor.ToGameSpace(earthPosition);
            HoverPositionXY.Text = $"{worldPosition.X:F0}, {worldPosition.Y:F0}";
        }
Beispiel #11
0
 public static void PositionPoint(UIElement renderedGeometry, Point point, IStyle style, IViewport viewport)
 {
     var matrix = XamlMedia.Matrix.Identity;
     if (style is SymbolStyle) matrix = CreatePointSymbolMatrix(viewport.Resolution, style as SymbolStyle);
     else MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
     MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(point, viewport));
     renderedGeometry.RenderTransform = new XamlMedia.MatrixTransform { Matrix = matrix };
 }
Beispiel #12
0
        private void SetCurrentNode(string nodeId)
        {
            Mapsui.Geometries.Point nodePoint = nodeChooser.TilesHolder.GetNodePoint(nodeId);
            MyMapControl.Navigator.NavigateTo(nodePoint, 1);
            UpdatePinLayer(nodePoint);
            walker.CurrentNodeId = nodeId;

            Console.WriteLine("Point is now {0} at {1}", nodeId, nodePoint.ToString());
        }
Beispiel #13
0
        public static void Pan(Viewport transform, Point currentMap, Point previousMap)
        {
            Point  current  = transform.ScreenToWorld(currentMap.X, currentMap.Y);
            Point  previous = transform.ScreenToWorld(previousMap.X, previousMap.Y);
            double diffX    = previous.X - current.X;
            double diffY    = previous.Y - current.Y;

            transform.Center = new Point(transform.CenterX + diffX, transform.CenterY + diffY);
        }
Beispiel #14
0
        private static CGAffineTransform CreateAffineTransform(double rotation, CGPoint position, float scale)
        {
            var transformTranslate = CGAffineTransform.MakeTranslation((nfloat)(float)position.X, (nfloat)(float)position.Y);
            var transformRotate    = CGAffineTransform.MakeRotation((nfloat)(float)(rotation * RadiansPerDegree));
            var transformScale     = CGAffineTransform.MakeScale((nfloat)scale, (nfloat)scale);
            var transform          = transformScale * transformRotate * transformTranslate;

            return(transform);
        }
Beispiel #15
0
        private async Task WalkOnce()
        {
            string neighborId = nodeChooser.GetNextNode(walker);

            Mapsui.Geometries.Point nodePoint = nodeChooser.TilesHolder.GetNodePoint(neighborId);
            await SetCurrentNodeDelayed(neighborId);

            Tile neighborTile = nodeChooser.TilesHolder.GetNodeTile(neighborId);
            await nodeChooser.TilesHolder.LoadAdjacentTiles(neighborTile);
        }
Beispiel #16
0
        public void MoveWaypoint(Point position)
        {
            if (SelectedWaypoint == null)
            {
                return;
            }

            SelectedWaypoint.Latitude  = position.Y;
            SelectedWaypoint.Longitude = position.X;
            _map.UpdateRoute(Route);
        }
Beispiel #17
0
        private void UpdatePinLayer(Mapsui.Geometries.Point currentNodePoint)
        {
            LayerCollection layers = MyMapControl.Map.Layers;

            if (layers.Count > 1)
            {
                layers.Remove(pinLayer);
            }

            pinLayer = WalkerPin.CreateWalkerLayer(currentNodePoint);
            layers.Add(pinLayer);
        }
Beispiel #18
0
        private static void DrawPointWithVectorStyle(VectorStyle vectorStyle, Point destination)
        {
            var color = vectorStyle.Fill.Color;

            GL.Color4((byte)color.R, (byte)color.G, (byte)color.B, (byte)color.A);
            GL.PointSize((float)SymbolStyle.DefaultWidth);
            GL.EnableClientState(All.VertexArray);
            var destAsArray = new[] { (float)destination.X, (float)destination.Y };

            GL.VertexPointer(2, All.Float, 0, destAsArray);
            GL.DrawArrays(All.Points, 0, 1);
            GL.DisableClientState(All.VertexArray);
        }
Beispiel #19
0
        public static Mapsui.Geometries.Point CalculateCenter(double BoundsRight, double BoundsTop, double BoundsLeft, double BoundsBottom)
        {
            double lat = (BoundsLeft + BoundsRight) / 2;
            double lng = (BoundsBottom + BoundsTop) / 2;

            Mapsui.Geometries.Point p = new Mapsui.Geometries.Point()
            {
                X = lng,
                Y = lat
            };

            return(p);
        }
Beispiel #20
0
        private void callback(QueryResult queryResult)
        {
            if (queryResult != null)
            {
                var xyStart = SphericalMercator.FromLonLat(queryResult.bbox[0], queryResult.bbox[1]);
                var xyEnd   = SphericalMercator.FromLonLat(queryResult.bbox[2], queryResult.bbox[3]);

                var beginPoint = new Mapsui.Geometries.Point(xyStart.x, xyStart.y);
                var endPoint   = new Mapsui.Geometries.Point(xyEnd.x, xyEnd.y);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                          mapControl.ZoomToBox(beginPoint, endPoint)
                                                          );
            }
        }
Beispiel #21
0
        private async Task SetCurrentNodeDelayed(string nodeId)
        {
            Mapsui.Geometries.Point nodePoint        = nodeChooser.TilesHolder.GetNodePoint(nodeId);
            Mapsui.Geometries.Point currentNodePoint = nodeChooser.TilesHolder.GetNodePoint(walker.CurrentNodeId);

            double distanceKms          = nodeChooser.TilesHolder.GetGeoDistance(currentNodePoint, nodePoint);
            double walkTimeSeconds      = distanceKms / Walker.WALK_SPEED_KM_PER_SECOND;
            int    walkTimeMilliseconds = (int)(walkTimeSeconds * 1000);

            Console.WriteLine("Walking to new point {0} in {1} seconds", nodePoint, walkTimeSeconds);
            await Task.Delay(walkTimeMilliseconds);

            SetCurrentNode(nodeId);
        }
Beispiel #22
0
        public static void Render(Graphics graphics, Point point, IStyle style, IViewport viewport, StyleContext context)
        {
            if (point == null) return;
            if (style == null) return;

            var symbolStyle = style as SymbolStyle;
            if ((symbolStyle == null) || (symbolStyle.BitmapId < 0))
            {
                RenderVectorPoint(graphics, point, style, viewport, context);
            }
            else
            {
                RenderBitmapPoint(graphics, point, viewport, symbolStyle);
            }
        }
Beispiel #23
0
        private void WidgetTouched(IWidget widget, Point screenPosition)
        {
            if (widget is Hyperlink hyperlink)
            {
                global::Android.Net.Uri uri = global::Android.Net.Uri.Parse(hyperlink.Url);
                Intent intent = new Intent(Intent.ActionView);
                intent.SetData(uri);

                Intent chooser = Intent.CreateChooser(intent, "Open with");

                Context.StartActivity(chooser);
            }

            widget.HandleWidgetTouched(screenPosition);
        }
        private async Task Load()
        {
            var service = new EpanetService();

            service.InpPath = @"Samples\INP(Dr-누수량배분-연결요소수정).inp";
            service.Run();

            var nodeLayer = new WritableLayer()
            {
                Style = GetNodeLayerStyle()
            };
            var linkLayer = new WritableLayer()
            {
                Style = GetLinkLayerStyle()
            };

            foreach (var node in service.Nodes)
            {
                var point   = new Mapsui.Geometries.Point(node.X, node.Y);
                var feature = new Mapsui.Providers.Feature();
                feature.Geometry = point;
                nodeLayer.Add(feature);
            }

            foreach (var link in service.Links)
            {
                var vertices = new List <Mapsui.Geometries.Point>();
                vertices.Add(new Mapsui.Geometries.Point(link.Node1.X, link.Node1.Y));
                foreach (var v in link.Vertices)
                {
                    vertices.Add(new Mapsui.Geometries.Point(v.X, v.Y));
                }
                vertices.Add(new Mapsui.Geometries.Point(link.Node2.X, link.Node2.Y));
                var lineString = new Mapsui.Geometries.LineString(vertices);
                var feature    = new Mapsui.Providers.Feature();
                feature.Geometry = lineString;
                linkLayer.Add(feature);
            }

            mapControl.Map.Layers.Add(nodeLayer);
            mapControl.Map.Layers.Add(linkLayer);

            var p = (Mapsui.Geometries.Point)nodeLayer.GetFeatures().First().Geometry;

            mapControl.Navigator.NavigateTo(p, 11);

            await Animation(service, nodeLayer);
        }
Beispiel #25
0
        public void AddSection(Point position)
        {
            var sectionPoint = new GeoPosition(position.Y, position.X);
            var section      = new Section
            {
                Polygon = new List <GeoPosition>
                {
                    sectionPoint
                }
            };

            SelectSectionPoint(section, sectionPoint);
            Route.Sections.Add(section);

            _map.UpdateRoute(Route);
        }
Beispiel #26
0
        private void MapControl_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (mousePosition == null)
                {
                    return;
                }
                var newMousePosition = new Mapsui.Geometries.Point(e.X, e.Y);
                MapTransformHelpers.Pan(viewport, newMousePosition, mousePosition);
                mousePosition = newMousePosition;

                ViewChanged(true);
                InvalidateMap(true);
            }
        }
Beispiel #27
0
        public static void PositionPoint(UIElement renderedGeometry, Point point, IStyle style, IViewport viewport)
        {
            var matrix = XamlMedia.Matrix.Identity;

            if (style is SymbolStyle)
            {
                matrix = CreatePointSymbolMatrix(viewport.Resolution, style as SymbolStyle);
            }
            else
            {
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }
            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(point, viewport));
            renderedGeometry.RenderTransform = new XamlMedia.MatrixTransform {
                Matrix = matrix
            };
        }
        public Mapsui.Map CreateMap()
        {
            map = new Map();
            map.Layers.Add(OpenStreetMap.CreateTileLayer());

            // Get the lon lat coordinates from somewhere (Mapsui can not help you there)
            var center = new Mapsui.Geometries.Point(115.85713, -31.95496);
            // OSM uses spherical mercator coordinates. So transform the lon lat coordinates to spherical mercator
            var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(center.X, center.Y);

            // Set the center of the viewport to the coordinate. The UI will refresh automatically
            map.NavigateTo(sphericalMercatorCoordinate);
            // Additionally you might want to set the resolution, this could depend on your specific purpose
            map.NavigateTo(map.Resolutions[7]);
            LoadPoints();
            //CreatePointer();
            return(map);
        }
Beispiel #29
0
        private (uint, uint) WorldPosToGrid(Point worldPosition)
        {
            var Xgrid10KM = (uint)(worldPosition.X / 10000) % 10;
            var Xgrid1KM  = (uint)(worldPosition.X / 1000) % 10;
            var Xgrid100m = (uint)(worldPosition.X / 100) % 10;
            var Xgrid10m  = (uint)(worldPosition.X / 10) % 10;


            var Ygrid10KM = (uint)(worldPosition.Y / 10000) % 10;
            var Ygrid1KM  = (uint)(worldPosition.Y / 1000) % 10;
            var Ygrid100m = (uint)(worldPosition.Y / 100) % 10;
            var Ygrid10m  = (uint)(worldPosition.Y / 10) % 10;

            return(
                Xgrid10KM * 1000 + Xgrid1KM * 100 + Xgrid100m * 10 + Xgrid10m,
                Ygrid10KM * 1000 + Ygrid1KM * 100 + Ygrid100m * 10 + Ygrid10m
                );
        }
Beispiel #30
0
        public static void PositionPoint(UIElement renderedGeometry, Point point, IStyle style, IViewport viewport)
        {
            var matrix      = XamlMedia.Matrix.Identity;
            var symbolStyle = style as SymbolStyle;

            if (symbolStyle != null)
            {
                matrix = CreatePointSymbolMatrix(viewport.Resolution, viewport.Rotation, symbolStyle, renderedGeometry.RenderSize.Width, renderedGeometry.RenderSize.Height);
            }
            else
            {
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }
            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(viewport, point));
            renderedGeometry.RenderTransform = new XamlMedia.MatrixTransform {
                Matrix = matrix
            };
        }
Beispiel #31
0
        private static void DrawPointWithSymbolStyle(SymbolStyle symbolStyle, Point destination, IDictionary <int, TextureInfo> bitmapCache)
        {
            TextureInfo textureInfo;

            if (!bitmapCache.Keys.Contains(symbolStyle.BitmapId))
            {
                textureInfo = TextureHelper.LoadTexture(BitmapRegistry.Instance.Get(symbolStyle.BitmapId));
                bitmapCache[symbolStyle.BitmapId] = textureInfo;
            }
            else
            {
                textureInfo = bitmapCache[symbolStyle.BitmapId];
            }

            TextureHelper.RenderTexture(textureInfo, (float)destination.X, (float)destination.Y,
                                        (float)symbolStyle.SymbolRotation,
                                        (float)symbolStyle.SymbolOffset.X, (float)symbolStyle.SymbolOffset.Y,
                                        opacity: (float)symbolStyle.Opacity, scale: (float)symbolStyle.SymbolScale);
        }
Beispiel #32
0
        private static void RenderBitmapPoint(Graphics graphics, Point point, IViewport viewport, SymbolStyle symbolStyle)
        {
            var symbol = new Bitmap(BitmapRegistry.Instance.Get(symbolStyle.BitmapId));
            var symbolscale = symbolStyle.SymbolScale;
            var offset = symbolStyle.SymbolOffset.ToGdi();
            var rotation = symbolStyle.SymbolRotation;
            var dest = ConvertPoint(viewport.WorldToScreen(point));

            var width = symbol.Width * symbolscale;
            var height = symbol.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            graphics.DrawImage(symbol, 0, 0, (float)width, (float)height);
            graphics.ResetTransform();
        }
Beispiel #33
0
        public void AddWaypoint(Point position)
        {
            var waypoint = new WayPoint(position.Y, position.X);

            if (SelectedWaypoint == null)
            {
                Route.Waypoints.Add(waypoint);
            }
            else
            {
                Route.Waypoints.Insert(
                    Route.Waypoints.IndexOf(SelectedWaypoint) + 1,
                    waypoint
                    );
            }

            SelectRoutePoint(waypoint);
            _map.UpdateRoute(Route);
        }
Beispiel #34
0
        private static void RenderBitmapPoint(Graphics graphics, Point point, IViewport viewport, SymbolStyle symbolStyle)
        {
            var symbol      = new Bitmap(BitmapRegistry.Instance.Get(symbolStyle.BitmapId));
            var symbolscale = symbolStyle.SymbolScale;
            var offset      = symbolStyle.SymbolOffset.ToGdi();
            var rotation    = symbolStyle.SymbolRotation;
            var dest        = ConvertPoint(viewport.WorldToScreen(point));

            var width  = symbol.Width * symbolscale;
            var height = symbol.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            graphics.DrawImage(symbol, 0, 0, (float)width, (float)height);
            graphics.ResetTransform();
        }
Beispiel #35
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi()); //Calculate the size of the text

            labelPoint.X += offset.X; labelPoint.Y += offset.Y;          //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.ToGdi(), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                }
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi().Style, font.ToGdi().Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.ToGdi(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.ToGdi(), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);
                }

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi().Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.ToGdi(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Beispiel #36
0
        public static void RenderPoint(CALayer target, CGPoint point, IStyle style, IViewport viewport, IFeature feature)
        {
            CALayer symbol;
			float rotation = 0;
			float scale = 1;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;
				rotation = (float)symbolStyle.SymbolRotation;
				scale = (float)symbolStyle.SymbolScale;

				if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle);
                }

                if (symbolStyle.Outline != null)
                {
                    symbol.BorderColor = symbolStyle.Outline.Color.ToCG();
                    symbol.BorderWidth = (float)symbolStyle.Outline.Width;
                }

            }
            else if (style is VectorStyle)
            {
                var vectorStyle = (VectorStyle)style;
                symbol = CreateSymbolFromVectorStyle(vectorStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle(new VectorStyle());
            }

			symbol.AffineTransform = CreateAffineTransform(rotation, viewport.WorldToScreen(point), scale);
            target.AddSublayer(symbol);
        }
Beispiel #37
0
        public void AddSectionPoint(Point position)
        {
            if (SelectedSectionPoint == null)
            {
                MessageBox.Show("Select a section point first");
                return;
            }

            var section = Route.Sections
                          .Find(s => s.Polygon.Contains(SelectedSectionPoint));

            var sectionPoint = new GeoPosition(position.Y, position.X);

            section.Polygon.Insert(
                section.Polygon.IndexOf(SelectedSectionPoint),
                sectionPoint
                );

            SelectSectionPoint(section, sectionPoint);
            _map.UpdateRoute(Route);
        }
Beispiel #38
0
        private static void RenderVectorPoint(Graphics graphics, Point point, IStyle style, IViewport viewport, StyleContext context)
        {
            var symbolStyle = ToSymbolStyle(style);
            if (symbolStyle.Fill == null) return;

            var symbolscale = symbolStyle.SymbolScale;
            var offset = symbolStyle.SymbolOffset.ToGdi();
            var rotation = symbolStyle.SymbolRotation;
            var dest = ConvertPoint(viewport.WorldToScreen(point));

            var width = symbolStyle.Width * symbolscale;
            var height = symbolStyle.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            DrawSymbol(graphics, symbolStyle, context);
            graphics.ResetTransform();
        }
Beispiel #39
0
        public static void RenderPoint(CALayer target, CGPoint point, IStyle style, IViewport viewport, IFeature feature)
        {
            CALayer symbol;
            float   rotation = 0;
            float   scale    = 1;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;
                rotation = (float)symbolStyle.SymbolRotation;
                scale    = (float)symbolStyle.SymbolScale;

                if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle);
                }

                if (symbolStyle.Outline != null)
                {
                    symbol.BorderColor = symbolStyle.Outline.Color.ToCG();
                    symbol.BorderWidth = (float)symbolStyle.Outline.Width;
                }
            }
            else if (style is VectorStyle)
            {
                var vectorStyle = (VectorStyle)style;
                symbol = CreateSymbolFromVectorStyle(vectorStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle(new VectorStyle());
            }

            symbol.AffineTransform = CreateAffineTransform(rotation, viewport.WorldToScreen(point), scale);
            target.AddSublayer(symbol);
        }
Beispiel #40
0
        private static CGAffineTransform CreateAffineTransform(double rotation, CGPoint position, float scale)
        {
            var transformTranslate = CGAffineTransform.MakeTranslation((nfloat)(float)position.X, (nfloat)(float)position.Y);
            var transformRotate = CGAffineTransform.MakeRotation((nfloat)(float)(rotation * RadiansPerDegree));
			var transformScale = CGAffineTransform.MakeScale ((nfloat)scale, (nfloat)scale);
            var transform = transformScale * transformRotate * transformTranslate;
            return transform;
        }
        private void callback(QueryResult queryResult)
        {
            if (queryResult != null)
            {
                var xyStart = SphericalMercator.FromLonLat(queryResult.bbox[0], queryResult.bbox[1]);
                var xyEnd = SphericalMercator.FromLonLat(queryResult.bbox[2], queryResult.bbox[3]);

                var beginPoint = new Mapsui.Geometries.Point(xyStart.x, xyStart.y);
                var endPoint = new Mapsui.Geometries.Point(xyEnd.x, xyEnd.y);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    mapControl.ZoomToBox(beginPoint, endPoint)
                );
            }
        }
Beispiel #42
0
        private void MapControl_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (mousePosition == null) return;
                var newMousePosition = new Mapsui.Geometries.Point(e.X, e.Y);
                MapTransformHelpers.Pan(viewport, newMousePosition, mousePosition);
                mousePosition = newMousePosition;

                ViewChanged(true);
                InvalidateMap(true);
            }
        }
Beispiel #43
0
 public static PointF ConvertPoint(Point point)
 {
     return new PointF((float)point.X, (float)point.Y);
 }