Well, here is the entire class. I am getting different errors now that I updated to the 3/23 daily build.:
The latest error
System.IndexOutOfRangeException: Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount)
at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)
at ThinkGeo.MapSuite.Core.x1268e619012e8ab7.GetRecordOffset(Int32 recordIndex)
at ThinkGeo.MapSuite.Core.xdad12102199d8695.ReadRecord(Int32 recordIndex)
at ThinkGeo.MapSuite.Core.ShapeFileFeatureSource.GetFeaturesForDrawingCore(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)
at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesForDrawing(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)
at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.Overlay.MainDraw(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x03e3d48bcfe7bb6c(IEnumerable`1 xa6f0db4f183189f1)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xff5b27c00f9678c2(RectangleShape x178b193eec228e6e)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xe3cee4adb9c72451()
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xc8fbf8304fe7558e(InteractionArguments x195facd4ef5d753d)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xfeca3317d3c75bbb(Object xd9272088e65bd176, x6a8380ab1a7ebb4c xc2fd4c0ed406cdb7)
at ThinkGeo.MapSuite.DesktopEdition.x5cd462d41be2f68a.OnMouseEvent(x6a8380ab1a7ebb4c e)
at ThinkGeo.MapSuite.DesktopEdition.x5cd462d41be2f68a.AnalyseMouseWheel(Double screenX, Double screenY, Double worldX, Double worldY, Int32 delta)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xb0cb8571d4771126(Object xd9272088e65bd176, MouseEventArgs xc2fd4c0ed406cdb7)
at System.Windows.Forms.Control.OnMouseWheel(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseWheel(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
And here is the form code:
Imports ThinkGeo.MapSuite.Core
Imports ThinkGeo.MapSuite.DesktopEdition
Namespace Controls
Public Class ctlNearMeMap
Private Const MAX_ZOOM_FEET As Int32 = 3000
Private m_foreclosuresLayer As InMemoryFeatureLayer
Private m_tempForeclosuresLayer As InMemoryFeatureLayer
Private m_listingsLayer As InMemoryFeatureLayer
Private m_tempListingsLayer As InMemoryFeatureLayer
Private m_reoLayer As InMemoryFeatureLayer
Private m_tempReoLayer As InMemoryFeatureLayer
Private m_markerOverlay As ThinkGeo.MapSuite.DesktopEdition.SimpleMarkerOverlay
Private m_tempMarkerOverlay As ThinkGeo.MapSuite.DesktopEdition.SimpleMarkerOverlay
Private m_backgroundUpdateThread As System.Threading.Thread = Nothing
Private m_threadSpecifiedLocation As PointShape = New PointShape(0, 0)
Private m_threadFeetFromLocation As Int32 = 0
Private m_lastPosition As PointShape = New PointShape(0, 0)
Private m_lastThreadMessage As String = ""
Private m_clearErrorCounter As Int32 = 0
Private m_otherOverlay As LayerOverlay
Private m_booksOverlay As LayerOverlay
Private m_autoUpdateAgain As Boolean = False
Dim pos As Int32 = 0
Dim tempKey As String
Private m_hotspotFeatures As New Generic.Dictionary(Of String, NVC.Maricopa.BusinessObjects.HotspotProperty)
Private Sub ctlNearMeMap_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim tempCurrentPath As String = My.Application.Info.DirectoryPath
Dim saveCursor As Cursor = Cursor.Current
Dim tempOverlay As ThinkGeo.MapSuite.DesktopEdition.LayerOverlay
Dim tempLayer As ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer
Dim currentLocation As PointShape
lblMapStatus.Text = ""
lblMapStatus.BringToFront()
If GlobalInfo.CurrentUser.GetCurrentService("FORECLOSURES", NVC.Cais.BusinessObjects.User.COUNTY_MARICOPA).ExpireDate < Date.Now And GlobalInfo.CurrentUser.Admin = False Then
ForeclosuresCheckEdit.Enabled = False
ForeclosuresCheckEdit.Checked = False
Else
ForeclosuresCheckEdit.Enabled = True
ForeclosuresCheckEdit.Checked = True
End If
If GlobalInfo.CurrentUser.GetCurrentService("REOS", NVC.Cais.BusinessObjects.User.COUNTY_MARICOPA).ExpireDate < Date.Now And GlobalInfo.CurrentUser.Admin = False Then
ReoCheckEdit.Enabled = False
ReoCheckEdit.Checked = False
Else
ReoCheckEdit.Enabled = True
ReoCheckEdit.Checked = True
End If
If GlobalInfo.CurrentUser.SpecialAccess1 = False And GlobalInfo.CurrentUser.Admin = False Then
ListingsCheckEdit.Enabled = False
ListingsCheckEdit.Checked = False
Else
ListingsCheckEdit.Enabled = True
ListingsCheckEdit.Checked = True
End If
Try
Cursor.Current = Cursors.WaitCursor
m_otherOverlay = New ThinkGeo.MapSuite.DesktopEdition.LayerOverlay()
tempOverlay = m_otherOverlay
m_tempForeclosuresLayer = New InMemoryFeatureLayer
m_foreclosuresLayer = New InMemoryFeatureLayer()
With m_foreclosuresLayer.ZoomLevelSet.ZoomLevel01
.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.SimpleColors.Green)
.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.DarkGreen
.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
End With
m_foreclosuresLayer.IsVisible = ForeclosuresCheckEdit.Checked
tempOverlay.Layers.Add(m_foreclosuresLayer)
m_tempListingsLayer = New InMemoryFeatureLayer
m_listingsLayer = New InMemoryFeatureLayer()
With m_listingsLayer.ZoomLevelSet.ZoomLevel01
.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Purple)
.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.DarkViolet
.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
End With
m_listingsLayer.IsVisible = ListingsCheckEdit.Checked
tempOverlay.Layers.Add(m_listingsLayer)
m_tempReoLayer = New InMemoryFeatureLayer
m_reoLayer = New InMemoryFeatureLayer()
With m_reoLayer.ZoomLevelSet.ZoomLevel01
.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Orange)
.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.DarkOrange
.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
End With
m_reoLayer.IsVisible = ReoCheckEdit.Checked
tempOverlay.Layers.Add(m_reoLayer)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{0}\maps\Maricopa\streets.SHP", tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
With tempLayer.ZoomLevelSet.ZoomLevel01
.CustomStyles.Add(TextStyles.LocalRoad1("ROUTENAME"))
.CustomStyles.Add(LineStyles.LocalRoad1)
.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.StandardColors.DarkGray))
.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
End With
tempOverlay.Layers.Add("Streets", tempLayer)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{0}\maps\Maricopa\Canals.SHP", tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
With tempLayer.ZoomLevelSet.ZoomLevel01
.CustomStyles.Add(TextStyles.Canal1("FEATNAME"))
.CustomStyles.Add(LineStyles.Canal1)
.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.StandardColors.DeepSkyBlue))
.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
End With
tempOverlay.Layers.Add("Canals", tempLayer)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{0}\maps\Maricopa\Lakes.SHP", tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
With tempLayer.ZoomLevelSet.ZoomLevel01
.CustomStyles.Add(AreaStyles.Water1)
.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
End With
tempOverlay.Layers.Add("Lakes", tempLayer)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{0}\maps\Maricopa\Rivers.SHP", tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
With tempLayer.ZoomLevelSet.ZoomLevel01
.CustomStyles.Add(AreaStyles.Water1)
.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
End With
tempOverlay.Layers.Add("Rivers", tempLayer)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{0}\maps\Maricopa\Streams.SHP", tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
With tempLayer.ZoomLevelSet.ZoomLevel01
.CustomStyles.Add(AreaStyles.Water1)
.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
End With
tempOverlay.Layers.Add("Streams", tempLayer)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{0}\maps\Maricopa\Parks.SHP", tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
With tempLayer.ZoomLevelSet.ZoomLevel01
.CustomStyles.Add(AreaStyles.Park1)
.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
End With
tempOverlay.Layers.Add("Parks", tempLayer)
WinformsMap1.Overlays.Add("Other", tempOverlay)
m_tempMarkerOverlay = New SimpleMarkerOverlay
m_markerOverlay = New SimpleMarkerOverlay
m_markerOverlay.MapControl = WinformsMap1
WinformsMap1.Overlays.Add("SimpleMarker", m_markerOverlay)
m_booksOverlay = New ThinkGeo.MapSuite.DesktopEdition.LayerOverlay()
For pos = 1 To 5
tempKey = String.Format("Book{0}00", pos)
tempLayer = New ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer(String.Format("{1}\maps\Maricopa\{0}.SHP", tempKey, tempCurrentPath), ShapeFileReadWriteMode.ReadOnly)
tempLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.StandardColors.Black)
tempLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ThinkGeo.MapSuite.Core.ApplyUntilZoomLevel.Level20
m_booksOverlay.Layers.Add(tempKey, tempLayer)
Next
WinformsMap1.Overlays.Add("Books", m_booksOverlay)
With WinformsMap1
.MapUnit = ThinkGeo.MapSuite.Core.GeographyUnit.DecimalDegree
.BackgroundOverlay.BackgroundBrush = New ThinkGeo.MapSuite.Core.GeoSolidBrush(ThinkGeo.MapSuite.Core.GeoColor.StandardColors.LightGoldenrodYellow)
' .Refresh()
End With
If GlobalInfo.GpsStatus.GpsAvailable = True And GlobalInfo.GpsStatus.FixObtained = True Then
Cursor.Current = Cursors.WaitCursor
pnlGpsOptions.Enabled = True
currentLocation = New PointShape(GlobalInfo.GpsStatus.Longitude, GlobalInfo.GpsStatus.Latitude)
m_lastPosition = currentLocation
SetExtentToSpecifiedLocation(currentLocation, True)
WinformsMap1.Refresh()
m_threadSpecifiedLocation = currentLocation
m_threadFeetFromLocation = CInt(DecimalDegreesHelper.GetDistanceFromDecimalDegrees(WinformsMap1.CurrentExtent.UpperLeftPoint, WinformsMap1.CurrentExtent.LowerRightPoint, DistanceUnit.Feet))
Else
pnlGpsOptions.Enabled = False
End If
Finally
Cursor.Current = saveCursor
End Try
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub btnReloadFromGps_Click(sender As System.Object, e As System.EventArgs) Handles btnReloadFromGps.Click
Dim currentLocation As PointShape
Dim saveCursor As Cursor = Cursor.Current
If GlobalInfo.GpsStatus.FixObtained = True Then
currentLocation = New PointShape(GlobalInfo.GpsStatus.Longitude, GlobalInfo.GpsStatus.Latitude)
Try
Cursor.Current = Cursors.WaitCursor
SetExtentToSpecifiedLocation(currentLocation, True)
WinformsMap1.Refresh()
SyncLock m_threadSpecifiedLocation
m_threadSpecifiedLocation = currentLocation
m_threadFeetFromLocation = CInt(DecimalDegreesHelper.GetDistanceFromDecimalDegrees(WinformsMap1.CurrentExtent.UpperLeftPoint, WinformsMap1.CurrentExtent.LowerRightPoint, DistanceUnit.Feet))
m_autoUpdateAgain = True
End SyncLock
Finally
Cursor.Current = saveCursor
End Try
Else
System.Windows.Forms.MessageBox.Show("No satelite fix obtained")
End If
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
WinformsMap1.Dispose()
Me.Close()
End Sub
Private Sub SetExtentToSpecifiedLocation(p_specifiedLocation As PointShape, p_createMarker As Boolean)
Dim tempExtent As RectangleShape
Dim longitudeDifference As Double
Dim latitudeDifference As Double
If p_createMarker = True Then
CreateYouAreHereMarker(p_specifiedLocation)
End If
latitudeDifference = DecimalDegreesHelper.GetLatitudeDifferenceFromDistance(500, DistanceUnit.Feet, p_specifiedLocation.X)
longitudeDifference = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(500, DistanceUnit.Feet, p_specifiedLocation.Y)
tempExtent = New RectangleShape(p_specifiedLocation.X - longitudeDifference, p_specifiedLocation.Y + latitudeDifference, p_specifiedLocation.X + longitudeDifference, p_specifiedLocation.Y - latitudeDifference)
WinformsMap1.CurrentExtent = tempExtent
End Sub
Private Sub CreateYouAreHereMarker(ByVal p_specifiedLocation As PointShape)
Dim tempMarker As Marker
SyncLock m_markerOverlay
If m_markerOverlay.Markers.Contains("CurrentLocation") = True Then
m_markerOverlay.Markers.Remove("CurrentLocation")
End If
tempMarker = New Marker(p_specifiedLocation.X, p_specifiedLocation.Y)
With tempMarker
.Image = My.Resources.Man_24
.Width = 24
.Height = 24
.YOffset = 0
.XOffset = 0
.ToolTipText = "You are here"
End With
m_markerOverlay.Markers.Add("CurrentLocation", tempMarker)
End SyncLock
End Sub
Private Sub StartLocalFeaturesThread()
m_backgroundUpdateThread = New System.Threading.Thread(AddressOf Me.GetLocalFeatures)
m_backgroundUpdateThread.Start()
End Sub
Private Sub ProcessNewFeatures()
Dim tempFeature As Feature
Dim tempMarker As Marker
Dim tempKey As String
Dim saveCursor As Cursor = Cursor.Current
Try
Cursor.Current = Cursors.WaitCursor
If m_tempForeclosuresLayer.InternalFeatures.Count > 0 Then
SyncLock m_tempForeclosuresLayer.InternalFeatures
For Each tempKey In m_tempForeclosuresLayer.InternalFeatures.GetKeys
tempFeature = m_tempForeclosuresLayer.InternalFeatures(tempKey)
m_foreclosuresLayer.InternalFeatures.Add(tempKey, tempFeature)
Next
m_tempForeclosuresLayer.InternalFeatures.Clear()
End SyncLock
End If
If m_tempReoLayer.InternalFeatures.Count > 0 Then
SyncLock m_tempReoLayer.InternalFeatures
For Each tempKey In m_tempReoLayer.InternalFeatures.GetKeys
tempFeature = m_tempReoLayer.InternalFeatures(tempKey)
m_reoLayer.InternalFeatures.Add(tempKey, tempFeature)
Next
m_tempReoLayer.InternalFeatures.Clear()
End SyncLock
End If
If m_tempListingsLayer.InternalFeatures.Count > 0 Then
SyncLock m_tempListingsLayer.InternalFeatures
For Each tempKey In m_tempListingsLayer.InternalFeatures.GetKeys
tempFeature = m_tempListingsLayer.InternalFeatures(tempKey)
m_listingsLayer.InternalFeatures.Add(tempKey, tempFeature)
Next
m_tempListingsLayer.InternalFeatures.Clear()
End SyncLock
End If
If m_tempMarkerOverlay.Markers.Count > 0 Then
SyncLock m_tempMarkerOverlay.Markers
For Each tempKey In m_tempMarkerOverlay.Markers.GetKeys
tempMarker = m_tempMarkerOverlay.Markers(tempKey)
m_markerOverlay.Markers.Add(tempKey, tempMarker)
Next
m_tempMarkerOverlay.Markers.Clear()
End SyncLock
End If
Finally
Cursor.Current = saveCursor
End Try
End Sub
Private Sub GetLocalFeatures()
Dim tempCurrentPath As String = My.Application.Info.DirectoryPath
Dim tempSpecifiedLocation As PointShape
Dim tempFeetFromLocation As Int32
Dim tempOverlay As ThinkGeo.MapSuite.DesktopEdition.LayerOverlay
Dim tempLayer As ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer
'Dim tempFeature As Feature
Dim longitudeDifference As Double
Dim latitudeDifference As Double
Dim latitudeLow As Double
Dim latitudeHigh As Double
Dim longitudeLow As Double
Dim longitudeHigh As Double
Dim resultObject As Warp10.Framework.BaseObjects.BaseResult = Nothing
Dim apDAO As NVC.Maricopa.DataAccess.AllProperties
Dim tempAllProperty As NVC.Maricopa.BusinessObjects.AllProperty = Nothing
Dim whereClause As String
Dim tempKey As String
Try
SyncLock m_threadSpecifiedLocation
tempSpecifiedLocation = m_threadSpecifiedLocation
tempFeetFromLocation = m_threadFeetFromLocation
m_autoUpdateAgain = False
m_threadSpecifiedLocation = New PointShape(0, 0)
m_threadFeetFromLocation = 0
End SyncLock
If tempSpecifiedLocation.X = 0 Or tempSpecifiedLocation.Y = 0 Or tempFeetFromLocation = 0 Then
SyncLock m_lastThreadMessage
m_lastThreadMessage = "No position specified"
End SyncLock
Return
End If
latitudeDifference = DecimalDegreesHelper.GetLatitudeDifferenceFromDistance(250, DistanceUnit.Feet, tempSpecifiedLocation.X)
longitudeDifference = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(250, DistanceUnit.Feet, tempSpecifiedLocation.Y)
latitudeLow = tempSpecifiedLocation.Y - latitudeDifference
latitudeHigh = tempSpecifiedLocation.Y + latitudeDifference
longitudeLow = tempSpecifiedLocation.X - longitudeDifference
longitudeHigh = tempSpecifiedLocation.X + longitudeDifference
apDAO = New NVC.Maricopa.DataAccess.AllProperties(GlobalInfo.ConnectionOptionsMaricopaNew)
apDAO.MaxResults = 1
apDAO.MaxResultBehavior = Warp10.Framework.BaseObjects.DataAccess.BaseDataAccessClass.MaxResultErrorBehaviors.StopProcessing
whereClause = String.Format("(ap.[Latitude] BETWEEN {0} AND {1}) AND (ap.[Longitude] BETWEEN {2} AND {3})", latitudeLow, latitudeHigh, longitudeLow, longitudeHigh)
resultObject = apDAO.Query(whereClause, False)
Select Case resultObject.ResultType
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Error
SyncLock m_lastThreadMessage
m_lastThreadMessage = String.Format("ERROR: {0}", resultObject.Message)
End SyncLock
Return
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Warning
SyncLock m_lastThreadMessage
m_lastThreadMessage = "No nearby properties found in Maricopa database"
End SyncLock
Return
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Success
tempAllProperty = CType(resultObject.Data, NVC.Maricopa.BusinessObjects.AllPropertyCollection)(0)
End Select
tempOverlay = m_booksOverlay
Catch ex As Exception
SyncLock m_lastThreadMessage
m_lastThreadMessage = String.Format("ERROR in GetLocalFeaturesThread: {0}", ex.Message)
End SyncLock
Return
End Try
'this will guarantee no crash due to invalid apn value from db
If tempAllProperty.Apn.Length = 0 Then
tempAllProperty.Apn = "0"
End If
Select Case tempAllProperty.Apn.Substring(0, 1)
Case "1", "2", "3", "4", "5"
tempKey = String.Format("Book{0}00", tempAllProperty.Apn.Substring(0, 1))
If tempOverlay.Layers.Contains(tempKey) = True Then
tempLayer = CType(tempOverlay.Layers(tempKey), ShapeFileFeatureLayer)
Else
SyncLock m_lastThreadMessage
m_lastThreadMessage = String.Format("Layer {0} not found in map", tempKey)
End SyncLock
Return
End If
Try
GetLocalFeaturesFromLayer(tempLayer, tempSpecifiedLocation, tempFeetFromLocation)
Catch ex As Exception
SyncLock m_lastThreadMessage
m_lastThreadMessage = String.Format("ERROR calling GetLocalFeaturesFromLayer: {0}", ex.Message)
End SyncLock
End Try
Case Else
SyncLock m_lastThreadMessage
m_lastThreadMessage = "Invalid Apn found in Maricopa database"
End SyncLock
End Select
End Sub
Private Sub GetLocalFeaturesFromLayer(ByVal p_layer As ThinkGeo.MapSuite.Core.ShapeFileFeatureLayer, ByVal p_specifiedLocation As ThinkGeo.MapSuite.Core.PointShape, p_feetFromLocation As Int32)
Dim tempFeature As ThinkGeo.MapSuite.Core.Feature
'Dim tempFeatureIdCollection As New System.Collections.ObjectModel.Collection(Of String)
Dim tempLocalFeatures As System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.Feature)
Dim tempMarker As Marker
Dim tempHotspot As NVC.Maricopa.BusinessObjects.HotspotProperty
Dim tempHotspotCollection As NVC.Maricopa.BusinessObjects.HotspotPropertyCollection = Nothing
tempHotspotCollection = GetHotspotPropertiesForLocation(p_specifiedLocation)
If tempHotspotCollection Is Nothing Then
Return
End If
'get shape features close to specified location to make matching up with hotspots faster
p_layer.Open()
Try
tempLocalFeatures = p_layer.QueryTools.GetFeaturesWithinDistanceOf(p_specifiedLocation, GeographyUnit.DecimalDegree, DistanceUnit.Feet, p_feetFromLocation, New String(0) {"APN"})
Catch ex As Exception
tempLocalFeatures = New System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.Feature)
End Try
p_layer.Close()
'now loop through hotspots and match them up if necessary
For Each tempHotspot In tempHotspotCollection
If m_hotspotFeatures.ContainsKey(tempHotspot.Apn) = True Then
'item already added to map, skip!
Continue For
End If
For Each tempFeature In tempLocalFeatures
If tempFeature.ColumnValues("APN") = tempHotspot.Apn Then
'add appropriate markers
With tempHotspot
If .TrusteeSaleID <> 0 Then
'add foreclosure marker and colored shape (you will never have both foreclosure and reo on same property)
SyncLock m_tempForeclosuresLayer.InternalFeatures
m_tempForeclosuresLayer.InternalFeatures.Add(tempFeature)
End SyncLock
tempMarker = GetMarkerForForeclosure(tempFeature, tempHotspot)
SyncLock m_tempMarkerOverlay.Markers
m_tempMarkerOverlay.Markers.Add(String.Format("{0}Foreclosure", tempHotspot.Apn), tempMarker)
End SyncLock
ElseIf .ReoPropertyID <> 0 Then
'add reo marker and colored shape
SyncLock m_tempReoLayer.InternalFeatures
m_tempReoLayer.InternalFeatures.Add(tempFeature)
End SyncLock
tempMarker = GetMarkerForReo(tempFeature, tempHotspot)
SyncLock m_tempMarkerOverlay.Markers
m_tempMarkerOverlay.Markers.Add(String.Format("{0}Reo", tempHotspot.Apn), tempMarker)
End SyncLock
End If
If .Listed = True Then
'add listed marker and colored shape (both foreclosures and reos can be listed so marker is offset in a different location)
SyncLock m_tempListingsLayer.InternalFeatures
m_tempListingsLayer.InternalFeatures.Add(tempFeature)
End SyncLock
tempMarker = GetMarkerForListed(tempFeature, tempHotspot)
SyncLock m_tempMarkerOverlay.Markers
m_tempMarkerOverlay.Markers.Add(String.Format("{0}Listing", tempHotspot.Apn), tempMarker)
End SyncLock
End If
End With
'add hotspot to dictionary indicating it is already on the map
SyncLock m_hotspotFeatures
m_hotspotFeatures.Add(tempHotspot.Apn, tempHotspot)
End SyncLock
Exit For
End If
Next
Next
End Sub
Private Function GetMarkerForListed(p_Feature As Feature, p_hotspot As NVC.Maricopa.BusinessObjects.HotspotProperty) As Marker
Dim tempMarker As Marker
tempMarker = New Marker(p_Feature.GetShape.GetCenterPoint.X, p_Feature.GetShape.GetCenterPoint.Y)
With tempMarker
.Image = New System.Drawing.Bitmap(My.Resources.MapMarkerListing)
.Width = 16
.Height = 16
.YOffset = -8
.XOffset = 8
.ToolTipText = String.Format("FOR SALE{0}APN: {1}{0}Price: {2:c0}{0}EstValue: {3:c0}", vbCrLf, p_hotspot.Apn, p_hotspot.ListPrice, p_hotspot.EstValue)
.Tag = p_hotspot.Apn
End With
Return tempMarker
End Function
Private Function GetMarkerForReo(p_Feature As Feature, p_hotspot As NVC.Maricopa.BusinessObjects.HotspotProperty) As Marker
Dim tempMarker As Marker
tempMarker = New Marker(p_Feature.GetShape.GetCenterPoint.X, p_Feature.GetShape.GetCenterPoint.Y)
With tempMarker
.Image = New System.Drawing.Bitmap(My.Resources.MapMarkerReo)
.Width = 16
.Height = 16
.YOffset = -8
.XOffset = -9
If p_hotspot.Listed = True Then
.ToolTipText = String.Format("BANK OWNED{0}APN: {1}{0}Bank: {2:c0}{0}Listed: Yes{0}EstValue: {3:c0}", vbCrLf, p_hotspot.Apn, p_hotspot.OwnerName, p_hotspot.EstValue)
Else
.ToolTipText = String.Format("BANK OWNED{0}APN: {1}{0}Bank: {2:c0}{0}Listed: No{0}EstValue: {3:c0}", vbCrLf, p_hotspot.Apn, p_hotspot.OwnerName, p_hotspot.EstValue)
End If
.Tag = p_hotspot.Apn
End With
Return tempMarker
End Function
Private Function GetMarkerForForeclosure(p_Feature As Feature, p_hotspot As NVC.Maricopa.BusinessObjects.HotspotProperty) As Marker
Dim tempMarker As Marker
tempMarker = New Marker(p_Feature.GetShape.GetCenterPoint.X, p_Feature.GetShape.GetCenterPoint.Y)
With tempMarker
If p_hotspot.SaleDate > Date.Now And p_hotspot.SaleDate < Date.Now.AddDays(5) Then
.Image = New System.Drawing.Bitmap(My.Resources.MapMarkerForeclosureSoon)
Else
.Image = New System.Drawing.Bitmap(My.Resources.MapMarkerForeclosure)
End If
.Width = 16
.Height = 16
.YOffset = -8
.XOffset = -9
If p_hotspot.Listed = True Then
.ToolTipText = String.Format("PENDING AUCTION{0}APN: {1}{0}SaleDate: {2:d}{0}Listed: Yes{0}OpenBid: {3:c0}{0}EstValue: {4:c0}", vbCrLf, p_hotspot.Apn, p_hotspot.SaleDate, p_hotspot.OpeningBid, p_hotspot.EstValue)
Else
.ToolTipText = String.Format("PENDING AUCTION{0}APN: {1}{0}SaleDate: {2:d}{0}Listed: No{0}OpenBid: {3:c0}{0}EstValue: {4:c0}", vbCrLf, p_hotspot.Apn, p_hotspot.SaleDate, p_hotspot.OpeningBid, p_hotspot.EstValue)
End If
.Tag = p_hotspot.Apn
End With
Return tempMarker
End Function
Private Function GetHotspotPropertiesForLocation(ByVal p_specifiedLocation As ThinkGeo.MapSuite.Core.PointShape) As NVC.Maricopa.BusinessObjects.HotspotPropertyCollection
Dim hsDAO As New NVC.Maricopa.DataAccess.HotspotProperties(GlobalInfo.ConnectionOptionsMaricopaNew)
Dim resultObject As Warp10.Framework.BaseObjects.BaseResult = Nothing
Dim tempHotspotCollection As NVC.Maricopa.BusinessObjects.HotspotPropertyCollection = Nothing
Dim whereClause As String
Dim longitudeDifference As Double
Dim latitudeDifference As Double
Dim latitudeLow As Double
Dim latitudeHigh As Double
Dim longitudeLow As Double
Dim longitudeHigh As Double
latitudeDifference = DecimalDegreesHelper.GetLatitudeDifferenceFromDistance(2500, DistanceUnit.Feet, p_specifiedLocation.X)
longitudeDifference = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(2500, DistanceUnit.Feet, p_specifiedLocation.Y)
latitudeLow = p_specifiedLocation.Y - latitudeDifference
latitudeHigh = p_specifiedLocation.Y + latitudeDifference
longitudeLow = p_specifiedLocation.X - longitudeDifference
longitudeHigh = p_specifiedLocation.X + longitudeDifference
whereClause = String.Format("(hp.[Latitude] BETWEEN {0} AND {1}) AND (hp.[Longitude] BETWEEN {2} AND {3}) ", latitudeLow, latitudeHigh, longitudeLow, longitudeHigh)
resultObject = hsDAO.Query(whereClause, False)
Select Case resultObject.ResultType
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Error
SyncLock m_lastThreadMessage
m_lastThreadMessage = String.Format("ERROR (GetLocalFeaturesFromLayer): {0}", resultObject.Message)
End SyncLock
Return Nothing
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Warning
Return Nothing
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Success
tempHotspotCollection = CType(resultObject.Data, NVC.Maricopa.BusinessObjects.HotspotPropertyCollection)
End Select
Return tempHotspotCollection
End Function
Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
Dim currentPosition As PointShape
Timer1.Enabled = False
If pnlGpsOptions.Enabled <> GlobalInfo.GpsStatus.FixObtained Then
pnlGpsOptions.Enabled = GlobalInfo.GpsStatus.FixObtained
End If
If m_clearErrorCounter = 1 Then
lblMapStatus.Text = ""
End If
If m_clearErrorCounter > 0 Then
m_clearErrorCounter -= 1
End If
If m_backgroundUpdateThread IsNot Nothing Then
If m_backgroundUpdateThread.IsAlive = False Then
ProcessNewFeatures()
WinformsMap1.Refresh()
m_backgroundUpdateThread = Nothing
If m_autoUpdateAgain = True Then
StartLocalFeaturesThread()
End If
End If
Else
If m_autoUpdateAgain = True Then
StartLocalFeaturesThread()
End If
End If
If AutoUpdateEdit.Checked = True Then
If GlobalInfo.GpsStatus.FixObtained = True Then
currentPosition = New PointShape(GlobalInfo.GpsStatus.Longitude, GlobalInfo.GpsStatus.Latitude)
If DecimalDegreesHelper.GetDistanceFromDecimalDegrees(currentPosition, m_lastPosition, DistanceUnit.Feet) > 50 Then
m_lastPosition = currentPosition
btnReloadFromGps_Click(btnReloadFromGps, New System.EventArgs)
End If
End If
End If
If m_lastThreadMessage.Trim <> "" Then
SyncLock m_lastThreadMessage
lblMapStatus.Text = m_lastThreadMessage
m_lastThreadMessage = ""
m_clearErrorCounter = 20 'approximately 10 seconds
End SyncLock
End If
Timer1.Enabled = True
End Sub
Private Sub WinformsMap1_CurrentExtentChanged(sender As Object, e As ThinkGeo.MapSuite.DesktopEdition.CurrentExtentChangedWinformsMapEventArgs) Handles WinformsMap1.CurrentExtentChanged
Dim centerPoint As PointShape
centerPoint = e.CurrentExtent.GetCenterPoint()
SyncLock m_threadSpecifiedLocation
m_threadSpecifiedLocation = centerPoint
m_threadFeetFromLocation = CInt(DecimalDegreesHelper.GetDistanceFromDecimalDegrees(e.CurrentExtent.UpperLeftPoint, e.CurrentExtent.LowerRightPoint, DistanceUnit.Feet))
m_autoUpdateAgain = True
End SyncLock
End Sub
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim tempSpecifiedLocation As PointShape = m_threadSpecifiedLocation
Dim tempFeetFromLocation As Int32 = m_threadFeetFromLocation
Dim resultObject As Warp10.Framework.BaseObjects.BaseResult = Nothing
Dim apDAO As NVC.Maricopa.DataAccess.AllProperties
Dim tempAllProperty As NVC.Maricopa.BusinessObjects.AllProperty = Nothing
Dim whereClause As String
Dim tempAddr As Warp10.Framework.Common.Parsing.AddressInfo
Dim tempAddrParser As Warp10.Framework.Common.Parsing.AddressParser
Dim searchParameters As Warp10.Framework.BaseObjects.DataAccess.BaseSearchParametersCollection
Dim tempPosition As PointShape
apDAO = New NVC.Maricopa.DataAccess.AllProperties(GlobalInfo.ConnectionOptionsMaricopaNew)
apDAO.MaxResults = 1
apDAO.MaxResultBehavior = Warp10.Framework.BaseObjects.DataAccess.BaseDataAccessClass.MaxResultErrorBehaviors.StopProcessing
If ApnEdit.Text.Trim <> "" Then
whereClause = String.Format("ap.[Apn] = '{0}'", ApnEdit.Text.Trim.Replace("'", "''").Replace("-", "").Replace(" ", ""))
ElseIf AddressEdit.Text.Trim <> "" Then
tempAddrParser = New Warp10.Framework.Common.Parsing.AddressParser()
tempAddr = tempAddrParser.ParseAddress(AddressEdit.Text)
searchParameters = New Warp10.Framework.BaseObjects.DataAccess.BaseSearchParametersCollection
With searchParameters
If tempAddr.Number <> 0 Then
.Add("SitusNumber", tempAddr.Number.ToString)
End If
If tempAddr.Direction.Trim <> "" Then
.Add("SitusDirection", tempAddr.Direction)
End If
If tempAddr.StreetName.Trim <> "" Then
.Add("SitusStreetName", tempAddr.StreetName)
End If
If tempAddr.Unit.Trim <> "" Then
.Add("SitusUnit", tempAddr.Unit)
End If
End With
whereClause = NVC.Maricopa.DataAccess.MaricopaProperties.BuildSQLWhereClause(searchParameters)
Else
Warp10.DeveloperExpress.Dialogs.MessageBox.Show("You must specify an address or an APN to do a manual search", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
End If
If whereClause.Trim = "" Then
Warp10.DeveloperExpress.Dialogs.MessageBox.Show("Not enough information specified to do a search", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
End If
resultObject = apDAO.Query(whereClause, False)
Select Case resultObject.ResultType
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Error
Warp10.DeveloperExpress.Dialogs.MessageBox.Show(String.Format("Error: {0}", resultObject.Message), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Warning
Warp10.DeveloperExpress.Dialogs.MessageBox.Show("No properties found", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Success
tempAllProperty = CType(resultObject.Data, NVC.Maricopa.BusinessObjects.AllPropertyCollection)(0)
End Select
If tempAllProperty.Latitude <> 0 And tempAllProperty.Longitude <> 0 Then
tempPosition = New PointShape(tempAllProperty.Longitude, tempAllProperty.Latitude)
SetExtentToSpecifiedLocation(tempPosition, True)
WinformsMap1.Refresh()
SyncLock m_threadSpecifiedLocation
m_threadSpecifiedLocation = tempPosition
m_threadFeetFromLocation = CInt(DecimalDegreesHelper.GetDistanceFromDecimalDegrees(WinformsMap1.CurrentExtent.UpperLeftPoint, WinformsMap1.CurrentExtent.LowerRightPoint, DistanceUnit.Feet))
m_autoUpdateAgain = True
End SyncLock
Else
Warp10.DeveloperExpress.Dialogs.MessageBox.Show("Geo coordinates not found for selected property.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
End If
End Sub
Private Sub ForeclosuresCheckEdit_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles ForeclosuresCheckEdit.CheckedChanged
Dim tempMarker As Marker
Dim key As String
ForeclosuresSoonCheckEdit.Checked = ForeclosuresCheckEdit.Checked
If m_foreclosuresLayer IsNot Nothing Then
m_foreclosuresLayer.IsVisible = ForeclosuresCheckEdit.Checked
For Each key In m_markerOverlay.Markers.GetKeys
If key.ToUpper.Contains("FORECLOSURE") = True Then
tempMarker = m_markerOverlay.Markers(key)
tempMarker.Visible = ForeclosuresCheckEdit.Checked
End If
Next
WinformsMap1.Refresh(m_otherOverlay)
End If
End Sub
Private Sub ReoCheckEdit_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles ReoCheckEdit.CheckedChanged
Dim tempMarker As Marker
Dim key As String
If m_reoLayer IsNot Nothing Then
m_reoLayer.IsVisible = ReoCheckEdit.Checked
For Each key In m_markerOverlay.Markers.GetKeys
If key.ToUpper.Contains("REO") = True Then
tempMarker = m_markerOverlay.Markers(key)
tempMarker.Visible = ReoCheckEdit.Checked
End If
Next
WinformsMap1.Refresh(m_otherOverlay)
End If
End Sub
Private Sub ListingsCheckEdit_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles ListingsCheckEdit.CheckedChanged
Dim tempMarker As Marker
Dim key As String
If m_listingsLayer IsNot Nothing Then
m_listingsLayer.IsVisible = ListingsCheckEdit.Checked
For Each key In m_markerOverlay.Markers.GetKeys
If key.ToUpper.Contains("LISTING") = True Then
tempMarker = m_markerOverlay.Markers(key)
tempMarker.Visible = ListingsCheckEdit.Checked
End If
Next
WinformsMap1.Refresh(m_otherOverlay)
End If
End Sub
Private Sub AutoUpdateEdit_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles AutoUpdateEdit.CheckedChanged
If AutoUpdateEdit.Checked = True Then
btnReloadFromGps.Enabled = False
AddressEdit.Enabled = False
ApnEdit.Enabled = False
btnSearch.Enabled = False
Else
btnReloadFromGps.Enabled = True
AddressEdit.Enabled = True
ApnEdit.Enabled = True
btnSearch.Enabled = True
End If
End Sub
Private Sub WinformsMap1_MapClick(sender As Object, e As ThinkGeo.MapSuite.DesktopEdition.MapClickWinformsMapEventArgs) Handles WinformsMap1.MapClick
Dim tempLocation As PointShape = e.WorldLocation
Dim pos As Int32
Dim tempKey As String
Dim tempLayer As ShapeFileFeatureLayer
Dim tempSelectedFeatures As System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.Feature)
Dim tempFeature As Feature
Dim tempApn As String
For pos = 1 To 5
tempKey = String.Format("Book{0}00", pos)
If m_booksOverlay.Layers.Contains(tempKey) = True Then
tempLayer = CType(m_booksOverlay.Layers(tempKey), ShapeFileFeatureLayer)
tempSelectedFeatures = tempLayer.QueryTools.GetFeaturesContaining(tempLocation, New String(0) {"APN"})
If tempSelectedFeatures.Count = 0 Then
Continue For
End If
tempFeature = tempSelectedFeatures(0)
tempApn = tempFeature.ColumnValues("APN").Trim
If tempApn <> "" Then
DisplayPropertyPopup(tempApn)
Return
End If
End If
Next
End Sub
Private Sub DisplayPropertyPopup(p_apn As String)
Dim resultObject As Warp10.Framework.BaseObjects.BaseResult = Nothing
Dim apDAO As New NVC.Maricopa.DataAccess.AllProperties(GlobalInfo.ConnectionOptionsMaricopaNew)
Dim tempProperty As NVC.Maricopa.BusinessObjects.AllProperty = Nothing
resultObject = apDAO.Query(String.Format("ap.[Apn] = '{0}'", p_apn.Replace("'", "''")), False)
Select Case resultObject.ResultType
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Error
Warp10.DeveloperExpress.Dialogs.MessageBox.Show(resultObject)
Return
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Warning
Warp10.DeveloperExpress.Dialogs.MessageBox.Show("Property info not found")
Return
Case Warp10.Framework.BaseObjects.BaseResult.ResultTypes.Success
tempProperty = CType(resultObject.Data, NVC.Maricopa.BusinessObjects.AllPropertyCollection)(0)
End Select
PropertyInfoBindingSource.DataSource = tempProperty
grpPropertyInfo.BringToFront()
grpPropertyInfo.Visible = True
End Sub
Private Sub btnClosePropertyInfo_Click(sender As System.Object, e As System.EventArgs) Handles btnClosePropertyInfo.Click
grpPropertyInfo.Visible = False
grpPropertyInfo.SendToBack()
End Sub
End Class
End Namespace
Hope this helps.