Hey I've been messing around with the xamMap control for potential use in an upcoming project and I'm curious if I'm missing something about map coordinates. I was checking our the EarthQuakes example that Infragistics provided to sort of learn how the controls worked. As far as I know I have things set up correctly and created a couple "points" and attempted to add them to the map. For some reason they are not showing up. I'm not sure if its because of the coordinates I chose or what but I'm sorta confused.
<StackPanel>
<igMaps:XamMap x:Name="myMap" IsClickable="False" MapProjectionType="Lambert" >
<igMaps:XamMap.Layers>
<igMaps:MapLayer x:Name="mapLayer">
<igMaps:MapLayer.Reader>
<igMaps:ShapeFileReader Uri="/../ClientBin/Shapefiles/usa_st">
</igMaps:ShapeFileReader>
</igMaps:MapLayer.Reader>
</igMaps:MapLayer>
<igMaps:MapLayer x:Name="symbolLayer">
<igMaps:MapLayer.ValueTemplate>
<DataTemplate>
<Image Source="Resources/marker.png" Height="50" Width="50" />
</DataTemplate>
</igMaps:MapLayer.ValueTemplate>
</igMaps:XamMap.Layers>
</igMaps:XamMap>
</StackPanel>
private void AddMapElements()
{
if (_vm.Spots != null)
MapElementCollection elementCollection = new MapElementCollection();
foreach (SpotViewModel location in _vm.Spots)
Point coordinates = new Point(location.Longitude, location.Latitude);
Point origin = myMap.MapProjection.ProjectToMap(coordinates);
SymbolElement mapElement = new SymbolElement
ToolTip = location,
SymbolOrigin = origin,
SymbolType =
MapSymbolType.Diamond
};
elementCollection.Add(mapElement);
}
myMap.Layers[
"symbolLayer"].Elements = elementCollection;
this is basically all I got going on besides some constructors that call all this and some getters and setters of data.
Any help would be awesome.
Also just for clarification I have a shapefile that has its own (or default?) WorldRect (which I assume is some sort of positioning mechanism) and I am "synch-ing" the symbol layer with the shapefile layer? Sorry if there is already an explination of this, you can just refer me to it. But I found the documentation a little ambiguous but this is what it seems like it is.
EDIT: also just for more clarification I am using the USA shapefile that I found in the demo source files. I tried your suggestions to add points but I still can't seem them. Should I use different coordinates or should those coordinates that you gave me work?
EDIT2: I realized that there is a problem with the way that I am doing symbols somehow. Following the documentation on how to add symbols to maps I figured out some things. I have the code
<igMaps:XamMap x:Name="myMap"> <igMaps:XamMap.Layers> <igMaps:MapLayer x:Name="mapLayer" IsClickable="False"> <igMaps:MapLayer.Reader> <igMaps:ShapeFileReader Uri="/../ClientBin/Shapefiles/world"> </igMaps:ShapeFileReader> </igMaps:MapLayer.Reader> </igMaps:MapLayer> <igMaps:MapLayer x:Name="symbolLayer" IsClickable="False" Imported="symbolLayer_Imported"> <igMaps:MapLayer.ValueTemplate> <DataTemplate> <Image Source="Resources/marker.png" Height="50" Width="50" /> </DataTemplate> </igMaps:MapLayer.ValueTemplate> </igMaps:MapLayer> </igMaps:XamMap.Layers> </igMaps:XamMap>
The problem has to do with when I try and make the symbolsLayer its own layer. If I embed the ValueTemplate in the mapLayer layer then then they show up fine, but trying to interact with a different layer the symbols don't show up. Does this have something to do with overlapping?
private void symbolLayer_Imported(object sender, MapLayerImportEventArgs e) { if (e.Action == MapLayerImportAction.End) { MapLayer layer = myMap.Layers["symbolLayer"]; layer.WorldRect = myMap.Layers[0].WorldRect; MapElementCollection ele = new MapElementCollection(); double latitude = 0; double longitude = 0; Point origin = myMap.MapProjection.ProjectToMap(new Point(longitude, latitude)); SymbolElement element = new SymbolElement() { SymbolOrigin = origin, Caption = "Marker" }; ele.Add(element); layer.Elements = ele; } }
I just made this simple like the documentation, but as I said before when I do it on the mapLayer it works fine (although it adds the symbol to all the countries, which I assume has to do with the shapefile) but when I make a separate symbols layer it doesn't work
Ah thank you very much. Sorry about my code this is the first time I've posted on this forum :)
Hi MattMacd,
The WorldRect property of the symbolLayer needs to be set prior to adding the SymbolElements to it. A sample approach is the following: private void AddMapElements() { IList<SpotDataModel> data = GetEarthQuakeData(); if (data != null) { MapLayer layer = myMap.Layers["symbolLayer"];
layer.WorldRect = myMap.Layers[0].WorldRect;
foreach (SpotDataModel location in data) { Point coordinates = new Point(location.Longitude, location.Latitude);
SymbolElement mapElement = new SymbolElement { ToolTip = location, SymbolOrigin = origin, SymbolType = MapSymbolType.Diamond, };
elementCollection.Add(mapElement); } layer.Elements = elementCollection; } }The other thing is that the (0,0) point is geographically located somewhere near Africa's west coast, so it cannot be visualized in this case. Also the latitude should be a value between -90 and 90 degrees.Sample coordinates of points which could be visualized are (40.713956,-73.959961), (39.095963,-75.498047) which both belong to locations somewhere on the USA's east coast.
Best regards,Milana Zhileva