# Migrate to WPF Desktop edition

**URL:** <https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114>\
**Category:** WPF\
**Created:** [December 5, 2011, 1:17am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114 "2011-12-05T01:17:58Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 5, 2011, 1:17am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/1 "2011-12-05T01:17:58Z")

</div>

Hello&nbsp;ThinkGeo-Team,

we&nbsp;want&nbsp;to&nbsp;switch&nbsp;map&nbsp;control&nbsp;in&nbsp;our&nbsp;application&nbsp;from&nbsp;Desktop&nbsp;to&nbsp;WPFDesktop&nbsp;edition.&nbsp;At&nbsp;the&nbsp;moment&nbsp;we&nbsp;try&nbsp;to&nbsp;migrate&nbsp;our&nbsp;code&nbsp;to&nbsp;work&nbsp;with&nbsp;WPF&nbsp;edition.

Currently&nbsp;we&nbsp;need&nbsp;help&nbsp;on&nbsp;following&nbsp;problems:

1.)  
  
We&nbsp;have&nbsp;a&nbsp;server&nbsp;side&nbsp;caching&nbsp;system&nbsp;based&nbsp;on&nbsp;following&nbsp;code:

`Public Function GetLayerImage(ByVal dblBBULX As Double, ByVal dblBBULY As Double, _                                        ByVal dblBBLRX As Double, ByVal dblBBLRY As Double, _                                        ByVal lngImageWidth As Integer, ByVal lngMapUnit As ThinkGeo.MapSuite.Core.GeographyUnit, ByVal lngImageHeight As Integer) As Byte()      Dim oBoundingBox As ThinkGeo.MapSuite.Core.RectangleShape      Dim bytArray(-1) As Byte      Dim oLayer As ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer      Dim oCanvas As ThinkGeo.MapSuite.Core.GeoCanvas      Dim oGeoImage As ThinkGeo.MapSuite.Core.GeoImage = New ThinkGeo.MapSuite.Core.GeoImage(lngImageWidth, lngImageHeight)      Dim oOverlay As ThinkGeo.MapSuite.DesktopEdition.LayerOverlay      oBoundingBox = New ThinkGeo.MapSuite.Core.RectangleShape(New ThinkGeo.MapSuite.Core.PointShape(dblBBULX, dblBBULY), _                                                               New ThinkGeo.MapSuite.Core.PointShape(dblBBLRX, dblBBLRY))      oOverlay = New ThinkGeo.MapSuite.DesktopEdition.LayerOverlay()      SyncLock oOverlay        oLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer()        oOverlay.Layers.Add(oLayer)        oOverlay.TileCache = New ThinkGeo.MapSuite.Core.FileBitmapTileCache()        oCanvas = New ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas        Try          oCanvas.BeginDrawing(oGeoImage, oBoundingBox, lngMapUnit)          oOverlay.Draw(oCanvas)        Finally          If oCanvas.IsDrawing Then            oCanvas.Flush()            oCanvas.EndDrawing()          End If        End Try      End SyncLock      bytArray = ThinkGeo.MapSuite.Core.GdiPlusGeoCanvas.ConvertGeoImageToMemoryStream(oGeoImage, System.Drawing.Imaging.ImageFormat.Png).ToArray      Return bytArray    End Function`&nbsp;

As&nbsp;you&nbsp;can&nbsp;see&nbsp;we&nbsp;use&nbsp;Overlay&nbsp;and&nbsp;the&nbsp;associated&nbsp;cache&nbsp;to&nbsp;draw&nbsp;on&nbsp;canvas.&nbsp;With&nbsp;the&nbsp;WPF&nbsp;edition&nbsp;we&nbsp;can't&nbsp;do&nbsp;this&nbsp;because&nbsp;there&nbsp;is&nbsp;now&nbsp;draw()&nbsp;method&nbsp;with&nbsp;we&nbsp;can&nbsp;draw&nbsp;direct&nbsp;to&nbsp;the&nbsp;canvas.&nbsp;How&nbsp;can&nbsp;we&nbsp;implement&nbsp;a&nbsp;server&nbsp;cache&nbsp;with&nbsp;WPF&nbsp;edition?

2.)  
  
We&nbsp;have&nbsp;to&nbsp;edit&nbsp;large&nbsp;shapes.&nbsp;In&nbsp;the&nbsp;Desktop&nbsp;Edition&nbsp;you&nbsp;made&nbsp;some&nbsp;enhancements&nbsp;to&nbsp;improve&nbsp;the&nbsp;performance&nbsp;when&nbsp;working&nbsp;with&nbsp;large&nbsp;shapes.  
  
