ThinkGeo.com    |     Documentation    |     Premium Support

How to dynamicly generate new layer?

Hello, all


I'd like to add some points to Map every 5 seconds.


But I can't predefine how much points I have to draw.  Maybe it will decrease/increase one or two point after 5 sec.


could you give some idea about follow code?


 Private Sub ShowImage(ByVal lonX() As Double, ByVal latY() As Double)

        For i As Integer = 0 To lonX.Length - 1

            Dim imgLayer As New InMemoryFeatureLayer()

            imgLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap

            imgLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = New GeoImage("....gif")

            imgLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

            imgLayer.InternalFeatures.Add("Car", New Feature(New PointShape(lonX(i), latY(i))))

            Dim PointLayer As New InMemoryFeatureLayer()

            PointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20


            Dim imgQueryResultsOverlay As New LayerOverlay()

            imgQueryResultsOverlay.Layers.Add("imgLayer", imgLayer)

            imgQueryResultsOverlay.Layers.Add("PointLayer", PointLayer)

            If WinformsMap1.Overlays.Contains("imgQueryResultsOverlay") Then

                WinformsMap1.Overlays.Remove("imgQueryResultsOverlay")

            End If

            WinformsMap1.Overlays.Add("imgQueryResultsOverlay", imgQueryResultsOverlay)

        Next

       

    End Sub


 



Carol, 
  
 I don’t know what’s your problem. Can you explain it to me? 
 After review your code, I think you don’t need add point to different layer, you can add all points to one layer. 
  
 Please let me know if you have more questions. 
 Thanks 
 James

Sorry, I describe unclearly… 
 Yes, I’d like to generate all points. 
 Fist time, I generate all points in one layer. 
 Second time, I input new array to this method, I have to redraw all points. 
 but my code which just show one image of point…so how to midify it?

Carol,


Your problem is that everytime when for each point you will add a new overlay and layer, so you can just show the last one.


My suggestion is that you can define layer and overlay outside, all points add the same layer and same overlay.


        Dim imgLayer As New InMemoryFeatureLayer()
        Dim imgQueryResultsOverlay As New LayerOverlay()

        Private Sub ShowImage(ByVal lonX() As Double, ByVal latY() As Double)
            For i As Integer = 0 To lonX.Length - 1
                imgLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Bitmap
                imgLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = New GeoImage("....gif")
                imgLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
                imgLayer.InternalFeatures.Add("Car", New Feature(New PointShape(lonX(i), latY(i))))

                If Not imgQueryResultsOverlay.Layers.Contains("imgLayer") Then
                    imgQueryResultsOverlay.Layers.Add("imgLayer", imgLayer)
                End If
                If Not WinformsMap1.Overlays.Contains("imgQueryResultsOverlay") Then
                    WinformsMap1.Overlays.Add("imgQueryResultsOverlay", imgQueryResultsOverlay)
                End If
            Next
        End Sub

James



thanks for your reply, James 
 but the follow code has a error message: you have the same index item 
  
 imgLayer.InternalFeatures.Add("Car", New Feature(New PointShape(lonX(i), latY(i)))) 


Carol, 
  
 You can use anther overload method. 
 imgLayer.InternalFeatures.Add(New Feature(New PointShape(lonX(i), latY(i))))  


Thanks for your help!! James. 
 it runs very good! :)

It’s awesome! Any more questions just let me know.

Hello, James 
 I have a problem. 
 I load 400 coordinates and draw 400 points fo image in the map. 
 it use Memory about 4xxMB… 
  
 could you give some idea?

Carol,


I have updated the DrawAPointUsingABitmap sample in HowDoI samples, but it just uses Memory about 33-35MB.


The attachement is my sample code.


James



1526-DrawAPointUsingABitmap.zip (1.52 KB)

Thanks for your help, James

Sorry, it's my wrong in my code. your code is correct!


if i input long./lat. and image_name, i want to draw a image in long./lat. and show image name.could you give me some idea?


(Public Sub ShowImage(ByVal lonX() As String, ByVal latY() As String, ByVal LT_Name() As String))


i want to show like below picture:




