Hi ,
I am trying to display google map on background of WpfMap.
It’s working fine when I add GoogleMapsOverlay to overlays.
But when I remove it and set projections to null it doesn’t work as expected .
I’ve provided a light sample to demonstrate the problem.
Regards
ThinkGeoProjection.zip (28.5 KB)
Problem with GoogleMap and projection
Hi Shaahin,
Your issue is happened on the map extent value in HideBackground method. After clicking on the HideBackground button, I guess you want to the map under EPSG 27700, so you should convert the map extent from Google projection to 27700 which means you should use the ConvertToExternalProjection method instead of ConvertToInternalProjection. the change works fine in my end, if any questions, please let me know.
For those projection issue, I think a good practice way is comparing the value between the before and later, like here, when we use the ConvertToInternalProjection method, the map extent before the projection is -394107.95264755,6727772.82592613,-316295.252479704,6691556.14197527, but after the projection, it changes to -5E-06,5E-06,5E-06,-5E-06 which is not invalid as the map extent.
Hope it helps and if there is anything I misunderstand, please feel free to correct me.
Regards,
Troy
Thanks for answer.
It fixed hide background problem but now there is another problem.
Each time I show or hide background then extent become smaller.
I’ve attached the project and created an image to show the problem.
Can you please check it and help me ?
Regards,
Shahin
ThinkGeoProjection2.zip (28.6 KB)
Hi,
In the HideBackground method, we can use the _extent value as the map extent to solve it as the _extent is exact the previous value of the map extent where the map is under EPSG 27700.
mapControl.CurrentExtent = _extent;
mapControl.Refresh();
Hope it helps.
Troy
Hi,
I was thinking about this way.
But if user adds background then changes zoom level and also position of map then _extent will not be equal with current extent.
I mean I want to keep current extent exactly when user hides background, not the extent before adding background that we store in _extent.
Thanks in advance.
Shahin
Hi Shaahin,
Okay, I check it again and find it is hard to restore the previous extent after the projection conversion. That’s because when we assign the extent value to the map extent, the map extent will do a calculation based on the value and map image size to generate a better extent, which means the map extent might not be equal to the given value.
But there is an option like I mentioned in the other thread from you, and this is also a recommendation way and can avoid such projection issues. We should apply the projection on the shape file as the first option. Would you please try the below codes to see if it’s fit for you:
void
mapControl_Loaded(
object
sender, RoutedEventArgs e)
{
mapControl.MapUnit = GeographyUnit.Meter;
var managedProj4 =
new
Proj4Projection
{
InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(27700),
ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString()
};
managedProj4.Open();
var layer =
new
ShapeFileFeatureLayer(@
“source\Cardiff_Boundary_region.shp”
);
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Antarctica1;
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
var staticOverlay =
new
LayerOverlay
{
TransitionEffect = TransitionEffect.None,
TileType = TileType.SingleTile
};
layer.FeatureSource.Projection = managedProj4;
staticOverlay.Layers.Add(
“layer”
, layer);
mapControl.Overlays.Add(staticOverlay);
layer.Open();
_extent = layer.GetBoundingBox();
layer.Close();
mapControl.CurrentExtent = _extent;
mapControl.Refresh();
}
private
void
ShowBackground(
object
sender, RoutedEventArgs e)
{
AddBackground();
mapControl.Refresh();
}
private
void
AddBackground()
{
var googleMapsOverlay =
new
GoogleMapsOverlay
{
MapType =GoogleMapsMapType.RoadMap
};
mapControl. Overlays.Insert(0,
“Googlemapsoverlay”
, googleMapsOverlay);
}
private
void
HideBackground(
object
sender, RoutedEventArgs e)
{
mapControl.Overlays.Remove(
“Googlemapsoverlay”
);
mapControl.Refresh();
}
Regards,
Troy