hello, i'm a cameroonian student, I do my training at Orange Cameroon, my job is to create a map incorporating all subscribers. I try map suite and I get errors in my code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WinformsMap1.MapUnit = GeographyUnit.DecimalDegree
'' Set a proper extent for the Map.
WinformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.GeographicColors.Sand)
Dim worldMapKitDesktopOverlay As New WorldMapKitWmsDesktopOverlay()
WinformsMap1.Overlays.Add(worldMapKitDesktopOverlay)
Dim worldlayer As New ShapeFileFeatureLayer("..\..\Data_admin_SHP\cameroun\CAM.shp")
'// Set the worldLayer (carte du cameroun)with a preset Style, as AreaStyles.Country1 has YellowGreen background and black border, our worldLayer will have the same render style.
worldlayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Orange, GeoColor.FromArgb(100, GeoColor.SimpleColors.Black))
'// This setting will apply from ZoonLevel01 to ZoomLevel20, that means we can see the world the same style with ZoomLevel01 all the time no matter how far we zoom out/in.
worldlayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
worldlayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City4("ADM2")
Dim LayerOverlay As New LayerOverlay()
'// Add the shapefile layer to the layer overlay
LayerOverlay.Layers.Add("wordlayer", worldlayer)
'// We need to add the layer overlay to Map.
WinformsMap1.Overlays.Add(LayerOverlay)
worldlayer.Open()
AddHandler WinformsMap1.MapClick, AddressOf WinformsMap1_MapClick
WinformsMap1.CurrentExtent = New RectangleShape(-139.2, 92.4, 120.9, -93.2)
''We now need to call the Refresh() method of the Map control so that the Map can redraw based on the data that has been provided.
WinformsMap1.Refresh()
Private Sub WinformsMap1_MapClick(ByVal sender As Object, ByVal e As MapClickWinformsMapEventArgs)
MsgBox("on commence")
Dim worldLayer As FeatureLayer = WinformsMap1.FindFeatureLayer("worldlayer")
Dim selectedFeatures As Collection(Of Feature) = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, New String(0) {"ADM2"})
If selectedFeatures Is Nothing Then
MessageBox.Show("aucune couche trouvée")
End If
worldLayer.Close()
If selectedFeatures.Count > 0 Then
Dim text As String = "The country you selected is: " & selectedFeatures(0).ColumnValues("ADM2").Trim()
MessageBox.Show(text, "Note", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, CType(0, MessageBoxOptions))
System.Diagnostics.Debug.WriteLine(text)
End If
MessageBox.Show("terminer")
End Sub
this is the error "l'exception nullreference n'a pas été gérée" i don't know why it is happening
Worldlayer.open() Exception NullReference
Hello Emmanuella,
Welcome to use map suite, sorry your exception message is French, so I guess the exception is “System.NullReferenceException was unhandled”? if not, could you please paste the English exception?
If so, this is an internal exception, it will caused by many reason, it’s hard to see which part was the root cause, is that possible you can provide a sample to us to recreate this problem?
Regards,
Gary
hello,
sorry for the french exception, in english it is “Systemm.nullReferenceException” as you said, the reason is that i’m using the french version of visual studio 2010. i’ve tried to put a breakpoint on the code “worldLayer.Open()” to see what happened
Dim worldLayer As FeatureLayer = WinformsMap1.FindFeatureLayer(“worldlayer”)
worldLayer.Open()
Dim selectedFeatures As Collection(Of Feature) = New Collection(Of Feature)
when the debuging starts, i see “worldLayer= nothing” how can i resolve this problem?
another question is to know if it is possible to click in some parts of the map to redirect it to images.
Regards,
Emma
i don’t know is the problem is that the application cannot access in my CAM.idx (of my shapefile) or i have created the index with Mapsuite Explorer as it is recommended to use a shapefile and display it.
sorry for the error,
when the debugging starts, the breakpoint on worldLayer.Open() , the error is [I] selectFeatures=nothing[/I] why? is it something wrong in my code?
Hello Emmanuella,
Thanks for the further information, sorry I can’t run your code, so I just read it, and I found something wrong here:
Dim worldLayer As FeatureLayer = WinformsMap1.FindFeatureLayer(“worldlayer”)
When you raise your map click event, you want to get the exist layer, but when you create your layer:
Dim worldlayer As New ShapeFileFeatureLayer("…\Data_admin_SHP\cameroun\CAM.shp")
You didn’t set a name to it, so you can’t use method FindFeatureLayer to find a layer without name.
Please try to add worldlayer.Name=“worldlayer” just after you create the layer and have another try.
Regards,
Gary
tank you so much
i have set a name on my shapefile and everything is now fine. but i still have some questions you didn’t answer me.
Is it possible or not to assign an image on point of a shapefile and display after a click, like a picturebox which can be visible after one winformsMap_click?
Dim poplayer = New ShapeFileFeatureLayer("…\Data_admin_SHP\POP\points6.shp")
poplayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1
poplayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
poplayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.County2(“NAME”)
poplayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City2
thanks
Hello Emmanuella,
I’m glad it’s working for you, and for your second question, yes, you can hook the winformsMap_click event, then when the event raise, get your shape file layer, set the point style to it, and that point style including the image you want, then refresh the overlay which contain the shape file feature layer.
Regards,
Gary
Morning Gary,
i’m happy to know that it is possible. But how can i do it?have you a sample with which i can reference? Because i don’t how and where start it. I want also to notify that it is the heart of my work.
Thanks
what are the tools that i have to use to implement it. I want all details about it to work fine and quick on my project.
regards
Hi Emmanuella,
You might take a look at the Desktop Edition Samples - Styles - DrawAPointUsingABitmap sample application. This sample uses a bitmap for each point.
You might also take a look at our Markers section of the sample applications that can provide you some additional functionality upon your click event.
i don’t really know how to start it. I’m just a beginner in programming. i’ve taken a look at the desktop edition samples but i’m not able to add click event
on a point of shapefile and display the bitmap corresponding.
Dim worldLayer As FeatureLayer = WinformsMap1.FindFeatureLayer(“PopLayer”)
worldLayer.Open()
Dim selectedFeatures As Collection(Of Feature) = worldLayer.QueryTools.GetFeaturesByColumnValue(“NAME”, “POP GAROUA”)
worldLayer.Close()
If selectedFeatures.Count > 0 Then
Dim text As String = "THIS IS what you have selected: " & selectedFeatures(0).ColumnValues(“NAME”).Trim()
MessageBox.Show(text, “Note”, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, CType(0, MessageBoxOptions))
System.Diagnostics.Debug.WriteLine(text)
Else
MessageBox.Show(“not found”)
End If
it displays the same name on every point i don’t know why.i don’t know what is the right expression, if i write the code the wrong way.
how put to image in tooltip In addition to text when the mouse move to point in the map?
Hello Emmanuella,
You can hook the maker.MouseHover event, and in that, add the text control to the marker like:
TextBox content = new TextBox();
content.Text = (index++).ToString();
content.FontSize = 14;
content.FontWeight = FontWeights.Bold;
content.Foreground = new SolidColorBrush(Colors.White);
content.Margin = new Thickness(0, -10, 0, 0);
marker.Content = content;
Let us know your queries.
Regards,
Gary