Fixed WMS feature info request

This commit is contained in:
ClemensFischer 2025-12-28 07:30:47 +01:00
parent c17cbe297f
commit 91f1960a00
6 changed files with 34 additions and 63 deletions

View file

@ -103,8 +103,8 @@ namespace MapControl
maxY = Math.Max(maxY, point.Y);
}
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
if (maxX >= 0d && minX <= ParentMap.ActualWidth &&
maxY >= 0d && minY <= ParentMap.ActualHeight)
{
var figure = new PathFigure
{

View file

@ -49,8 +49,6 @@ namespace MapControl
private Location transformCenter;
private Point viewCenter;
private Rect? mapBounds;
private BoundingBox geoBounds;
private double centerLongitude;
private double maxLatitude = 85.05112878; // default WebMercatorProjection
private bool internalPropertyChange;
@ -172,27 +170,6 @@ namespace MapControl
set => SetValue(TargetHeadingProperty, value);
}
/// <summary>
/// Gets the map viewport bounds in projected map coordinates.
/// </summary>
public Rect MapBounds
{
get
{
if (!mapBounds.HasValue)
{
mapBounds = ViewRectToMap(0d, 0d, ActualWidth, ActualHeight);
}
return mapBounds.Value;
}
}
/// <summary>
/// Gets the map viewport bounds in geographic coordinates.
/// </summary>
public BoundingBox GeoBounds => geoBounds ??= MapProjection.MapToBoundingBox(MapBounds);
/// <summary>
/// Gets the ViewTransform instance that is used to transform between projected
/// map coordinates and view coordinates.
@ -575,10 +552,6 @@ namespace MapControl
protected override void OnViewportChanged(ViewportChangedEventArgs e)
{
base.OnViewportChanged(e);
mapBounds = null;
geoBounds = null;
ViewportChanged?.Invoke(this, e);
}
}

View file