[wiki.thinkgeo.com/wiki/File:...Vertex.jpg](http://wiki.thinkgeo.com/wiki/File:Map_Suite_Desktop_Edition_Sample_Dragging_Vertex.jpg)  
  
&nbsp;  
  
In&nbsp;the&nbsp;WPF&nbsp;edition&nbsp;editing&nbsp;of&nbsp;those&nbsp;large&nbsp;shapes&nbsp;is&nbsp;not&nbsp;usable.&nbsp;Can&nbsp;we&nbsp;do&nbsp;something&nbsp;to&nbsp;improve&nbsp;the&nbsp;performance?

Thomas

---

<div class="post-metadata">

**Author:** ![Clint](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Clint](https://community.thinkgeo.com/u/Clint)\
**Post date:** [December 7, 2011, 10:13am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/2 "2011-12-07T10:13:41Z")

</div>

&nbsp;Thomas,

Thanks&nbsp;for&nbsp;your&nbsp;post!

For&nbsp;Issue&nbsp;#1&nbsp;the&nbsp;structure&nbsp;is&nbsp;different&nbsp;in&nbsp;the&nbsp;WPF&nbsp;Edition&nbsp;as&nbsp;we&nbsp;don't&nbsp;accept&nbsp;the&nbsp;GeoCanvas&nbsp;at&nbsp;the&nbsp;Overlay&nbsp;level.&nbsp;&nbsp;However&nbsp;you&nbsp;can&nbsp;accomplish&nbsp;what&nbsp;you&nbsp;want&nbsp;by&nbsp;accessing&nbsp;the&nbsp;Geocanvas&nbsp;on&nbsp;the&nbsp;layer&nbsp;within&nbsp;the&nbsp;overlay.&nbsp;&nbsp;Below&nbsp;is&nbsp;a&nbsp;code&nbsp;snippet&nbsp;that&nbsp;shows&nbsp;how&nbsp;to&nbsp;do&nbsp;this:

&nbsp;

`Private Sub GetLayersImage(overlay As LayerOverlay, canvas As GdiPlusGeoCanvas)        Dim candidates As New Collection(Of SimpleCandidate)        For Each layer As Layer In overlay.Layers            layer.Open()            layer.Draw(canvas, candidates)            layer.Close()        Next    End Sub`

On&nbsp;issue&nbsp;#2&nbsp;the&nbsp;code&nbsp;sample&nbsp;you&nbsp;referred&nbsp;to&nbsp;in&nbsp;the&nbsp;wiki&nbsp;should&nbsp;work&nbsp;with&nbsp;the&nbsp;WPF&nbsp;Edition&nbsp;too&nbsp;without&nbsp;any&nbsp;issue.&nbsp;&nbsp;Did&nbsp;you&nbsp;get&nbsp;it&nbsp;working&nbsp;and&nbsp;it's&nbsp;just&nbsp;that&nbsp;the&nbsp;performance&nbsp;is&nbsp;to&nbsp;slow?

Thanks!

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 9, 2011, 1:53am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/3 "2011-12-09T01:53:39Z")

</div>

Clint,

Thanks&nbsp;for&nbsp;your&nbsp;information.&nbsp;But&nbsp;I&nbsp;think&nbsp;I&nbsp;have&nbsp;to&nbsp;give&nbsp;you&nbsp;some&nbsp;more&nbsp;information&nbsp;because&nbsp;my&nbsp;sample&nbsp;code&nbsp;is&nbsp;not&nbsp;showing&nbsp;the&nbsp;real&nbsp;code,&nbsp;its&nbsp;just&nbsp;a&nbsp;sample&nbsp;to&nbsp;give&nbsp;you&nbsp;an&nbsp;overview&nbsp;what&nbsp;we&nbsp;are&nbsp;doing.

We&nbsp;use&nbsp;overlay&nbsp;with&nbsp;activated&nbsp;FileBitmapCache.&nbsp;If&nbsp;a&nbsp;user&nbsp;requests&nbsp;an&nbsp;extent&nbsp;for&nbsp;the&nbsp;first&nbsp;time,&nbsp;overlay&nbsp;draws&nbsp;the&nbsp;image&nbsp;with&nbsp;the&nbsp;layer.&nbsp;On&nbsp;the&nbsp;second&nbsp;request&nbsp;overlay&nbsp;draws&nbsp;the&nbsp;image&nbsp;using&nbsp;the&nbsp;data&nbsp;in&nbsp;the&nbsp;tile&nbsp;cache&nbsp;whitch&nbsp;is&nbsp;much&nbsp;more&nbsp;faster.

In&nbsp;your&nbsp;sample&nbsp;there&nbsp;is&nbsp;no&nbsp;caching&nbsp;operation.

issue&nbsp;#2:

In&nbsp;our&nbsp;evaluation&nbsp;version&nbsp;of&nbsp;WPF-Control&nbsp;we&nbsp;use&nbsp;the&nbsp;same&nbsp;code&nbsp;as&nbsp;in&nbsp;the&nbsp;Dektop&nbsp;edition&nbsp;but&nbsp;editing&nbsp;is&nbsp;much&nbsp;slower.&nbsp;I&nbsp;will&nbsp;make&nbsp;some&nbsp;tests&nbsp;with&nbsp;the&nbsp;wiki&nbsp;sample.

Thomas

---

<div class="post-metadata">

**Author:** ![Clint](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Clint](https://community.thinkgeo.com/u/Clint)\
**Post date:** [December 12, 2011, 11:26am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/4 "2011-12-12T11:26:59Z")

</div>

Thomas,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;reply.&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;On&nbsp;Issue&nbsp;#1,&nbsp;is&nbsp;there&nbsp;anyway&nbsp;you&nbsp;can&nbsp;use&nbsp;our&nbsp;built&nbsp;in&nbsp;cache&nbsp;system?&nbsp;&nbsp;It&nbsp;sound&nbsp;like&nbsp;it&nbsp;will&nbsp;do&nbsp;what&nbsp;you&nbsp;want&nbsp;without&nbsp;the&nbsp;complexity&nbsp;of&nbsp;having&nbsp;to&nbsp;manage&nbsp;it&nbsp;yourself,&nbsp;however&nbsp;you&nbsp;may&nbsp;have&nbsp;additional&nbsp;requirements&nbsp;that&nbsp;I’m&nbsp;aware&nbsp;of.&nbsp;&nbsp;For&nbsp;a&nbsp;sample&nbsp;on&nbsp;how&nbsp;to&nbsp;use&nbsp;the&nbsp;built&nbsp;in&nbsp;Tile&nbsp;Cache&nbsp;system&nbsp;check&nbsp;out&nbsp;the&nbsp;How&nbsp;Do&nbsp;I&nbsp;sample&nbsp;included&nbsp;with&nbsp;the&nbsp;WPF&nbsp;Edtion,&nbsp;I&nbsp;believe&nbsp;it’s&nbsp;in&nbsp;the&nbsp;following&nbsp;directory;&nbsp;&nbsp;“\HowDoISamples\CSharp&nbsp;Samples\Getting&nbsp;Started\UsingTileCache.xaml”&nbsp;  
&nbsp;&nbsp;  
&nbsp;On&nbsp;Issue&nbsp;#2&nbsp;if&nbsp;you&nbsp;are&nbsp;seeing&nbsp;slowness&nbsp;one&nbsp;thing&nbsp;you&nbsp;might&nbsp;try&nbsp;is&nbsp;setting&nbsp;the&nbsp;RenderMode&nbsp;on&nbsp;the&nbsp;EditOVerlay&nbsp;and&nbsp;TrackOverlay&nbsp;using&nbsp;the&nbsp;code&nbsp;below:&nbsp;  
&nbsp;&nbsp;  
&nbsp;wpfMap1.EditOverlay.RenderMode&nbsp;=&nbsp;RenderMode.GdiPlus;&nbsp;  
&nbsp;wpfMap1.TrackOverlay.RenderMode&nbsp;=&nbsp;RenderMode.GdiPlus;&nbsp;  
&nbsp;&nbsp;  
&nbsp;WPF&nbsp;rendering&nbsp;has&nbsp;several&nbsp;ties&nbsp;to&nbsp;the&nbsp;rendering&nbsp;depending&nbsp;on&nbsp;the&nbsp;OS&nbsp;and&nbsp;hardware&nbsp;configuration,&nbsp;so&nbsp;if&nbsp;you&nbsp;set&nbsp;the&nbsp;render&nbsp;mode&nbsp;go&nbsp;GDI&nbsp;Plus&nbsp;it&nbsp;will&nbsp;be&nbsp;using&nbsp;the&nbsp;same&nbsp;rendering&nbsp;as&nbsp;the&nbsp;Desktop&nbsp;edition.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks!&nbsp;  
&nbsp;&nbsp;

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 13, 2011, 5:08am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/5 "2011-12-13T05:08:38Z")

</div>

Clint,

if&nbsp;you&nbsp;look&nbsp;on&nbsp;my&nbsp;sample&nbsp;code&nbsp;you&nbsp;can&nbsp;see&nbsp;that&nbsp;I'm&nbsp;using&nbsp;your&nbsp;caching&nbsp;system.

oOverlay.TileCache&nbsp;=&nbsp;New&nbsp;ThinkGeo.MapSuite.Core.FileBitmapTileCache(_...Path&nbsp;to&nbsp;our&nbsp;cache&nbsp;directory_)  
  
&nbsp;

Also&nbsp;you&nbsp;can&nbsp;see&nbsp;in&nbsp;my&nbsp;sample&nbsp;code&nbsp;how&nbsp;it&nbsp;works&nbsp;in&nbsp;Desktop&nbsp;Edition.&nbsp;I&nbsp;use&nbsp;overlay&nbsp;with&nbsp;activated&nbsp;Tile-Cache&nbsp;to&nbsp;draw&nbsp;on&nbsp;local&nbsp;GdiPlusGeoCanvas&nbsp;then&nbsp;convert&nbsp;the&nbsp;canvas&nbsp;image&nbsp;to&nbsp;byte&nbsp;array&nbsp;and&nbsp;deliver&nbsp;it&nbsp;to&nbsp;my&nbsp;client.

In&nbsp;WPF-Edition&nbsp;there&nbsp;is&nbsp;no&nbsp;Draw()&nbsp;method&nbsp;in&nbsp;overlay.&nbsp;As&nbsp;you&nbsp;mentioned&nbsp;I&nbsp;can&nbsp;use&nbsp;layer-object&nbsp;to&nbsp;draw&nbsp;to&nbsp;the&nbsp;canvas&nbsp;but&nbsp;then&nbsp;I&nbsp;can't&nbsp;use&nbsp;Tile-Cache&nbsp;because&nbsp;it&nbsp;is&nbsp;only&nbsp;on&nbsp;the&nbsp;overlay&nbsp;level.

Thomas

---

<div class="post-metadata">

**Author:** ![Clint](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Clint](https://community.thinkgeo.com/u/Clint)\
**Post date:** [December 13, 2011, 11:17am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/6 "2011-12-13T11:17:34Z")

</div>

Thomas,&nbsp;  
  
  
  
Let's&nbsp;step&nbsp;back&nbsp;a&nbsp;little&nbsp;bit&nbsp;so&nbsp;I&nbsp;have&nbsp;a&nbsp;better&nbsp;understanding&nbsp;of&nbsp;what&nbsp;you&nbsp;are&nbsp;wanting&nbsp;to&nbsp;do&nbsp;overall&nbsp;and&nbsp;then&nbsp;maybe&nbsp;I&nbsp;can&nbsp;provide&nbsp;a&nbsp;good&nbsp;approach&nbsp;in&nbsp;how&nbsp;to&nbsp;do&nbsp;this&nbsp;in&nbsp;the&nbsp;WPF&nbsp;Edition.&nbsp;&nbsp;&nbsp;  
  
  
  
On&nbsp;your&nbsp;original&nbsp;post&nbsp;you&nbsp;said&nbsp;"We&nbsp;have&nbsp;a&nbsp;server&nbsp;side&nbsp;caching&nbsp;system&nbsp;based&nbsp;on&nbsp;following&nbsp;code".&nbsp;&nbsp;&nbsp;&nbsp;Can&nbsp;you&nbsp;provide&nbsp;more&nbsp;information&nbsp;on&nbsp;how&nbsp;your&nbsp;server&nbsp;side&nbsp;cacheing&nbsp;works?&nbsp;&nbsp;I'm&nbsp;assuming&nbsp;it&nbsp;will&nbsp;serve&nbsp;up&nbsp;a&nbsp;cached&nbsp;image&nbsp;that&nbsp;you&nbsp;will&nbsp;then&nbsp;want&nbsp;to&nbsp;draw&nbsp;on&nbsp;the&nbsp;client?&nbsp;&nbsp;If&nbsp;this&nbsp;is&nbsp;the&nbsp;case&nbsp;you&nbsp;wouldn't&nbsp;you&nbsp;have&nbsp;the&nbsp;equivalent&nbsp;of&nbsp;one&nbsp;layer&nbsp;within&nbsp;your&nbsp;overlay&nbsp;making&nbsp;up&nbsp;the&nbsp;tile&nbsp;from&nbsp;the&nbsp;server&nbsp;side&nbsp;cache&nbsp;and&nbsp;could&nbsp;use&nbsp;the&nbsp;Layer.Draw?&nbsp;  
  
  
  
Can&nbsp;you&nbsp;also&nbsp;give&nbsp;a&nbsp;general&nbsp;overview&nbsp;of&nbsp;your&nbsp;application&nbsp;and&nbsp;architecture&nbsp;and&nbsp;maybe&nbsp;that&nbsp;will&nbsp;help&nbsp;me&nbsp;better&nbsp;understand&nbsp;the&nbsp;issue.&nbsp;  
  
  
  
Thanks!&nbsp;

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 14, 2011, 3:02am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/7 "2011-12-14T03:02:52Z")

</div>

Clint,&nbsp;  
&nbsp;&nbsp;  
&nbsp;you&nbsp;wrote:&nbsp;“I’m&nbsp;assuming&nbsp;it&nbsp;will&nbsp;serve&nbsp;up&nbsp;a&nbsp;cached&nbsp;image&nbsp;that&nbsp;you&nbsp;will&nbsp;then&nbsp;want&nbsp;to&nbsp;draw&nbsp;on&nbsp;the&nbsp;client?”.&nbsp;This&nbsp;is&nbsp;exactly&nbsp;what&nbsp;I&nbsp;want&nbsp;to&nbsp;do!&nbsp;  
&nbsp;In&nbsp;our&nbsp;client/server&nbsp;application&nbsp;the&nbsp;users&nbsp;can&nbsp;create&nbsp;their&nbsp;own&nbsp;layers&nbsp;and&nbsp;maps.&nbsp;If&nbsp;the&nbsp;user&nbsp;created&nbsp;map&nbsp;contains&nbsp;many&nbsp;layers&nbsp;e.g.&nbsp;Shapefile-Layers&nbsp;with&nbsp;great&nbsp;number&nbsp;of&nbsp;shapes&nbsp;the&nbsp;drawing&nbsp;performance&nbsp;is&nbsp;very&nbsp;slow.&nbsp;To&nbsp;improve&nbsp;the&nbsp;performance&nbsp;the&nbsp;user&nbsp;can&nbsp;combine&nbsp;those&nbsp;layers&nbsp;how&nbsp;are&nbsp;used&nbsp;as&nbsp;static&nbsp;background&nbsp;to&nbsp;a&nbsp;static&nbsp;map&nbsp;and&nbsp;activate&nbsp;the&nbsp;client&nbsp;side&nbsp;caching&nbsp;system.&nbsp;This&nbsp;means&nbsp;we&nbsp;put&nbsp;them&nbsp;all&nbsp;in&nbsp;one&nbsp;overlay&nbsp;and&nbsp;activate&nbsp;the&nbsp;associated&nbsp;Tile-Cache.&nbsp;This&nbsp;works&nbsp;fine&nbsp;on&nbsp;the&nbsp;client.&nbsp;But&nbsp;every&nbsp;client&nbsp;(\>100)&nbsp;has&nbsp;to&nbsp;draw&nbsp;the&nbsp;static&nbsp;background&nbsp;map&nbsp;until&nbsp;it&nbsp;is&nbsp;stored&nbsp;in&nbsp;the&nbsp;client&nbsp;cache.&nbsp;To&nbsp;avoid&nbsp;this&nbsp;we&nbsp;want&nbsp;to&nbsp;create&nbsp;a&nbsp;server&nbsp;side&nbsp;cache&nbsp;on&nbsp;our&nbsp;application&nbsp;server.&nbsp;First&nbsp;map&nbsp;request&nbsp;creates&nbsp;the&nbsp;image&nbsp;and&nbsp;returns&nbsp;it&nbsp;to&nbsp;the&nbsp;client&nbsp;besides&nbsp;the&nbsp;image&nbsp;is&nbsp;stored&nbsp;it&nbsp;in&nbsp;the&nbsp;server&nbsp;cache.&nbsp;Second&nbsp;map&nbsp;request&nbsp;can&nbsp;get&nbsp;the&nbsp;image&nbsp;from&nbsp;the&nbsp;server&nbsp;cache.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;sample&nbsp;code&nbsp;shows&nbsp;how&nbsp;we&nbsp;have&nbsp;done&nbsp;this&nbsp;in&nbsp;the&nbsp;Desktop&nbsp;Edition.&nbsp;I&nbsp;think&nbsp;in&nbsp;WPF-Edition&nbsp;we&nbsp;must&nbsp;use&nbsp;the&nbsp;TileCache-Class&nbsp;to&nbsp;get&nbsp;the&nbsp;same&nbsp;result&nbsp;but&nbsp;I&nbsp;need&nbsp;some&nbsp;sample&nbsp;code&nbsp;how&nbsp;to&nbsp;do&nbsp;this.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thomas

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 15, 2011, 9:16pm UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/8 "2011-12-15T21:16:25Z")

