Exemplo n.º 1
0
 /// <summary>
 /// Called when the mouse button is pressed down. Records the
 /// mouse position, to be used to move map center when the
 /// mouse button is released.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="args">Event data.</param>
 private void OnButtonPress(object sender, ButtonPressEventArgs args)
 {
     try
     {
         isDragging = true;
         CartesianToGeoCoords(args.Event.X, args.Event.Y, out double lat, out double lon);
         mouseAtDragStart = new Map.Coordinate(lat, lon);
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Show the given markers on the map and set the center/zoom level.
        /// </summary>
        /// <param name="coordinates">Coordinates of the markers.</param>
        /// <param name="locNames">Names of the marekrs (unused currently).</param>
        /// <param name="zoom">Zoom level of the map.</param>
        /// <param name="center">Location of the center of the map.</param>
        public void ShowMap(List <Map.Coordinate> coordinates, List <string> locNames, double zoom, Map.Coordinate center)
        {
            if (map != null)
            {
                map.Dispose();
            }
            map = InitMap();

            GeometryFactory  gf          = new GeometryFactory(new PrecisionModel(), 3857);
            List <IGeometry> locations   = coordinates.Select(c => gf.CreatePoint(new Coordinate(c.Longitude, c.Latitude))).ToList <IGeometry>();
            VectorLayer      markerLayer = new VectorLayer("Markers");

            markerLayer.Style.Symbol = GetResourceImage("ApsimNG.Resources.Marker.png");
            markerLayer.DataSource   = new GeometryProvider(locations);
            map.Layers.Add(markerLayer);
            map.Zoom   = zoom;
            map.Center = new Coordinate(center.Longitude, center.Latitude);
            if (image.Allocation.Width > 1 && image.Allocation.Height > 1)
            {
                RefreshMap();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Show the given markers on the map and set the center/zoom level.
        /// </summary>
        /// <param name="coordinates">Coordinates of the markers.</param>
        /// <param name="locNames">Names of the marekrs (unused currently).</param>
        /// <param name="zoom">Zoom level of the map.</param>
        /// <param name="center">Location of the center of the map.</param>
        public void ShowMap(List <Map.Coordinate> coordinates, List <string> locNames, double zoom, Map.Coordinate center)
        {
            if (map != null)
            {
                map.Dispose();
            }
            map = InitMap();

            GeometryFactory  gf          = new GeometryFactory(new PrecisionModel(), 4326);
            List <IGeometry> locations   = coordinates.Select(c => gf.CreatePoint(new Coordinate(c.Longitude, c.Latitude))).ToList <IGeometry>();
            VectorLayer      markerLayer = new VectorLayer("Markers");

            markerLayer.Style.Symbol             = GetResourceImage("ApsimNG.Resources.Marker.png");
            markerLayer.Style.SymbolOffset       = new PointF(0, -16); // Offset so the point is marked by the tip of the symbol, not its center
            markerLayer.DataSource               = new GeometryProvider(locations);
            markerLayer.CoordinateTransformation = LatLonToMetres;

            map.Layers.Add(markerLayer);
            Zoom = zoom;
            Coordinate location = LatLonToMetres.MathTransform.Transform(new Coordinate(center.Longitude, center.Latitude));

            map.Center = location;
            if (image.Allocation.Width > 1 && image.Allocation.Height > 1)
            {
                RefreshMap();
            }
        }