@ -171,14 +171,14 @@ namespace MapControl
private void DrawCylindricalGraticule(PathFigureCollection figures, List<Label> labels)
{
var bounds = ParentMap.GeoBounds;
var latLabelStart = Math.Ceiling(bounds.South / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(bounds.West / lineDistance) * lineDistance;
var boundingBox = ParentMap.ViewRectToBoundingBox(0d, 0d, ParentMap.ActualWidth, ParentMap.ActualHeight);
var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(boundingBox.West / lineDistance) * lineDistance;
for (var lat = latLabelStart; lat <= bounds.North; lat += lineDistance)
for (var lat = latLabelStart; lat <= boundingBox.North; lat += lineDistance)
{
var p1 = ParentMap.LocationToView(lat, bounds.West);
var p2 = ParentMap.LocationToView(lat, bounds.East);
var p1 = ParentMap.LocationToView(lat, boundingBox.West);
var p2 = ParentMap.LocationToView(lat, boundingBox.East);
if (p1.HasValue && p2.HasValue)
{
@ -186,17 +186,17 @@ namespace MapControl
}
}
for (var lon = lonLabelStart; lon <= bounds.East; lon += lineDistance)
for (var lon = lonLabelStart; lon <= boundingBox.East; lon += lineDistance)
{
var p1 = ParentMap.LocationToView(bounds.South, lon);
var p2 = ParentMap.LocationToView(bounds.North, lon);
var p1 = ParentMap.LocationToView(boundingBox.South, lon);
var p2 = ParentMap.LocationToView(boundingBox.North, lon);
if (p1.HasValue && p2.HasValue)
{
figures.Add(CreateLineFigure(p1.Value, p2.Value));
}
for (var lat = latLabelStart; lat <= bounds.North; lat += lineDistance)
for (var lat = latLabelStart; lat <= boundingBox.North; lat += lineDistance)
{
var position = ParentMap.LocationToView(lat, lon);

View file

@ -169,7 +169,8 @@ namespace MapControl
ParentMap.ActualWidth > 0d &&
ParentMap.ActualHeight > 0d)
{
var uri = GetFeatureInfoRequestUri(ParentMap.GeoBounds, position, format);
var boundingBox = ParentMap.ViewRectToBoundingBox(0d, 0d, ParentMap.ActualWidth, ParentMap.ActualHeight);
var uri = GetFeatureInfoRequestUri(boundingBox, position, format);
if (uri != null)
{
@ -283,7 +284,7 @@ namespace MapControl
{ "STYLES", RequestStyles ?? "" },
{ "FORMAT", "image/png" },
{ "CRS", GetCrsValue() },
{ "BBOX", GetBboxValue(boundingBox, bbox.Value) },
{ "BBOX", GetBboxValue(bbox.Value) },
{ "WIDTH", Math.Round(width).ToString("F0") },
{ "HEIGHT", Math.Round(height).ToString("F0") }
});
@ -306,9 +307,11 @@ namespace MapControl
var height = ParentMap.ViewTransform.Scale * bbox.Value.Height;
var transform = ViewTransform.CreateTransformMatrix(
-ParentMap.ActualWidth / 2d, -ParentMap.ActualWidth / 2d,
-ParentMap.ActualWidth / 2d,
-ParentMap.ActualHeight / 2d,
-ParentMap.ViewTransform.Rotation,
width / 2d, height / 2d);
width / 2d,
height / 2d);
var imagePos = transform.Transform(position);
@ -322,7 +325,7 @@ namespace MapControl
{ "FORMAT", "image/png" },
{ "INFO_FORMAT", format },
{ "CRS", GetCrsValue() },
{ "BBOX", GetBboxValue(boundingBox, bbox.Value) },
{ "BBOX", GetBboxValue(bbox.Value) },
{ "WIDTH", Math.Round(width).ToString("F0") },
{ "HEIGHT", Math.Round(height).ToString("F0") },
{ "I", Math.Round(imagePos.X).ToString("F0") },
@ -350,27 +353,22 @@ namespace MapControl
return crs;
}
protected virtual string GetBboxValue(BoundingBox boundingBox, Rect mapBoundingBox)
protected virtual string GetBboxValue(Rect mapBoundingBox)
{
var crs = ParentMap.MapProjection.CrsId;
string format;
double x1, y1, x2, y2;
var format = "{0:F2},{1:F2},{2:F2},{3:F2}";
var x1 = mapBoundingBox.X;
var y1 = mapBoundingBox.Y;
var x2 = mapBoundingBox.X + mapBoundingBox.Width;
var y2 = mapBoundingBox.Y + mapBoundingBox.Height;
if (crs == "CRS:84" || crs == "EPSG:4326")
{
format = crs == "CRS:84" ? "{0:F8},{1:F8},{2:F8},{3:F8}" : "{1:F8},{0:F8},{3:F8},{2:F8}";
x1 = boundingBox.West;
y1 = boundingBox.South;
x2 = boundingBox.East;
y2 = boundingBox.North;
}
else
{
format = "{0:F2},{1:F2},{2:F2},{3:F2}";
x1 = mapBoundingBox.X;
y1 = mapBoundingBox.Y;
x2 = mapBoundingBox.X + mapBoundingBox.Width;
y2 = mapBoundingBox.Y + mapBoundingBox.Height;
x1 /= MapProjection.Wgs84MeterPerDegree;
y1 /= MapProjection.Wgs84MeterPerDegree;
x2 /= MapProjection.Wgs84MeterPerDegree;
y2 /= MapProjection.Wgs84MeterPerDegree;
}
return string.Format(CultureInfo.InvariantCulture, format, x1, y1, x2, y2);

View file

@ -101,8 +101,8 @@ namespace MapControl
maxY = Math.Max(maxY, point.Y);
}
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
if (maxX >= 0d && minX <= ParentMap.ActualWidth &&
maxY >= 0d && minY <= ParentMap.ActualHeight)
{
context.BeginFigure(start, true, closed);
context.PolyLineTo(polyline, true, true);

View file

@ -107,8 +107,8 @@ namespace MapControl
maxY = Math.Max(maxY, point.Y);
}
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
if (maxX >= 0d && minX <= ParentMap.ActualWidth &&
maxY >= 0d && minY <= ParentMap.ActualHeight)
{
var figure = new PathFigure
{