</div>

&nbsp;Hi&nbsp;Thomas,

&nbsp;  
I&nbsp;reviewed&nbsp;your&nbsp;scenario&nbsp;and&nbsp;found&nbsp;that&nbsp;you&nbsp;want&nbsp;to&nbsp;use&nbsp;the&nbsp;functionality&nbsp;of&nbsp;the&nbsp;Draw&nbsp;method&nbsp;to&nbsp;generate&nbsp;cache&nbsp;files.&nbsp;The&nbsp;WPF&nbsp;and&nbsp;Desktop&nbsp;Edition&nbsp;are&nbsp;designed&nbsp;in&nbsp;different&nbsp;structure.&nbsp;So&nbsp;the&nbsp;Draw&nbsp;with&nbsp;GeoCanvas&nbsp;parameter&nbsp;is&nbsp;moved&nbsp;into&nbsp;the&nbsp;Tile&nbsp;level&nbsp;so&nbsp;that&nbsp;we&nbsp;can&nbsp;have&nbsp;better&nbsp;performance&nbsp;with&nbsp;multithread.  
&nbsp;  
We&nbsp;still&nbsp;have&nbsp;a&nbsp;chance&nbsp;to&nbsp;implement&nbsp;an&nbsp;extension&nbsp;for&nbsp;you&nbsp;with&nbsp;the&nbsp;Draw&nbsp;method&nbsp;you&nbsp;need.&nbsp;Please&nbsp;see&nbsp;the&nbsp;code&nbsp;below.  
  
