ThinkGeo.com    |     Documentation    |     Premium Support

MapView use the Web Mercator Coordinates?

Hi!
I want to know about the coordinates of the MapView.
And I want to know the unit of WorldX() function.

Hey @willson_sam,

If you want your map to be in mercator units, you need to set the map’s MapUnit property to:

mapView.MapUnit = GeographyUnit.Meter;

You can set that in the C# code or in the MapView’s declaration in the razor page.

I’m not sure about this WorldX function that you are referring to. Maybe that’s a property of something?

Thanks,
Kyle

I have receive the Mouse Click Event from the MapView.
And then, I got the position of mouse cursor from mouse event arguments.
But the args.WorldX() value is always static even though the unit of MapView Unit changed.

Hey @willson_sam,

I am unable to recreate this issue. If I set the MapUnit to DecimalDegree, the args come back as lat/lon and if the MapUnit is in Meter, the args come back in meters. Can you provide a sample project so that I can look at your code?

Thanks,
Kyle

Hi Kyle.
The section of get mouse position.

private void OnMouseMoveEvent(MouseMovingMapViewEventArgs args)
{
currentMouseCursor = Convert.ToString(Math.Round(args.WorldX, 3)) + ", " + Convert.ToString(Math.Round(args.WorldY,3));
xValue = Convert.ToString(args.ScreenX);
yValue = Convert.ToString(args.ScreenY);
}

The section of MapView

<MapView Id=“map” OnClick="@OnMouseClickEvent" @ref="@map" MapUnit="@currentGeographyUnit.GeoUnit"

private MapGeographyUnit currentGeographyUnit { get; set; } = new MapGeographyUnit();

public class MapGeographyUnit
{
public GeographyUnit GeoUnit { get; set; }
public string Name { get; set; } =null!;
}

I have checked the changing of the valuable “currentGeographyUnit”.
Thanks.

Hey @willson_sam,

Ok, so it seems like you have some dropdown menu or something to switch the MapUnit? What does that code look like? I believe after the user changes that, you’ll need to perform a map.Refresh() to take effect. If you hardcode the map to be MapUnit=GeographyUnit.Meter or MapUnit=GeographyUnit.DecimalDegree, does the OnMouseMoveEvent change the values between runs? Also, you may not want to round the WorldX/Y because you’ll lose a lot of accuracy.

Thanks,
Kyle

Hi Kyle!
Thanks very much.
I am going to set the current extent of MapView into the extent of a vector layer.
So, after load the vector layer, how can I set the current extent in Blazor?

Hey @willson_sam,

Setting the extent isn’t quite as easy as our other platforms due to some limitations that we are currently working on. For now, you can set the CenterPoint of the map and set the zoom level by doing the following:

map.ZoomToCenterAsync(15, cityLimits.GetBoundingBox().GetCenterPoint());

Thanks,
Kyle

Hi Kyle!
Thanks for your help.

Hi Kyle!
I have to invoke the map.ZoomToCenterAsync() after OnInitializedAsync() ?
I coded your example in OnInitializedAsync() function, but It doesn’t work.
So, I set the CenterPoint as follows.

<MapView … Center="@centerPoint"

@code{
protected override async Task OnInitializedAsync()
{
centerPoint = vLayer.GetBoundingBox().GetCenterPoint();
}

This works well.

Hey @willson_sam,

Yes, that works just as well. I was thinking about putting that map.ZoomToCenterAsync call into the OnAfterRenderAsync event. But your method is probably better suited for your case because you can also set the zoom level in the MapView properties to effectively do the same thing without a weird “jump-to” after the first render.

Thanks,
Kyle