ThinkGeo.com    |     Documentation    |     Premium Support

VB Collection vs. Generic Collection

Hello,


I am not a paying customer currently but am evaluating the web edition of Map Suite. Potentially we may pick this up but I need to make a case for ease of use versus cost etc...


The issue I'm having at the moment is trivial. I am trying to establish track zoom by selecting a tool or having pressed a button as opposed to holding shift. Also, I will be adding other resources that utilize a trackshape such as selection features, etc.


I found this lone post in regards to trackshape: gis.thinkgeo.com/Support/Dis...fault.aspx


I am working in vb.net but have successfully been running down it trying to convert it over which is usually not too difficult. In my trackshapefinished event of my map object, this is what I have so far:



 


Dim highlightLayer As InMemoryFeatureLayer = GeoMap.DynamicOverlay.Layers("HighlightLayer")Dim parcelLayer As FeatureLayer = GeoMap.StaticOverlay.Layers("Parcels")For Each fKey As String In GeoMap.EditLayer.InternalFeatures.KeysDim trackShape As Feature = GeoMap.EditLayer.InternalFeatures(fKey)Dim fCollection As Collection = parcelLayer.QueryTools.GetFeaturesIntersecting (trackShape, New String() {})   Next 

Value of type 'System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.Feature)' cannot be converted to 'Microsoft.VisualBasic.Collection'.


I can't really figure out why this is the case if both are of the collection type. Unless they are deriving from different collection classes. Any help would be appreciated; I am certainly interested in moving forward and setting up a demonstration page to make a case for investment into this product.


 


Thanks,


Nelson


 


 


 


highlightLayer.InternalFeatures.Clear()


 


 


 


 



GeoMap.EditLayer.InternalFeatures.Clear()


---End code.


This is where I have stopped because I am getting an error on the fCollection line. The error generated is:



 



Thank you for evaluating our products.  I hope you find our discussion forums helpful.


  To your question I believe the issue is that the two collections are not the same.  They may have the same name in “Collection” but are from very different name spaces.  The Visual Basic one is from the Microsoft.VisualBasic and the other is from System.Collections.ObjectModel.  Being a VB developer for most of my career I remember the VisualBasic collection was added to the VB.NET mainly for compatibility reasons and the expectations form VB developers such as 1 versus 0 based collections and support for Object. 


  For maximum compatibility with all .NET languages we use the collectio in the System name space.  Sorry for the inconvenience on this point but we had to use the least common denominator.  What we did do through our framework to make things easier is that whenever we want you to pass in a collection we allow you to pass in IEnumerable which will take anything that can be iterated over.  This helps because you can pass in just about anything ranging from arrays to VB Collections.


  If in your program you need to use both VB.NET collections and also the default framework collection you will need to add an import for the  System.Collections.ObjectModel.  Then you will need to specify the one you want in the class name deceleration.  This is because there is going to be a namespace conflict over the term collection.  This might be messy in your code so I have another option below.


  Another option for you is to create a shared function called something like ToVBCollection which will take something IEnumerable and pass back one of your VB.NET collections.  In this way you can always deal with the VB collection and you just need to wrap a few of your calls to our API in the function.  Please the function in a new class so that class can import the System.Collection.ObjectModel so that the only place you will have a naming conflict is there.  I wrote a sample of this, I hope you find it useful.




Imports System.Collections.ObjectModel

Public Class VBUtils

    ' Pass in anything that is enumerable and we will copy them
    ' to a VB.NET collection.  This should be fairly fast as this 
    ' only copies a reference.
    Public Shared Function ToVBCollection(ByRef enumerableCollection As IEnumerable) As Collection
        Dim newCollection As New Collection()

        For Each item As Object In enumerableCollection
            newCollection.Add(item)
        Next

        Return newCollection
    End Function

End Class



Nevermind; I figured this out after taking two seconds to actually look at the problem… 
  
 This was corrected by using the following: 
  
 Dim fCollection As System.Collections.ObjectModel.Collection(Of Feature) 
  
 I do want to raise another issue that I’ve found though regarding the TrackShapeFinished event. It seems when you only click the map while in the trackrectangle mode a small feature will generate and persist between zooms but the event never fires off. Is this intentional?? I realize I could likely acheive what I want by also going to the click event but it just seems that all track shapes regardless of drag and drop or click should fire the event off or simply no feature should generate from a click. I could have it all wrong though. 
  
 Thanks

Thanks for the previous solution, Dave. There seems to be a period of time between post approvals so I had actualyl posted the above reply after posting the original and before you had posted your solution as well. Reading the posts as they are posted would make it seem like I was ungrateful for your help!


 


I'm still interested though on an opinion as to why the TrackShapeFinished Event doesn't fire off during what could be interpretted as just the Click Event but in TrackMode. Whether this is intentional or a bug and so forth.


 


Thanks again!



Nelson, 
  
 The TrackShapeFinished event will only be raised when you Track a meaningful Shape. That is intentionally implemented by OpenLayers which is the core component of our Web Edition. I think the reason is that as click cannot track a shape, it makes sense to avoid invoking the TrackShapeFinished event. Maybe click is supposed to be a bad operation in TrackShape mode as the tracked shape will be very small if not nothing, which usually is not the really shape user wants to track.    
  
 Can you let us know your scenario why you want this? Maybe we can give you some better solutions to work it around using 3.0 
  
 Thanks, 
  
 Ben

Actually, I had interesting behavior at first. When just clicking in track mode a tiny square shape would be drawn and stayed so at that point I assumed a track shape is always generated. Some time after I replied to this post, this behavior stopped and the tiny shape would dissapear after letting go of the mouse button. At that point I went ahead with creating a click event to fire off if specifically in track mode with a variable monitoring exactly which tool I’m in so as to support the different click events similar to what I imagine has to be done in the TrackShapeFinished event anyway.  
  
 My concern was that even with just a click the trackshape generated and existed in the edit layer but didn’t trigger the event but that behavior seems to have cleared up. It was probably on my end for all I know!  
  
 Thanks guys!

One thing we can improve may be when clicking in track mode, instead of draw a tiny square, we just draw nothing. That will give user less confusion what that tiny shape is. 
  
 Writing it down on the list and we will see if we can make it. :) 
  
 Ben