`public static class LayerOverlayExtension{    public static void Draw(this LayerOverlay layerOverlay, GeoCanvas geoCanvas)    {        Collection<SimpleCandidate> labelCandidates = new Collection<SimpleCandidate>();        foreach (var layer in layerOverlay.Layers)        {            lock (layer)            {                if (!layer.IsOpen) layer.Open();                geoCanvas.Flush();                layer.Draw(geoCanvas, labelCandidates);            }        }        if (layerOverlay.TileCache != null)        {            layerOverlay.TileCache.TileMatrix.Scale = ExtentHelper.GetScale(geoCanvas.CurrentWorldExtent, geoCanvas.Width, geoCanvas.MapUnit);            var tiles = layerOverlay.TileCache.GetTiles(geoCanvas.CurrentWorldExtent);            foreach (var tile in tiles)            {                if (tile.Bitmap == null)                {                    GdiPlusGeoCanvas tempGeoCanvas = new GdiPlusGeoCanvas();                    Bitmap nativeImage = new Bitmap(layerOverlay.TileWidth, layerOverlay.TileHeight);                    try                    {                        tempGeoCanvas.BeginDrawing(nativeImage, tile.BoundingBox, geoCanvas.MapUnit);                        Collection<SimpleCandidate> tempLabelCandidates = new Collection<SimpleCandidate>();                        foreach (var layer in layerOverlay.Layers)                        {                            lock (layer)                            {                                if (!layer.IsOpen) layer.Open();                                geoCanvas.Flush();                                layer.Draw(tempGeoCanvas, tempLabelCandidates);                            }                        }                        tempGeoCanvas.EndDrawing();                        tile.Bitmap = nativeImage;                        layerOverlay.TileCache.SaveTile(tile);                    }                    finally                    {                        nativeImage.Dispose();                    }                }            }        }    }}`  
&nbsp;  
  
