Hello,
I want to use Google Map instead of shape files in window application. How I can cache Google Map so that the tiles can be used in offline mode.
Waiting for your reply.
Thanks,
Akku
Hello,
I want to use Google Map instead of shape files in window application. How I can cache Google Map so that the tiles can be used in offline mode.
Waiting for your reply.
Thanks,
Akku
Akku,
Thanks for your post,
There is an easy to implement your requirement, please see the following code:
According to the code above, you can see the GoogleMapsLayer constructor, the second parameter is the cache directory for caching the tile. You can set the direcoty to yours.
GoogleMapsLayer layer = new GoogleMapsLayer(@"ABQIAAAAX_L0oJKT0IU2n0u0qxcr3BR3rCYD_eVzP3e6DX1YTr2ah9RbohStaDJYLxi99hL16CJfmL4rjnw9wA", "C:\\ImageCache");
engine.StaticLayers.Add(layer);
RefreshMap();
If you have any other questions please let me know,
Thanks,
Scott,
Akku,
As now GoogleMap does not require to input license key for a free user, you can also make your code as following.
-------------------------------------------------------
private void TestForm_Load(object sender, EventArgs e)
{
// Set the full extent and the background color
winformsMap.MapUnit = GeographyUnit.Meter;
winformsMap.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
GoogleMapsLayer googleMapLayer = new GoogleMapsLayer();
googleMapLayer.CacheDirectory = @"C:\GoogleMapImageCache";
LayerOverlay layeroverlay = new LayerOverlay();
layeroverlay.Layers.Add(googleMapLayer);
winformsMap.Overlays.Add(layeroverlay);
winformsMap.Refresh();
}
----------------------------------------------------------
Thanks,
Ben
Hiii,
I have cached Google Map tiles and when I disconnect the Internet connection my application runs properly with these tiles in my computer. But when I run the same application on client side which donot have internet connection, then it fires an error message "The remote name couldnot be resolved: 'maps.google.com' " . So please help me to resolve the problem.
Waiting for the reply.
Thanks,
Akku
Akku,
Thanks for your reply,
I would like to ask you that is the client side the same computer as your own computer? Actually, you have to cached the Google maps tiles first, then you can run your application with these tiles correctly, I think you would not cache the Google maps tiles first on the client side, then run the application in the offline mode directly. The logic is that if you dose not cache the google maps tiles, it has to connect the google maps server to request the data.
I suggest you cache the Google maps tiles first on any computers then run the application in offline mode so that the tiles can be stored in the special computer.
If you have any other questions please let me know,
Thanks,
Scott,
Hiii,
I have cached the google map tiles in a folder and while running the application on client side by saving the cached tiles in it which donot have internet connection. The application search MapSuite folder in the Temp folder of Environment and if found then run the application properly but if it is not found then it create a blank folder with this name and fires an error message "The remote name couldnot be resolved: 'maps.google.com' " . The code I have used is given below. So please look at it and give me the solution.
[code]
WinformsMap1.MapUnit = GeographyUnit.Meter
WinformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)
WinformsMap1.ZoomLevelSet.ZoomLevel03.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
WinformsMap1.CurrentExtent = New RectangleShape(-10000000, 10000000, 10000000, -10000000)
Dim googleOverlay As GoogleMapsOverlay googleOverlay = New GoogleMapsOverlay()
googleOverlay.MapType = GoogleMapsMapType.RoadMap
WinformsMap1.Overlays.Add("GoogleMap", googleOverlay)
Dim googleMapLayer As New GoogleMapsLayer() googleMapLayer.MapType = GoogleMapsMapType.RoadMap
googleMapLayer.CacheDirectory = Application.StartupPath & "\GoogleMapImageCache"
Dim inMemoryOverlay As New LayerOverlay()
inMemoryOverlay.Layers.Add("GoogleMapLayer", googleMapLayer)
WinformsMap1.Overlays.Add("InMemoryOverlay", inMemoryOverlay)
WinformsMap1.Refresh()
Waiting for the reply.
Thanks,
Akku
Akku,
Thanks for your reply,
I have reproduced this exception exactly, actually, I think there are no problems in the core code of Desktop edition for google maps cache, I checked the cache folder, the tiles can be stored correctly for each zoomlevel where you ever paned or zoomed in. When I first ran the application in the offline mode, it ran correctly because of the cached tiles, but if I zoom in/out to some un-cached areas, the exception will be occurred. I would like to tell you that the cache tiles are used to increase the load or zoom in/out performance, if you want to use it in the offline mode, you have to zoom in/out or pan the map in the same way as you first ran it, so it can read the cached tiles directly, this is the only way to use the cache in the offline mode.
Thanks,
Scott,
Scott,
I think you have not understood my problem. I am caching the Google Map tiles in a folder and even tiles are getting stored at that location. And If I work in offline mode, then it works properly upto the level whose tiles are stored. Now delete the MapSuite folder from Temp folder of the environment which also stores cached tiles. Now run the application with only cached files we have saved in the defined location. Now it will fires an error "The remote name couldnot be resolved: 'maps.google.com' " . My question is that the tiles which are stored bydefault to Temp folder is only used in the application. And the tiles cached by us are not used at all.
Thanks
Akku
Akku,
I think this problem is happening is because an attempt to connect to Google to get more tiles if extent changed.
I made a sample in attachment which limit those zoomlevel on the top 4 zoomlevel and cached all the tiles in the folder, in this case, I can 100% sure all the needed tiles are cached, you can have a try, it should work well event he network is off.
Any more questions just feel free to let me know.
Thanks.
Yale
Post7589.zip (424 KB)
Hiii Yale,
I am getting your point. But I want that If some tiles are missing at some zoom level then I should be able to catch that exception.
Thanks,
Akku
Akku,
Try to set the property DrawingExceptionMode in the Overlay:
layerOverlay.DrawingExceptionMode = DrawingExceptionMode.ThrowException;
Any more questions just feel free to let me know.
Thanks.
Yale
Yale,
Sorry, but I am not getting it what this line is doing layerOverlay.DrawingExceptionMode = DrawingExceptionMode.ThrowException . I am not able to catch the error so that I can show blank tiles insead of displaying error message.
Waiting for the reply.
Thanks,
Akku
Akku,
Yes, by default we will draw the cross error message. If you want to change its behavior, try following codes. I am sorry to say that we should set the DrawingExceptionMode for the Layer instead of the Overlay.
private void DisplayMap_Load(object sender, EventArgs e)
{
//Set the full extent and the background color
winformsMap1.MapUnit = GeographyUnit.Meter;
winformsMap1.CurrentExtent = new RectangleShape(-10000000, 10000000, 10000000, -10000000);
MyGoogleMapLayer googleMapLayer = new MyGoogleMapLayer();
googleMapLayer.CacheDirectory = @"..\..\GoogleMapImageCache";
googleMapLayer.DrawingExceptionMode = DrawingExceptionMode.DrawException;
InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();
pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
double longtitude = 77.217;
double lattidue = 28.667;
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
proj4.Open();
Vertex vertex = proj4.ConvertToExternalProjection(longtitude, lattidue);
proj4.Close();
pointLayer.InternalFeatures.Add("Point", new Feature(vertex, "Point"));
LayerOverlay layeroverlay = new LayerOverlay();
layeroverlay.Layers.Add(googleMapLayer);
//layeroverlay.Layers.Add("PointLayer", pointLayer);
layeroverlay.DrawingExceptionMode = DrawingExceptionMode.DrawException;
winformsMap1.Overlays.Add("LayerOverlay", layeroverlay);
//winformsMap1.MapClick += new EventHandler<MapClickWinformsMapEventArgs>(winformsMap1_MapClick);
winformsMap1.MinimumScale = new GoogleMapZoomLevelSet().ZoomLevel08.Scale;
winformsMap1.Refresh();
}
class MyGoogleMapLayer : GoogleMapsLayer
{
protected override void DrawExceptionCore(GeoCanvas canvas, Exception e)
{
canvas.Clear(new GeoSolidBrush(GeoColor.FromArgb(128, 255, 192, 203)));
}
}
Any more questions just feel free to let me know.
Thanks.
Yale
How to use GoogleMap in offline mode (Map Suite Web), please!
Tran,
If you want to use GoogleMap in offline mode, the simplest way is to cache it. The first time you view the map, the map will get pictures from Google server and cache it. Then you view the map, it will use the pictures you cached. Here is the code.
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -13929426.6371, 6693997.4056);
Map1.MapUnit = GeographyUnit.Meter;
GoogleMapsLayer googleMapsLayer = new GoogleMapsLayer();
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.IsBaseOverlay = true;
layerOverlay.Layers.Add(googleMapsLayer);
layerOverlay.ServerCache = new ServerCache(@"C:\temp");
Map1.CustomOverlays.Add(layerOverlay);
Thanks,
James