# Object Reference not set to an instance of an object when adding layers

**URL:** <https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001>\
**Category:** WebForms\
**Created:** [October 5, 2009, 12:57pm UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001 "2009-10-05T12:57:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![va3wxw](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@va3wxw](https://community.thinkgeo.com/u/va3wxw)\
**Post date:** [October 5, 2009, 12:57pm UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/1 "2009-10-05T12:57:01Z")

</div>

Hi&nbsp;there,

I&nbsp;urgently&nbsp;need&nbsp;help&nbsp;to&nbsp;try&nbsp;and&nbsp;get&nbsp;the&nbsp;mapping&nbsp;up&nbsp;and&nbsp;running&nbsp;here!&nbsp;&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;use&nbsp;code&nbsp;converted&nbsp;from&nbsp;the&nbsp;desktop&nbsp;version&nbsp;of&nbsp;the&nbsp;Mapsuite&nbsp;product&nbsp;and&nbsp;incorporate&nbsp;it&nbsp;into&nbsp;the&nbsp;web&nbsp;version.

I&nbsp;have&nbsp;a&nbsp;problem&nbsp;with&nbsp;any&nbsp;code&nbsp;that&nbsp;I&nbsp;seem&nbsp;to&nbsp;use&nbsp;to&nbsp;try&nbsp;to&nbsp;dynamically&nbsp;add&nbsp;layers&nbsp;to&nbsp;a&nbsp;map&nbsp;control.&nbsp;&nbsp;All&nbsp;I&nbsp;seem&nbsp;to&nbsp;get&nbsp;is&nbsp;a&nbsp;grid&nbsp;of&nbsp;pink&nbsp;bordered&nbsp;tiles&nbsp;with&nbsp;a&nbsp;message&nbsp;stating&nbsp;"Object&nbsp;Reference&nbsp;not&nbsp;set&nbsp;to&nbsp;an&nbsp;instance&nbsp;of&nbsp;an&nbsp;object&nbsp;"&nbsp;below&nbsp;it.&nbsp;&nbsp;Using&nbsp;either&nbsp;the&nbsp;code&nbsp;I&nbsp;am&nbsp;using&nbsp;in&nbsp;my&nbsp;app&nbsp;or&nbsp;the&nbsp;one&nbsp;from&nbsp;your&nbsp;example&nbsp;application&nbsp;fail&nbsp;to&nbsp;load&nbsp;with&nbsp;the&nbsp;same&nbsp;result.&nbsp;&nbsp;I&nbsp;am&nbsp;using&nbsp;VS2008&nbsp;here.  
  
  
  
Also,&nbsp;I&nbsp;am&nbsp;having&nbsp;issues&nbsp;displaying&nbsp;markers&nbsp;on&nbsp;a&nbsp;map&nbsp;populated&nbsp;from&nbsp;a&nbsp;database&nbsp;in&nbsp;a&nbsp;way&nbsp;that&nbsp;won't&nbsp;cause&nbsp;a&nbsp;severe&nbsp;performance&nbsp;hit&nbsp;(using&nbsp;java&nbsp;to&nbsp;update&nbsp;the&nbsp;map&nbsp;currently&nbsp;but&nbsp;coupled&nbsp;to&nbsp;a&nbsp;windows&nbsp;standard&nbsp;timer&nbsp;is&nbsp;causing&nbsp;issues).&nbsp;&nbsp;Different&nbsp;issue&nbsp;which&nbsp;may&nbsp;require&nbsp;another&nbsp;post,&nbsp;but&nbsp;I&nbsp;would&nbsp;really&nbsp;appreciate&nbsp;if&nbsp;anyone&nbsp;has&nbsp;any&nbsp;sample&nbsp;code&nbsp;that&nbsp;could&nbsp;actually&nbsp;work&nbsp;and&nbsp;get&nbsp;me&nbsp;up&nbsp;and&nbsp;running&nbsp;on&nbsp;any&nbsp;map,&nbsp;whether&nbsp;the&nbsp;base&nbsp;map&nbsp;is&nbsp;a&nbsp;web&nbsp;based&nbsp;one&nbsp;(google),&nbsp;&nbsp;Mr.&nbsp;Sid,&nbsp;other&nbsp;raster&nbsp;type&nbsp;map.\

Best&nbsp;regards,  
  
Bob

Example&nbsp;Code:

&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;Protected&nbsp;Sub&nbsp;Page\_Load(ByVal&nbsp;sender&nbsp;As&nbsp;Object,&nbsp;ByVal&nbsp;e&nbsp;As&nbsp;System.EventArgs)&nbsp;Handles&nbsp;Me.Load  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;(Not&nbsp;Page.IsPostBack)&nbsp;Then  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.MapBackground.BackgroundBrush&nbsp;=&nbsp;New&nbsp;GeoSolidBrush(GeoColor.StandardColors.White)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.CurrentExtent&nbsp;=&nbsp;New&nbsp;RectangleShape(-80.5,&nbsp;68.9,&nbsp;80,&nbsp;-60.43)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.MapUnit&nbsp;=&nbsp;GeographyUnit.DecimalDegree  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;gdiPlusImageLayer&nbsp;As&nbsp;New&nbsp;GdiPlusRasterLayer(MapPath("~\Maps\Map1.jpg"))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gdiPlusImageLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gdiPlusImageLayer.LowerThreshold&nbsp;=&nbsp;0  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map1.StaticOverlay.Layers.Add(gdiPlusImageLayer)  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;The&nbsp;following&nbsp;two&nbsp;lines&nbsp;of&nbsp;code&nbsp;enable&nbsp;the&nbsp;client&nbsp;and&nbsp;server&nbsp;caching.&nbsp;&nbsp;&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;If&nbsp;you&nbsp;enable&nbsp;these&nbsp;features&nbsp;it&nbsp;will&nbsp;greatly&nbsp;increase&nbsp;the&nbsp;scalability&nbsp;of&nbsp;your&nbsp;&nbsp;&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;mapping&nbsp;application&nbsp;however&nbsp;there&nbsp;some&nbsp;side&nbsp;effects&nbsp;that&nbsp;may&nbsp;be&nbsp;counter&nbsp;intuitive.&nbsp;&nbsp;&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;Please&nbsp;read&nbsp;the&nbsp;white&nbsp;paper&nbsp;on&nbsp;web&nbsp;caching&nbsp;or&nbsp;the&nbsp;documentation&nbsp;regarding&nbsp;these&nbsp;methods.&nbsp;&nbsp;&nbsp;  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;Map1.StaticOverlay.ClientCache.CacheId&nbsp;=&nbsp;"WorldOverlay"&nbsp;&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;Map1.StaticOverlay.ServerCache.CacheDirectory&nbsp;=&nbsp;MapPath("~/ImageCache/"&nbsp;+&nbsp;Request.Path)&nbsp;&nbsp;&nbsp;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;If  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub  
  
End&nbsp;Class

&nbsp;

Code&nbsp;I&nbsp;am&nbsp;using:

&nbsp;&nbsp;&nbsp;&nbsp;Private&nbsp;Sub&nbsp;Open\_Raster\_Map(ByVal&nbsp;MpPath&nbsp;As&nbsp;String)  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;mapOverlay.Layers.Contains(MapPath(MpPath))&nbsp;Then  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapOverlay.Layers.Remove(MapPath(MpPath))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;If  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tgMap.MapUnit&nbsp;=&nbsp;GeographyUnit.DecimalDegree  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;mapLayer&nbsp;As&nbsp;New&nbsp;GdiPlusRasterLayer(MapPath(MpPath))  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapLayer.LowerThreshold&nbsp;=&nbsp;0  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'tgMap.BackgroundOverlay.IsVisible&nbsp;=&nbsp;False  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapLayer.Name&nbsp;=&nbsp;MapPath(MpPath)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapLayer.Open()  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapOverlay.Layers.Add(MapPath(MpPath),&nbsp;mapLayer)  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tgMap.CurrentExtent&nbsp;=&nbsp;GetFullExtent()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tgMap.CustomOverlays.Add(mapOverlay)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'tgMap.Refresh()  
  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub

---

<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:** [October 5, 2009, 10:21pm UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/2 "2009-10-05T22:21:51Z")

</div>

Bob,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;description.&nbsp; The&nbsp;pink&nbsp;tile&nbsp;may&nbsp;cause&nbsp;by&nbsp;the&nbsp;configuration&nbsp;of&nbsp;your&nbsp;map&nbsp;such&nbsp;as&nbsp;styles,&nbsp;shape&nbsp;file&nbsp;path&nbsp;or&nbsp;data.&nbsp;If&nbsp;possible,&nbsp;please&nbsp;provide&nbsp;us&nbsp;a&nbsp;simple&nbsp;sample&nbsp;with&nbsp;you&nbsp;data.&nbsp;If&nbsp;the&nbsp;sample&nbsp;is&nbsp;too&nbsp;big&nbsp;to&nbsp;paste&nbsp;here;&nbsp;please&nbsp;send&nbsp;to&nbsp;[support@ThinkGeo.com](mailto:support@ThinkGeo.com)&nbsp;and&nbsp;forward&nbsp;to&nbsp;me.&nbsp;  
&nbsp;&nbsp;  
&nbsp;On&nbsp;the&nbsp;other&nbsp;hand,&nbsp;markers&nbsp;are&nbsp;all&nbsp;client&nbsp;stuff&nbsp;so&nbsp;that&nbsp;the&nbsp;more&nbsp;markers&nbsp;on&nbsp;the&nbsp;client&nbsp;side&nbsp;the&nbsp;more&nbsp;DOM&nbsp;tree&nbsp;maintains&nbsp; the&nbsp;lower&nbsp;the&nbsp;performance&nbsp;you&nbsp;gain.&nbsp;I’m&nbsp;not&nbsp;sure&nbsp;which&nbsp;marker&nbsp;overlay&nbsp;do&nbsp;you&nbsp;use.&nbsp;If&nbsp;you&nbsp;have&nbsp;many&nbsp;markers&nbsp;display&nbsp;at&nbsp;the&nbsp;same&nbsp;time,&nbsp;we&nbsp;recommend&nbsp;setting&nbsp;SuppressGridSize&nbsp;property&nbsp;on&nbsp;InMemoryMarkerOverlay&nbsp;or&nbsp;FeatureSourceMarkerOverlay&nbsp;which&nbsp;suppress&nbsp;markers&nbsp;which&nbsp;are&nbsp;too&nbsp;close&nbsp;together.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Currently&nbsp;we&nbsp;are&nbsp;planning&nbsp;to&nbsp;add&nbsp;cluster&nbsp;marker&nbsp;which&nbsp;will&nbsp;be&nbsp;better.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Hope&nbsp;it&nbsp;makes&nbsp;sense.&nbsp;Looking&nbsp;forward&nbsp;your&nbsp;sample.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard

---

<div class="post-metadata">

**Author:** ![va3wxw](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@va3wxw](https://community.thinkgeo.com/u/va3wxw)\
**Post date:** [October 8, 2009, 10:39am UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/3 "2009-10-08T10:39:32Z")

</div>

Hi&nbsp;Howard,

Thanks&nbsp;for&nbsp;your&nbsp;response!&nbsp;&nbsp;I&nbsp;have&nbsp;attached&nbsp;the&nbsp;map&nbsp;I&nbsp;was&nbsp;trying&nbsp;to&nbsp;use&nbsp;here.&nbsp;&nbsp;Also&nbsp;the&nbsp;code&nbsp;I&nbsp;am&nbsp;using&nbsp;is&nbsp;below.  
  
As&nbsp;you&nbsp;can&nbsp;see,&nbsp;I've&nbsp;tried&nbsp;code&nbsp;from&nbsp;a&nbsp;few&nbsp;different&nbsp;places&nbsp;to&nbsp;make&nbsp;the&nbsp;maps&nbsp;I&nbsp;am&nbsp;using&nbsp;work&nbsp;but&nbsp;to&nbsp;no&nbsp;avail.

With&nbsp;regards&nbsp;to&nbsp;the&nbsp;markers,&nbsp;I&nbsp;would&nbsp;like&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;load&nbsp;all&nbsp;markers&nbsp;from&nbsp;a&nbsp;database,&nbsp;populate&nbsp;them&nbsp;on&nbsp;a&nbsp;layer  
  
and&nbsp;then&nbsp;apply&nbsp;that&nbsp;to&nbsp;the&nbsp;map.&nbsp;&nbsp;Whatever&nbsp;way&nbsp;is&nbsp;the&nbsp;most&nbsp;efficient&nbsp;(and&nbsp;fastest)&nbsp;method&nbsp;to&nbsp;populate&nbsp;a&nbsp;map&nbsp;with  
  
several&nbsp;hundred&nbsp;objects.&nbsp;&nbsp;Keep&nbsp;in&nbsp;mind&nbsp;I&nbsp;need&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;populate&nbsp;them&nbsp;from&nbsp;a&nbsp;database&nbsp;and&nbsp;also&nbsp;allow&nbsp;for  
  
text&nbsp;entries&nbsp;describing&nbsp;each&nbsp;object&nbsp;to&nbsp;be&nbsp;displayed&nbsp;when&nbsp;the&nbsp;user&nbsp;hovers&nbsp;over&nbsp;them&nbsp;with&nbsp;the&nbsp;mouse&nbsp;cursor.

I&nbsp;just&nbsp;need&nbsp;a&nbsp;concrete&nbsp;example&nbsp;that&nbsp;works&nbsp;because&nbsp;I&nbsp;am&nbsp;getting&nbsp;myself&nbsp;all&nbsp;confused.&nbsp;&nbsp;The&nbsp;idiosyncrasies&nbsp;of&nbsp;the&nbsp;  
  
control,&nbsp;some&nbsp;of&nbsp;which&nbsp;I've&nbsp;been&nbsp;able&nbsp;to&nbsp;work&nbsp;around&nbsp;haven't&nbsp;helped&nbsp;either.

Bob

Private&nbsp;Sub&nbsp;Open\_sid\_map(ByVal&nbsp;MpPath&nbsp;As&nbsp;String)

&nbsp;&nbsp;Try

&nbsp;&nbsp;&nbsp;If&nbsp;mapOverlay.Layers.Contains(Server.MapPath(MpPath))&nbsp;Then  
  
&nbsp;&nbsp;&nbsp;&nbsp;mapOverlay.Layers.Remove(MpPath)  
  
&nbsp;&nbsp;&nbsp;End&nbsp;If

&nbsp;&nbsp;&nbsp;'tgMap.MapBackground.BackgroundBrush&nbsp;=&nbsp;New&nbsp;GeoSolidBrush(GeoColor.StandardColors.White)  
  
&nbsp;&nbsp;&nbsp;'tgMap.CurrentExtent&nbsp;=&nbsp;New&nbsp;RectangleShape(-80.5,&nbsp;68.9,&nbsp;80,&nbsp;-60.43)  
  
&nbsp;&nbsp;&nbsp;'tgMap.MapUnit&nbsp;=&nbsp;GeographyUnit.DecimalDegree

&nbsp;&nbsp;&nbsp;'Dim&nbsp;mapLayer&nbsp;As&nbsp;New&nbsp;MrSidRasterLayer(Server.MapPath(MpPath))  
  
&nbsp;&nbsp;&nbsp;'mapLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue  
  
&nbsp;&nbsp;&nbsp;'mapLayer.LowerThreshold&nbsp;=&nbsp;0

&nbsp;&nbsp;&nbsp;''tgMap.BackgroundOverlay.IsVisible&nbsp;=&nbsp;False

&nbsp;&nbsp;&nbsp;''mapLayer.Name&nbsp;=&nbsp;Server.MapPath(MpPath)  
  
&nbsp;&nbsp;&nbsp;''mapLayer.Open()

&nbsp;&nbsp;&nbsp;''mapOverlay.Layers.Add(Server.MapPath(MpPath),&nbsp;mapLayer)

&nbsp;&nbsp;&nbsp;''tgMap.CurrentExtent&nbsp;=&nbsp;GetFullExtent()  
  
&nbsp;&nbsp;&nbsp;'tgMap.StaticOverlay.Layers.Add(mapLayer)

&nbsp;&nbsp;&nbsp;'Dim&nbsp;mapLayer&nbsp;As&nbsp;New&nbsp;MrSidRasterLayer(Server.MapPath(MpPath))  
  
&nbsp;&nbsp;&nbsp;'mapLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue  
  
&nbsp;&nbsp;&nbsp;'mapLayer.LowerThreshold&nbsp;=&nbsp;0

&nbsp;&nbsp;&nbsp;''tgMap.BackgroundOverlay.IsVisible&nbsp;=&nbsp;False

&nbsp;&nbsp;&nbsp;'mapLayer.Name&nbsp;=&nbsp;Server.MapPath(MpPath)  
  
&nbsp;&nbsp;&nbsp;'mapLayer.Open()

&nbsp;&nbsp;&nbsp;'mapOverlay.Layers.Add(Server.MapPath(MpPath),&nbsp;mapLayer)

&nbsp;&nbsp;&nbsp;''tgMap.CurrentExtent&nbsp;=&nbsp;GetFullExtent()  
  
&nbsp;&nbsp;&nbsp;'tgMap.CustomOverlays.Add(mapOverlay)

&nbsp;

&nbsp;&nbsp;&nbsp;tgMap0.MapBackground.BackgroundBrush&nbsp;=&nbsp;New&nbsp;GeoSolidBrush(GeoColor.StandardColors.White)  
  
&nbsp;&nbsp;&nbsp;tgMap0.CurrentExtent&nbsp;=&nbsp;New&nbsp;RectangleShape(-80.5,&nbsp;68.9,&nbsp;80,&nbsp;-60.43)  
  
&nbsp;&nbsp;&nbsp;tgMap0.MapUnit&nbsp;=&nbsp;GeographyUnit.DecimalDegree

&nbsp;&nbsp;&nbsp;Dim&nbsp;sidImageLayer&nbsp;As&nbsp;MrSidRasterLayer&nbsp;=&nbsp;New&nbsp;MrSidRasterLayer(MpPath)  
  
&nbsp;&nbsp;&nbsp;sidImageLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue  
  
&nbsp;&nbsp;&nbsp;sidImageLayer.LowerThreshold&nbsp;=&nbsp;0  
  
&nbsp;&nbsp;&nbsp;tgMap0.StaticOverlay.Layers.Add(sidImageLayer)

&nbsp;&nbsp;''Dim&nbsp;markerOverlay&nbsp;As&nbsp;New&nbsp;InMemoryMarkerOverlay("MarkerOverlay")  
  
&nbsp;&nbsp;&nbsp;''tgMap.CustomOverlays.Add(markerOverlay)

&nbsp;Catch&nbsp;ex&nbsp;As&nbsp;Exception  
  
&nbsp;&nbsp;&nbsp;Stop  
  
&nbsp;&nbsp;End&nbsp;Try  
  
&nbsp;&nbsp;'tgMap.refresh()

&nbsp;End&nbsp;Sub

&nbsp;Private&nbsp;Sub&nbsp;Open\_jp2\_map(ByVal&nbsp;MpPath&nbsp;As&nbsp;String)

&nbsp;&nbsp;If&nbsp;mapOverlay.Layers.Contains(MpPath)&nbsp;Then  
  
&nbsp;&nbsp;&nbsp;mapOverlay.Layers.Remove(MpPath)  
  
&nbsp;&nbsp;End&nbsp;If

&nbsp;&nbsp;tgMap0.MapUnit&nbsp;=&nbsp;GeographyUnit.DecimalDegree

&nbsp;&nbsp;Dim&nbsp;mapLayer&nbsp;As&nbsp;New&nbsp;Jpeg2000RasterLayer(MpPath)  
  
&nbsp;&nbsp;mapLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue  
  
&nbsp;&nbsp;mapLayer.LowerThreshold&nbsp;=&nbsp;0

&nbsp;&nbsp;'tgMap0.BackgroundOverlay.IsVisible&nbsp;=&nbsp;False

&nbsp;&nbsp;mapLayer.Name&nbsp;=&nbsp;MpPath  
  
&nbsp;&nbsp;mapLayer.Open()

&nbsp;&nbsp;mapOverlay.Layers.Add(MpPath,&nbsp;mapLayer)  
  
&nbsp;&nbsp;tgMap0.CustomOverlays.Add(mapOverlay)

&nbsp;&nbsp;'tgMap.CurrentExtent&nbsp;=&nbsp;GetFullExtent()

&nbsp;&nbsp;'tgMap.Refresh()

&nbsp;End&nbsp;Sub

[1288-Map.zip](https://community.thinkgeo.com/uploads/default/original/2X/7/78ee559d3a4d2bbd44a98b7322e613682a4061ab.zip) (163 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:** [October 9, 2009, 2:34am UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/4 "2009-10-09T02:34:10Z")

</div>

Bob,&nbsp;  
  
  
  
We&nbsp;used&nbsp;your&nbsp;data&nbsp;to&nbsp;implement&nbsp;a&nbsp;simple&nbsp;sample&nbsp;and&nbsp;it&nbsp;works&nbsp;fine.&nbsp;Please&nbsp;try&nbsp;our&nbsp;code&nbsp;in&nbsp;a&nbsp;new&nbsp;project.&nbsp;If&nbsp;there&nbsp;is&nbsp;any&nbsp;misunderstanding,&nbsp;please&nbsp;provide&nbsp;a&nbsp;project&nbsp;which&nbsp;we&nbsp;can&nbsp;recreate&nbsp;your&nbsp;issue&nbsp;easily;&nbsp;because&nbsp;your&nbsp;attached&nbsp;code&nbsp;cannot&nbsp;work&nbsp;on&nbsp;our&nbsp;end.  
  
  
`tgMap.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)tgMap.MapUnit = GeographyUnit.DecimalDegreetgMap.CurrentExtent = New RectangleShape(-80.5, 68.9, 80, -60.43)Dim gdiPlusImageLayer As GdiPlusRasterLayer = New GdiPlusRasterLayer(MapPath("~\SampleData\Erin.jpg"))gdiPlusImageLayer.UpperThreshold = Double.MaxValuegdiPlusImageLayer.LowerThreshold = 0tgMap.StaticOverlay.Layers.Add(gdiPlusImageLayer)`  
Thanks,  
  
Howard

---

<div class="post-metadata">

**Author:** ![va3wxw](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@va3wxw](https://community.thinkgeo.com/u/va3wxw)\
**Post date:** [October 19, 2009, 3:08am UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/5 "2009-10-19T03:08:14Z")

</div>

Howard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;was&nbsp;somehow&nbsp;able&nbsp;to&nbsp;get&nbsp;it&nbsp;to&nbsp;work&nbsp;using&nbsp;the&nbsp;following&nbsp;code&nbsp;with&nbsp;one&nbsp;problem.&nbsp;&nbsp;It&nbsp;now&nbsp;displays&nbsp;grid&nbsp;lines&nbsp;which&nbsp;become&nbsp;more&nbsp;numerous&nbsp;as&nbsp;I&nbsp;  
&nbsp;zoom&nbsp;in.&nbsp;&nbsp;How&nbsp;do&nbsp;I&nbsp;get&nbsp;rid&nbsp;of&nbsp;these?&nbsp;&nbsp;I&nbsp;think&nbsp;the&nbsp;code&nbsp;you&nbsp;gave&nbsp;in&nbsp;the&nbsp;post&nbsp;above&nbsp;with&nbsp;static&nbsp;overlay&nbsp;might&nbsp;be&nbsp;working&nbsp;as&nbsp;well&nbsp;but&nbsp;I&nbsp;cannot&nbsp;&nbsp;  
&nbsp;seem&nbsp;to&nbsp;zoom&nbsp;in&nbsp;and&nbsp;center&nbsp;on&nbsp;the&nbsp;tiny&nbsp;map&nbsp;I&nbsp;attached&nbsp;in&nbsp;a&nbsp;previous&nbsp;post&nbsp;in&nbsp;this&nbsp;thread&nbsp;(which&nbsp;the&nbsp;GetFullExtent&nbsp;function&nbsp;takes&nbsp;care&nbsp;of&nbsp;for&nbsp;&nbsp;  
&nbsp;me&nbsp;when&nbsp;I&nbsp;use&nbsp;the&nbsp;customoverlays&nbsp;object).&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;ideas&nbsp;on&nbsp;getting&nbsp;rid&nbsp;of&nbsp;the&nbsp;grid?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Also,&nbsp;Is&nbsp;there&nbsp;a&nbsp;reason&nbsp;you&nbsp;showed&nbsp;the&nbsp;example&nbsp;using&nbsp;the&nbsp;staticoverlay&nbsp;object&nbsp;for&nbsp;the&nbsp;load&nbsp;maps&nbsp;example&nbsp;instead&nbsp;of&nbsp;the&nbsp;customoverlays&nbsp;object&nbsp;  
&nbsp;that&nbsp;I&nbsp;am&nbsp;using?&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Bob&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Private&nbsp;Sub&nbsp;Open\_Raster\_Map(ByVal&nbsp;MpPath&nbsp;As&nbsp;String)&nbsp;  
&nbsp;&nbsp;  
&nbsp; If&nbsp;mapOverlay.Layers.Contains(MapPath(MpPath))&nbsp;Then&nbsp;  
&nbsp; mapOverlay.Layers.Remove(MapPath(MpPath))&nbsp;  
&nbsp; End&nbsp;If&nbsp;  
&nbsp;&nbsp;  
&nbsp; tgMap.MapUnit&nbsp;=&nbsp;GeographyUnit.DecimalDegree&nbsp;  
&nbsp;&nbsp;  
&nbsp; tgMap.MapBackground.BackgroundBrush&nbsp;=&nbsp;New&nbsp;GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)&nbsp;  
&nbsp; Dim&nbsp;mapLayer&nbsp;As&nbsp;New&nbsp;GdiPlusRasterLayer(MapPath(MpPath))&nbsp;  
&nbsp; mapLayer.UpperThreshold&nbsp;=&nbsp;Double.MaxValue&nbsp;  
&nbsp; mapLayer.LowerThreshold&nbsp;=&nbsp;0&nbsp;  
&nbsp;&nbsp;  
&nbsp; mapLayer.Name&nbsp;=&nbsp;MapPath(MpPath)&nbsp;  
&nbsp; mapLayer.Open()&nbsp;  
&nbsp;&nbsp;  
&nbsp; mapOverlay.Layers.Add(MapPath(MpPath),&nbsp;mapLayer)&nbsp;  
&nbsp;&nbsp;  
&nbsp; tgMap.CustomOverlays.Add(mapOverlay)&nbsp;  
&nbsp;&nbsp;  
&nbsp; tgMap.CurrentExtent&nbsp;=&nbsp;GetFullExtent()&nbsp;  
&nbsp;&nbsp;  
&nbsp; End&nbsp;Sub&nbsp;  
&nbsp;Private&nbsp;Function&nbsp;GetFullExtent()&nbsp;As&nbsp;RectangleShape&nbsp;  
&nbsp; Try&nbsp;  
&nbsp; Dim&nbsp;boundingBox&nbsp;As&nbsp;RectangleShape&nbsp;=&nbsp;Nothing&nbsp;  
&nbsp;&nbsp;  
&nbsp; For&nbsp;Each&nbsp;myOverlay&nbsp;As&nbsp;Overlay&nbsp;In&nbsp;tgMap.CustomOverlays '.Overlays&nbsp;  
&nbsp;&nbsp;  
&nbsp; If&nbsp;TypeOf&nbsp;(myOverlay)&nbsp;Is&nbsp;LayerOverlay&nbsp;Then&nbsp;  
&nbsp;&nbsp;  
&nbsp; Dim&nbsp;layerOverlay&nbsp;As&nbsp;LayerOverlay&nbsp;=&nbsp;DirectCast(myOverlay,&nbsp;LayerOverlay)&nbsp;  
&nbsp;&nbsp;  
&nbsp; For&nbsp;Each&nbsp;myLayer&nbsp;As&nbsp;Layer&nbsp;In&nbsp;layerOverlay.Layers&nbsp;  
&nbsp;&nbsp;  
&nbsp; If&nbsp;myLayer.HasBoundingBox&nbsp;Then&nbsp;  
&nbsp; If&nbsp;Not&nbsp;myLayer.IsOpen&nbsp;Then&nbsp;  
&nbsp; myLayer.Open()&nbsp;  
&nbsp; End&nbsp;If&nbsp;  
&nbsp;&nbsp;  
&nbsp; If&nbsp;boundingBox&nbsp;Is&nbsp;Nothing&nbsp;Then&nbsp;  
&nbsp; boundingBox&nbsp;=&nbsp;myLayer.GetBoundingBox()&nbsp;  
&nbsp; Else&nbsp;  
&nbsp; boundingBox.ExpandToInclude(myLayer.GetBoundingBox())&nbsp;  
&nbsp; End&nbsp;If&nbsp;  
&nbsp; End&nbsp;If&nbsp;  
&nbsp; Next&nbsp;  
&nbsp; End&nbsp;If&nbsp;  
&nbsp; Next&nbsp;  
&nbsp;&nbsp;  
&nbsp; GetFullExtent&nbsp;=&nbsp;boundingBox&nbsp;  
&nbsp; Catch&nbsp;ex&nbsp;As&nbsp;Exception&nbsp;  
&nbsp; Stop&nbsp;  
&nbsp;&nbsp;  
&nbsp; End&nbsp;Try&nbsp;  
&nbsp;&nbsp;  
&nbsp; End&nbsp;Function&nbsp;  
&nbsp;Bob&nbsp;

---

<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:** [October 19, 2009, 9:02pm UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/6 "2009-10-19T21:02:07Z")

</div>

Bob,&nbsp;  
  
  
  
Do&nbsp;you&nbsp;mean&nbsp;the&nbsp;grid&nbsp;is&nbsp;the&nbsp;joints&nbsp;between&nbsp;the&nbsp;tiles?&nbsp;We&nbsp;have&nbsp;an&nbsp;installed&nbsp;sample&nbsp;which&nbsp;use&nbsp;the&nbsp;RasterLayer;&nbsp;but&nbsp;it&nbsp;works&nbsp;fine&nbsp;without&nbsp;the&nbsp;grid&nbsp;you&nbsp;mentioned.&nbsp;  
  
[websamples.thinkgeo.com/webe...Image.aspx](http://websamples.thinkgeo.com/webeditionsamples/Samples/SatelliteImage/DisplayASatelliteImage.aspx)  
  
  
  
If&nbsp;there&nbsp;is&nbsp;any&nbsp;misunderstanding,&nbsp;please&nbsp;provide&nbsp;us&nbsp;a&nbsp;screenshot&nbsp;and&nbsp;upgrade&nbsp;our&nbsp;product&nbsp;to&nbsp;the&nbsp;latest&nbsp;version.  
  
  
  
On&nbsp;the&nbsp;other&nbsp;hand,&nbsp;the&nbsp;only&nbsp;reason&nbsp;I&nbsp;use&nbsp;StaticOverlay&nbsp;is&nbsp;that&nbsp;the&nbsp;sample&nbsp;is&nbsp;simple&nbsp;which&nbsp;only&nbsp;maintains&nbsp;a&nbsp;layer.&nbsp;It&nbsp;simplifies&nbsp;the&nbsp;code&nbsp;in&nbsp;the&nbsp;sample.&nbsp;Please&nbsp;try&nbsp;to&nbsp;think&nbsp;how&nbsp;much&nbsp;code&nbsp;will&nbsp;we&nbsp;use&nbsp;in&nbsp;CustomOverlay.  
  
  
  
Please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;questions.  
  
  
  
Thanks,  
  
Howard

---

<div class="post-metadata">

**Author:** ![va3wxw](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@va3wxw](https://community.thinkgeo.com/u/va3wxw)\
**Post date:** [October 21, 2009, 12:09pm UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/7 "2009-10-21T12:09:29Z")

</div>

Hi&nbsp;Howard,

Thanks&nbsp;for&nbsp;the&nbsp;quick&nbsp;reply!&nbsp;&nbsp;I&nbsp;have&nbsp;attached&nbsp;a&nbsp;jpg&nbsp;file&nbsp;to&nbsp;illustrate&nbsp;what&nbsp;I&nbsp;mean.&nbsp;&nbsp;Where&nbsp;can&nbsp;I&nbsp;download&nbsp;an&nbsp;update&nbsp;of&nbsp;the&nbsp;controls&nbsp;from?&nbsp;&nbsp;Can&nbsp;I&nbsp;just&nbsp;download&nbsp;the&nbsp;trial&nbsp;versions&nbsp;or&nbsp;do&nbsp;I&nbsp;have&nbsp;to&nbsp;login&nbsp;to&nbsp;download&nbsp;another&nbsp;one?  
  
  
  
Bob

&nbsp;

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 23, 2009, 4:45am UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/8 "2009-10-23T04:45:34Z")

</div>

Hi&nbsp;Bob,

We&nbsp;didn’t&nbsp;see&nbsp;and&nbsp;receive&nbsp;your&nbsp;screenshot&nbsp;file.&nbsp;Please&nbsp;check&nbsp;it&nbsp;or&nbsp;send&nbsp;the&nbsp;screenshot&nbsp;to&nbsp;[support@thinkgeo.com](mailto:support@thinkgeo.com)&nbsp;and&nbsp;ask&nbsp;him&nbsp;forward&nbsp;to&nbsp;Howard&nbsp;or&nbsp;Sun.&nbsp;And&nbsp;you&nbsp;can&nbsp;just&nbsp;download&nbsp;the&nbsp;trial&nbsp;version&nbsp;then&nbsp;install&nbsp;it&nbsp;to&nbsp;have&nbsp;a&nbsp;try,&nbsp;and&nbsp;the&nbsp;trial&nbsp;version&nbsp;is&nbsp;here:  
[gis.thinkgeo.com/Products/Ma...fault.aspx](http://gis.thinkgeo.com/Products/MapSuiteFreeTrialDownloads/tabid/152/Default.aspx)  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;let&nbsp;us&nbsp;know.  
Thanks,  
Sun

---

<div class="post-metadata">

**Author:** ![va3wxw](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@va3wxw](https://community.thinkgeo.com/u/va3wxw)\
**Post date:** [October 29, 2009, 8:56am UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/9 "2009-10-29T08:56:23Z")

</div>

K.&nbsp;&nbsp;I'll&nbsp;try&nbsp;attaching&nbsp;here&nbsp;once&nbsp;more&nbsp;and&nbsp;if&nbsp;it&nbsp;doesn't&nbsp;work,&nbsp;will&nbsp;email&nbsp;to&nbsp;support.

Bob

&nbsp;

---

<div class="post-metadata">

**Author:** ![va3wxw](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/v/8797f3/32.png) [@va3wxw](https://community.thinkgeo.com/u/va3wxw)\
**Post date:** [October 29, 2009, 9:01am UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/10 "2009-10-29T09:01:29Z")

</div>

OK.&nbsp;&nbsp;This&nbsp;should&nbsp;work.&nbsp;&nbsp;

Bob

&nbsp;

&nbsp;

 ![](https://community.thinkgeo.com/uploads/default/original/2X/0/016a501529f5409c0dc14e96aa23216c85135c3c.jpg)

&nbsp;

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [October 29, 2009, 9:02pm UTC](https://community.thinkgeo.com/t/object-reference-not-set-to-an-instance-of-an-object-when-adding-layers/5001/11 "2009-10-29T21:02:41Z")

</div>

Hi&nbsp;Bob,

Are&nbsp;you&nbsp;using&nbsp;the&nbsp;latest&nbsp;public&nbsp;release&nbsp;version&nbsp;(3.1.273)&nbsp;of&nbsp;WebEdition&nbsp;in&nbsp;your&nbsp;application?&nbsp;We&nbsp;have&nbsp;done&nbsp;a&nbsp;simple&nbsp;sample&nbsp;which&nbsp;uses&nbsp;the&nbsp;code&nbsp;and&nbsp;data&nbsp;file&nbsp;(“Erin&nbsp;1.jpg”)&nbsp;you&nbsp;supplied&nbsp;in&nbsp;this&nbsp;post,&nbsp;and&nbsp;it&nbsp;works&nbsp;fine&nbsp;in&nbsp;our&nbsp;machine.&nbsp;Please&nbsp;get&nbsp;this&nbsp;sample&nbsp;from&nbsp;the&nbsp;attachment&nbsp;to&nbsp;take&nbsp;a&nbsp;look.  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;let&nbsp;us&nbsp;know.  
Thanks,  
Sun&nbsp;  
  
[1379-Post6394.zip](https://community.thinkgeo.com/uploads/default/original/2X/7/791b12a0ff3359e785854878b63c1d14df107992.zip) (180 KB)