Here&nbsp;is&nbsp;also&nbsp;a&nbsp;sample&nbsp;for&nbsp;you&nbsp;to&nbsp;use&nbsp;this&nbsp;extension.&nbsp;Please&nbsp;make&nbsp;sure&nbsp;putting&nbsp;the&nbsp;our&nbsp;dlls&nbsp;into&nbsp;the&nbsp;dependencies&nbsp;folder&nbsp;and&nbsp;put&nbsp;country02.shp&nbsp;into&nbsp;the&nbsp;app\_data&nbsp;folder&nbsp;to&nbsp;run&nbsp;this&nbsp;app.  
&nbsp;  
Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;question.  
&nbsp;  
Thanks,  
Howard  
  
[Post9837\_WPFOverlayDrawWithGeoCanvasParameter.zip](https://community.thinkgeo.com/uploads/default/original/2X/f/f9c622e247d6ecee0a56734a07c8c4d8600341d6.zip) (11.2 KB)

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 16, 2011, 10:07am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/9 "2011-12-16T10:07:56Z")

</div>

Hello&nbsp;Howard,

thanks&nbsp;for&nbsp;your&nbsp;sample.&nbsp;I&nbsp;made&nbsp;some&nbsp;test&nbsp;with&nbsp;your&nbsp;sample&nbsp;and&nbsp;it&nbsp;is&nbsp;almost&nbsp;close&nbsp;to&nbsp;what&nbsp;we&nbsp;want&nbsp;to&nbsp;do.&nbsp;When&nbsp;looking&nbsp;on&nbsp;your&nbsp;sample&nbsp;code&nbsp;I&nbsp;recognized&nbsp;that&nbsp;we&nbsp;can&nbsp;build&nbsp;our&nbsp;server&nbsp;cache&nbsp;simply&nbsp;by&nbsp;using&nbsp;the&nbsp;TileCache&nbsp;class.&nbsp;I&nbsp;think&nbsp;this&nbsp;is&nbsp;a&nbsp;better&nbsp;way&nbsp;than&nbsp;our&nbsp;current&nbsp;implementation&nbsp;with&nbsp;the&nbsp;desktop&nbsp;edition&nbsp;because&nbsp;we&nbsp;access&nbsp;the&nbsp;caching&nbsp;system&nbsp;in&nbsp;a&nbsp;multithreaded&nbsp;way&nbsp;and&nbsp;I&nbsp;think&nbsp;overlay&nbsp;class&nbsp;is&nbsp;designed&nbsp;to&nbsp;work&nbsp;in&nbsp;the&nbsp;UI&nbsp;thread.

