Hi MapSuite Team
Could you give me a simple sample code showing how to cache an image in the web application to improve panning and zooming speed.
My image is in tiff format.
Best Regards,
Vincent
Hi MapSuite Team
Could you give me a simple sample code showing how to cache an image in the web application to improve panning and zooming speed.
My image is in tiff format.
Best Regards,
Vincent
Hi Vincent,
To make sure the Map works with Caching, we just need to set the ServerCache property of LayerOverlay which the Layers are added to. Additionally,we can use “LayerOverlay. GenerateCacheImages” method to pre-generate the cached image based on extent, and then set the “ServerCache” property of LayerOverlay to read the cache from the specified folder. Here as following is the demo code:
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.MapUnit = GeographyUnit.DecimalDegree;
//WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
//Map1.CustomOverlays.Add(worldMapKitOverlay);
GeoTiffRasterLayer worldImageLayer = new GeoTiffRasterLayer(@"C:\Data\world.tif");
worldImageLayer.UpperThreshold = double.MaxValue;
worldImageLayer.LowerThreshold = 0;
worldImageLayer.IsGrayscale = false;
LayerOverlay ImageOverlay = new LayerOverlay();
ImageOverlay.ServerCache = new ServerCache(@"e:\temp");
ImageOverlay.Layers.Add("WorldImageLayer", worldImageLayer);
Map1.CustomOverlays.Add(ImageOverlay); ImageOverlay.GenerateCacheImages
Map1.CurrentExtent = new RectangleShape(-118.098, 84.3, 118.098, -84.3);
Thanks,
Johnny
Hi Johnny
Thank you for the reply. It has worked but I have encountered a problem. I have a shape file with land parcels which I overlay with an image. I have set the rectangleshape cache extent parameter of the GenerateCacheImages method to the bounding box of my shape file.
Now when I zoom the resulting map to a certain extent, the shape file is displaced from the image i.e. they don't overlay with each other the way they should. Can you help me here please, if possible with a simple code.
Best Regards,
Vincent
Hi Vincent,
Do you mean that the offset just happens after caching the image? I’m sorry that we are unable to recreate it, is it possible to post a demo code and screenshot here?
Thanks,
Johnny
Hi Johnny
Thank you for the reply. Here is my code.
string LayerFilePath = Directory.GetParent(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).FullName).FullName + "\\GISMaps\\" + overall_path;
MyCustomDataShapeFileFeatureLayer ParcelLayer= new MyCustomDataShapeFileFeatureLayer(LayerFilePath );
ParcelLayer.Open();
RectangleShape rec = ParcelLayer.GetBoundingBox();
ParcelLayer.Close();
Map1.CurrentExtent = rec;
GeoTiffRasterLayer Layera = new GeoTiffRasterLayer(TiffImage);
Layera.UpperThreshold = double.MaxValue;
Layera.LowerThreshold = 0;
Layera.IsGrayscale = false;
LayerOverlay dynamicOverlay = new LayerOverlay();
dynamicOverlay.IsBaseOverlay = false;
dynamicOverlay.Name = "Image";
dynamicOverlay.TileType = TileType.SingleTile;
dynamicOverlay.Layers.Add(Layera);
Map1.CustomOverlays.Add(dynamicOverlay);
dynamicOverlay.ServerCache = new ServerCache(@"c:\temp\img1");
dynamicOverlay.GenerateCacheImages(Map1.ClientZoomLevelScales[9], Map1.CurrentExtent, Map1.MapUnit);
LayerOverlay dynamicOverlay111 = new LayerOverlay();
dynamicOverlay111.IsBaseOverlay = false;
dynamicOverlay111.Name = "All Property";
dynamicOverlay111.TileType = TileType.SingleTile;
dynamicOverlay111.Layers.Add("DynamicLayer11", ParcelLayer);
Map1.CustomOverlays.Add(dynamicOverlay111);
Best Regards,
Vincent
Hi Vincent,
Thanks for the demo code, I think the offset is cause by the “dynamicOverlay.TileType = TileType.SingleTile”. The MapSuite doesn’t allow adding the cache when working with SingleTile. As far as we all know, the cached image is based on extent, in other words, if it’s single tile, the server will always save the images once we pan the map, because the extent changed. Please use the MulTile instead.
Thanks,
Johnny