I have a shapefile at the county level and need to add 50+ shapefiles at the precinct level, but only if the county is clicked on. This is the function I have:
Private Sub xamWebMap_ElementClick(ByVal sender As Object, ByVal e As MapElementClickEventArgs) Dim map1 As XamWebMap = DirectCast(sender, XamWebMap) Dim i As Integer i += 1 For Each ele As MapElement In map1.Layers(0).Elements Dim builder As New StringBuilder() ele.Name = builder.Append("precinct" + i.ToString()).ToString i = i + 1 Next Dim elementName As String = e.Element.Name map1.WindowFit(e.Element) Dim newLayer As New MapLayer() newLayer.LayerName = elementName newLayer.VisibleFromScale = 3 map1.Layers.Add(newLayer) Dim reader As New ShapeFileReader() Dim converter As New DataMapping.Converter() reader.Uri = "Shapefiles/" + elementName reader.DataMapping = TryCast(converter.ConvertFromString("Caption=NAME"), DataMapping) newLayer.Reader = reader Dim layer As MapLayer = DirectCast(map1.Layers.FindName(elementName).ElementAt(0), MapLayer) Dim elements As IEnumerable(Of MapElement) = TryCast(layer.Elements.FindElement("Caption", "Name"), IEnumerable(Of MapElement)) For Each element As MapElement In layer.Elements pop.IsOpen = False element.IsClickable = False Next If elements.Count() > 0 Then pop.IsOpen = True Dim element As MapElement = TryCast(elements.ElementAt(0), MapElement) element.Caption = Nothing End If End Sub
I am naming all of the shapefiles precinct1, precinct2 and so on. Can anyone help?
Thanks
Those calls to GetDataAsync are asynchronous, as the method name implies, so using the layerCnt field as you are trying will not work as it will get incremented to 3 before the first response even comes. You will have to use another method to identify the data returned from the data service.
-Graham
Hi
now its working when i add one layer dynamically but when i add multiple layers the layer added last only showing up. I noticed that the GetDataCompleted event is firing only when all the layers added not when every layer added. what is the problem. I think my approach is wrong.Can you help me. I am using Geo Spatial data to create shapes. Here with i have attached the code for the setup i have tried and the service i have created.
fra97, you may also want to experiment with calling windowfit if the new layer you are trying to show is scaled or positioned differently from the layer your were previously showing. But if the layer is the same scale and position and is just more detail that the other layer, you probably wont have to adjust the window.
Oniv, if you are adding the layer programmatically like that, call WindowFit on the map control when the layer is done importing. This will adjust the map window to encompass the new content.
I need to show a map from Italy with the regions. For each Italian region should appear a cake diagram which reports the data.
By clicking on a given region I would like to show a detailed map where the municipalities are evidenced.
Therefore, each municipality has a cake diagram as well.
Every map with the municipality of a given region has to be a “shapefile” and it would be nice to show it in a different layer. Is it possible?
How can I load a new layer and hide the previous one by a click? This is my code, When I click on map I can't see "LayerZoom" layer (my map is empty).
<igMap:XamWebMap x:Name="map1" ElementClick="map1_ElementClick">
<igMap:XamWebMap.Layers >
<igMap:MapLayer x:Name="LayerItalia" DataMapping="Name=CountryName; Value=BirthRate" ToolTip="Valore XML: {Value}">
<igMap:MapLayer.Reader>
<igMap:ShapeFileReader Uri="Shapefiles/ITA_adm1" DataMapping="Name, Caption=NAME_1" >
<igMap:ShapeFileReader.CoordinateSystem>
<igMap:CoordinateSystem>
<igMap:CoordinateSystem.Projection>
<igMap:SphericalMercator/>
</igMap:CoordinateSystem.Projection>
</igMap:CoordinateSystem>
</igMap:ShapeFileReader.CoordinateSystem>
</igMap:ShapeFileReader>
</igMap:MapLayer.Reader>
</igMap:MapLayer>
</igMap:XamWebMap.Layers>
private void map1_ElementClick (object sender, Infragistics.Silverlight.Map.MapElementClickEventArgs e)
{
MapLayer statesLayer = new MapLayer();
statesLayer.LayerName = "LayerZoom";
ShapeFileReader reader = new ShapeFileReader();
reader.Uri = "Shapefiles/ITA_adm0";
DataMapping.Converter converter = new DataMapping.Converter();
reader.DataMapping = converter.ConvertFromString("Caption=CNTRY_NAME") as DataMapping;
statesLayer.Reader = reader;
map1.Layers.Add(statesLayer);
statesLayer.ImportAsync();
MapLayerCollection mapCollection = map1.Layers;
foreach (MapLayer map in mapCollection)
if (map.LayerName.Equals("LayerItalia"))
map.IsVisible = false;
else
map.IsVisible = true;
}
Can I present the data in a cake diagram?