I&nbsp;have&nbsp;modified&nbsp;your&nbsp;sample&nbsp;(see&nbsp;attachement)&nbsp;even&nbsp;we&nbsp;want&nbsp;to&nbsp;use&nbsp;it&nbsp;in&nbsp;our&nbsp;application.&nbsp;But&nbsp;there&nbsp;is&nbsp;a&nbsp;bug&nbsp;in&nbsp;my&nbsp;caching&nbsp;system.&nbsp;The&nbsp;cached&nbsp;image&nbsp;is&nbsp;not&nbsp;drawn&nbsp;as&nbsp;expected.

Sorry&nbsp;for&nbsp;the&nbsp;unprofessional&nbsp;source&nbsp;code&nbsp;but&nbsp;I&nbsp;normaly&nbsp;use&nbsp;vb.

Thomas

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 18, 2011, 9:00pm UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/10 "2011-12-18T21:00:06Z")

</div>

Hi&nbsp;Thomas,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;see,&nbsp;the&nbsp;attached&nbsp;file&nbsp;cannot&nbsp;be&nbsp;downloaded,&nbsp;please&nbsp;re-upload&nbsp;the&nbsp;sample&nbsp;so&nbsp;that&nbsp;I&nbsp;can&nbsp;check&nbsp;the&nbsp;cache&nbsp;image&nbsp;issue.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Chen

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 18, 2011, 9:00pm UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/11 "2011-12-18T21:00:28Z")