My code as follows: 
 Could you give me some idea? Thanks. 
    
 Public Sub ShowImage(ByVal lonX() As String, ByVal latY() As String, ByVal LT_Name() As String) 
  
        Dim columnValues As New Dictionary(Of String, String) 
  
         For j As Integer = 0 To lonX.Length - 1 
             columnValues.Add(j, LT_Name(j)) 
         Next 
  
         For i As Integer = 0 To lonX.Length - 1 
             imgLayer.ZoomLevelSet.ZoomLevel08.DefaultPointStyle.PointType = PointType.Bitmap 
             imgLayer.ZoomLevelSet.ZoomLevel08.DefaultPointStyle.Image =  New GeoImage("…\United States.png")             
             imgLayer.ZoomLevelSet.ZoomLevel08.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 
             imgLayer.InternalFeatures.Add(New Feature(New PointShape(lonX(i), latY(i)), columnValues(i))) 
  
             If Not imgQueryResultsOverlay.Layers.Contains("imgLayer") Then 
                 imgQueryResultsOverlay.Layers.Add("imgLayer", imgLayer) 
             End If 
             If Not WinformsMap1.Overlays.Contains("imgQueryResultsOverlay") Then 
                 WinformsMap1.Overlays.Add("imgQueryResultsOverlay", imgQueryResultsOverlay) 
             End If 
         Next 
 End Sub

I find a reference gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/5335/afv/topic/Default.aspx 
  
 I solve my problem. :)  
 Thanks! 


Carol,


This is my optimized code:


        Public Sub ShowImage(ByVal lonX() As String, ByVal latY() As String, ByVal LT_Name() As String)

            Dim columnValues As New Dictionary(Of String, String)

            For j As Integer = 0 To lonX.Length - 1
                columnValues.Add(j, LT_Name(j))
            Next

            For i As Integer = 0 To lonX.Length - 1
                imgLayer.ZoomLevelSet.ZoomLevel08.DefaultPointStyle.PointType = PointType.Bitmap
                imgLayer.ZoomLevelSet.ZoomLevel08.DefaultPointStyle.Image = New GeoImage("...\United States.png")
                imgLayer.ZoomLevelSet.ZoomLevel08.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
                Dim feature As New Feature(New PointShape(lonX(i), latY(i)))
                feature.ColumnValues.Add("name", columnValues(i))
                imgLayer.InternalFeatures.Add(feature)

                imgLayer.ZoomLevelSet.ZoomLevel08.DefaultTextStyle = TextStyles.Highway1("name")
                imgLayer.Open()
                If imgLayer.Columns.Count = 0 Then
                    imgLayer.Columns.Add(New FeatureSourceColumn("name"))
                End If
                imgLayer.Close()
                If Not imgQueryResultsOverlay.Layers.Contains("imgLayer") Then
                    imgQueryResultsOverlay.Layers.Add("imgLayer", imgLayer)
                End If
                If Not winformsMap1.Overlays.Contains("imgQueryResultsOverlay") Then
                    winformsMap1.Overlays.Add("imgQueryResultsOverlay", imgQueryResultsOverlay)
                End If
            Next
        End Sub

James


 



Thanks for your reply, James. 
  
 Sorry, I have another question. 
 I’d like to make sure one layer just shows one image? 
 If I want to show different image picture by different status. 
 Dose it have to divided many layers? 
  


Carol, 
  
 Thanks for your post and sorry for the delay for some problem in the discussion forum in the past few days. 
  
 The images on the layer are in fact labels of the Point features in the layer, so if you want show only one image on one layer. Probably one easy way is to create one layer for one feature as you did before. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Sorry, I come back again 
 I have a problem. 
  
 I have many image which means different direction. 
 if I’d like to show trace route of the car. each coordinates may be has different direction, so i have to show different image. 
  
 it have to retain trace route of the car (the car ever pass through), and insert a new image to show the car go to which direction currently. 
  
 do I have to create more layer?? 
 could you give me some idea? 
  
 Thanks! 
  


Carol,


Hope the following sample can give you some ideas. Of course, there are a couple of other ways to achieve this; I am not fully testing them:).
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

1550-Post6722Sample.zip (38.9 KB)

Thanks for your reply, Yale 
 do you have a sample in vb.net
  
 and why you use mapEngine but not WinformsMap? (sorry, i am confused in mapEngine. i have not used mapEngine) 
 What are they difference? 
 in method of DrawImage(), it shows Map is undeclare…can i modify it to WinformsMap? but it shows image isn’t the member of ThinGeo.MapSuite.DesktopEdition.WinformsMap. 
  
        private void DrawImage() 
         { 
             if (bitmap != null) { bitmap.Dispose(); } 
             bitmap = new Bitmap(Map.Width, Map.Height); 
             mapEngine.OpenAllLayers(); 
             mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.DecimalDegree); 
             mapEngine.CloseAllLayers(); 
             Map.Image = bitmap; 
         }

Carol,


Thanks for your post and questions.
 
Attachment is the VB.net version of sample using Desktop Edition instead of Service edition.
 
The original sample is a service sample by using the Map Engine to draw directly, sorry for making the confusion. The change from service edition to Desktop Edition is you can ignore MapEngine, just add the layer to Winforms control, it will handle the draw stuff by itself.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

1553-RotatedImageStyle(VB).zip (22.7 KB)