</div>

Hi&nbsp;Thomas,&nbsp;  
  
&nbsp;&nbsp;  
  
The&nbsp;attached&nbsp;file&nbsp;cannot&nbsp;be&nbsp;downloaded,&nbsp;please&nbsp;re-upload&nbsp;the&nbsp;sample&nbsp;so&nbsp;that&nbsp;I&nbsp;can&nbsp;check&nbsp;the&nbsp;cache&nbsp;image&nbsp;issue.&nbsp;I&nbsp;didn't&nbsp;aware&nbsp;that&nbsp;you&nbsp;are&nbsp;using&nbsp;VB;&nbsp;sorry&nbsp;for&nbsp;that;&nbsp;just&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;need&nbsp;the&nbsp;VB&nbsp;version&nbsp;:)  
  
&nbsp;&nbsp;  
  
Thanks,&nbsp;  
  
Chen

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 19, 2011, 1:35am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/12 "2011-12-19T01:35:54Z")

</div>

here&nbsp;again....

[Post9837\_WPFOverlayDrawGeoCanvasParam\_V2.zip](https://community.thinkgeo.com/uploads/default/original/2X/e/e1d9431c3294ef412d41226cf4a9ac184bfc3b8f.zip) (23.5 KB)

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 20, 2011, 1:03am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/13 "2011-12-20T01:03:22Z")

</div>

Hi&nbsp;Thomas,

I&nbsp;checked&nbsp;your&nbsp;code&nbsp;and&nbsp;found&nbsp;there&nbsp;is&nbsp;an&nbsp;issue&nbsp;for&nbsp;the&nbsp;mechanism&nbsp;to&nbsp;merge&nbsp;tile&nbsp;images&nbsp;to&nbsp;a&nbsp;whole&nbsp;image.&nbsp;I&nbsp;have&nbsp;corrected&nbsp;it&nbsp;and&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;see&nbsp;how&nbsp;it&nbsp;works.

Another&nbsp;tips&nbsp;is&nbsp;that,&nbsp;only&nbsp;if&nbsp;the&nbsp;TileCache&nbsp;object&nbsp;is&nbsp;set&nbsp;on&nbsp;the&nbsp;LayerOverlay,&nbsp;we&nbsp;will&nbsp;load&nbsp;the&nbsp;cache&nbsp;automatically,&nbsp;so&nbsp;we&nbsp;need&nbsp;create&nbsp;a&nbsp;new&nbsp;FileBitmapTileCache&nbsp;with&nbsp;the&nbsp;same&nbsp;cache&nbsp;id&nbsp;and&nbsp;cache&nbsp;directory.&nbsp;If&nbsp;the&nbsp;TileCache&nbsp;property&nbsp;is&nbsp;not&nbsp;set,&nbsp;we&nbsp;need&nbsp;write&nbsp;our&nbsp;own&nbsp;logic&nbsp;to&nbsp;read&nbsp;cache&nbsp;and&nbsp;combine&nbsp;them.

Now&nbsp;this&nbsp;sample&nbsp;works&nbsp;fine&nbsp;now,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;see&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.

Thanks,  
  
Howard

[Post9837\_V2.zip](https://community.thinkgeo.com/uploads/default/original/2X/8/8fb0cce9a202f210802a4827c69b7aed6eeb00c3.zip) (13.6 KB)

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [December 20, 2011, 5:15am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/14 "2011-12-20T05:15:57Z")

</div>

Hi,&nbsp;  
&nbsp;&nbsp;  
&nbsp;can’t&nbsp;download&nbsp;the&nbsp;sample.&nbsp;Please&nbsp;rename&nbsp;your&nbsp;attached&nbsp;filename&nbsp;to&nbsp;a&nbsp;shorter&nbsp;one.&nbsp;Looks&nbsp;like&nbsp;the&nbsp;file&nbsp;extension&nbsp;is&nbsp;not&nbsp;valid&nbsp;because&nbsp;it&nbsp;is&nbsp;cut&nbsp;if&nbsp;the&nbsp;filename&nbsp;is&nbsp;to&nbsp;long.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thomas

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [December 21, 2011, 12:40am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/15 "2011-12-21T00:40:18Z")

</div>

Hi&nbsp;Thomas,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;have&nbsp;updated&nbsp;the&nbsp;attached&nbsp;file&nbsp;in&nbsp;the&nbsp;previous&nbsp;reply.&nbsp;Please&nbsp;download&nbsp;that&nbsp;again&nbsp;and&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.&nbsp;Sorry&nbsp;for&nbsp;the&nbsp;inconvenience.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard

---

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [January 9, 2012, 9:23am UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/16 "2012-01-09T09:23:09Z")

</div>

Hi&nbsp;Howard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;it&nbsp;works.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;help,&nbsp;  
&nbsp;Thomas

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [January 9, 2012, 12:03pm UTC](https://community.thinkgeo.com/t/migrate-to-wpf-desktop-edition/3114/17 "2012-01-09T12:03:59Z")

</div>

Hello&nbsp;Thomas,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;welcome,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know&nbsp;your&nbsp;problems.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary
