syncfusion/wpf-ui-components-skills / skills/syncfusion-wpf-map
syncfusion-wpf-map
VerifiedImplement Syncfusion WPF Maps (SfMap) control for geographical data visualization in Windows Presentation Foundation applications. Use this when displaying geographical data, rendering shape files, or integrating map layers with markers and bubbles. This skill covers ShapeFileLayer, ImageryLayer, map customization, legends, OpenStreetMap/Bing Maps integration, and interactive map features.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 14.5 KB |
| references/annotations.md | markdown | 13.6 KB |
| references/bubbles.md | markdown | 16.2 KB |
| references/data-binding.md | markdown | 11.8 KB |
| references/events.md | markdown | 9.4 KB |
| references/getting-started.md | markdown | 7.1 KB |
| references/layers.md | markdown | 9.9 KB |
| references/legends.md | markdown | 15.0 KB |
| references/map-labels.md | markdown | 11.4 KB |
| references/map-providers.md | markdown | 14.2 KB |
| references/markers.md | markdown | 14.4 KB |
| references/multilayer-support.md | markdown | 10.1 KB |
| references/shapes-color-customization.md | markdown | 17.7 KB |
| references/user-interaction.md | markdown | 11.4 KB |
references/events.md
View on GitHub# Events in WPF Maps (SfMap)
The Maps control provides various events that enable you to respond to user interactions and state changes. These events allow you to implement custom behaviors when users interact with map elements.
## Available Events
### Selection Events
**ShapeSelected**
- **Trigger:** When a shape is clicked by the user
- **Arguments:** `ShapeSelectedEventArgs`
- **Use case:** Handle shape selection, show details, navigate
**MarkerSelected**
- **Trigger:** When a marker is clicked
- **Arguments:** `MarkerSelectedEventArgs`
- **Use case:** Display marker information, navigation
### Zoom Events
**ZoomedOut**
- **Trigger:** When map zoomed out
- **Arguments:** `ZoomEventArgs`
- **Use case:** Update UI based on zoom, load detail data
**ZoomedIn**
- **Trigger:** When map zoomed in.
- **Arguments:** `ZoomEventArgs`
- **Use case:** Update UI based on zoom, load detail data
## Shape Selection Events
### ShapeSelected Event
```xml
<syncfusion:SfMap>
<syncfusion:SfMap.Layers>
<syncfusion:ShapeFileLayer Uri="MyApp.ShapeFiles.world1.shp"
EnableSelection="True"
ShapesSelected="ShapeFileLayer_ShapeSelected">
</syncfusion:ShapeFileLayer>
</syncfusion:SfMap.Layers>
</syncfusion:SfMap>
```
```csharp
private void ShapeFileLayer_ShapeSelected(object sender, SelectionEventArgs e)
{
// Get the data object for the selected shape
var data = e.Items;
// Get the shape object
var shape = e.Shape;
// Example: Show shape information
if (data != null)
{
MessageBox.Show($"Selected: {data}");
}
}
```
## Marker Events
### MarkerSelected Event
```csharp
public class Marker
{
public string Label { get; set; }
public string Longitude { get; set; }
public string Latitude { get; set; }
}
public class ViewModel
{
public ObservableCollection<Marker> MarkerCollection { get; set; }
public ViewModel()
{
this.MarkerCollection = new ObservableCollection<Marker>
{
new Marker() { Label = "California", Latitude = "37", Longitude = "-120" },
new Marker() { Label = "USA", Latitude = "38.8833N", Longitude = "77.0167W" },
new Marker() { Label = "Brazil", Latitude = "15.7833S", Longitude = "47.8667W" },
new Marker() { Label = "India", Latitude = "21.0000N", Longitude = "78.0000E" },
new Marker() { Label = "China", Latitude = "35.0000N", Longitude = "103.0000E" },
new Marker() { Label = "Indonesia", Latitude = "6.1750S", Longitude = "106.8283E" },
new Marker() { Label = "Africa", Latitude = "-8.7832S", Longitude = "34.5085E" },
};
}
}
```
```xml
<syncfusion:ShapeFileLayer Uri="MyApp.ShapeFiles.world1.shp"
Markers="{Binding MarkerCollection}"
MarkerSelected="ShapeFileLayer_MarkerSelected">
</syncfusion:ShapeFileLayer>
```
```csharp
private void ShapeFileLayer_MarkerSelected(object sender, MarkerSelectedEventArgs e)
{
// Get the selected marker
var marker = e.SelectedMarker;
if (marker != null)
{
// Display marker information in intenally definied TextBlocks
MarkerLabel.Text = marker.Label;
MarkerCoordinates.Text = $"{marker.Latitude}, {marker.Longitude}";
}
}
```
## Complete Examples
### Example 1: Selection with Detail Panel
```xml
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<syncfusion:SfMap Grid.Column="0">
<syncfusion:SfMap.Layers>
<syncfusion:ShapeFileLayer Uri="MyApp.ShapeFiles.usa_state.shp"
ItemsSource="{Binding States}"
ShapeIDPath="Name"
ShapeIDTableField="STATE_NAME"
ShapeSelected="ShapeFileLayer_ShapeSelected">
<syncfusion:ShapeFileLayer.ShapeSettings>
<syncfusion:ShapeSetting ShapeValuePath="Population"
EnableSelection="True"
SelectedShapeColor="Orange" />
</syncfusion:ShapeFileLayer.ShapeSettings>
</syncfusion:ShapeFileLayer>
</syncfusion:SfMap.Layers>
</syncfusion:SfMap>
<Border Grid.Column="1" Background="#F5F5F5" Padding="20">
<StackPanel x:Name="DetailPanel" Visibility="Collapsed">
<TextBlock Text="State Information" FontSize="18" FontWeight="Bold" Margin="0,0,0,10" />
<TextBlock x:Name="StateName" FontSize="16" Margin="0,0,0,5" />
<TextBlock x:Name="StatePopulation" Margin="0,0,0,5" />
<TextBlock x:Name="StateArea" />
</StackPanel>
</Border>
</Grid>
```
```csharp
public partial class MapWindow : Window
{
public MapWindow()
{
InitializeComponent();
}
private void ShapeFileLayer_ShapeSelected(object sender, SelectionEventArgs e)
{
if (e.Items is StateData state)
{
DetailPanel.Visibility = Visibility.Visible;
StateName.Text = state.Name;
StatePopulation.Text = $"Population: {state.Population:N0}";
StateArea.Text = $"Area: {state.Area:N0} sq mi";
}
}
}
public class StateData : INotifyPropertyChanged
{
public string Name { get; set; }
public int Population { get; set; }
public double Area { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
```
### Example 2: Zoom-Based Detail Loading
```xml
<syncfusion:SfMap ZoomedIn="map_ZoomedIn"
ZoomedOut="map_ZoomedOut"
EnableZoom="True"
MinZoom="1"
MaxZoom="10">
<syncfusion:SfMap.Layers>
<syncfusion:ShapeFileLayer x:Name="MainLayer"
Uri="MyApp.ShapeFiles.world1.shp"
ItemsSource="{Binding Countries}" />
</syncfusion:SfMap.Layers>
</syncfusion:SfMap>
```
```csharp
public partial class ZoomMapWindow : Window
{
private const double DetailZoomThreshold = 4.0;
private bool detailsLoaded = false;
public ZoomMapWindow()
{
InitializeComponent();
}
private void map_ZoomedIn(object sender, ZoomEventArgs e)
{
double zoomLevel = e.NewZoomLevel;
// Load detailed markers when zooming in
if (zoomLevel >= DetailZoomThreshold && !detailsLoaded)
{
LoadDetailedMarkers();
detailsLoaded = true;
}
// Remove detailed markers when zooming out
else if (zoomLevel < DetailZoomThreshold && detailsLoaded)
{
ClearDetailedMarkers();
detailsLoaded = false;
}
}
private void map_ZoomedOut(object sender, ZoomEventArgs e)
{
double zoomLevel = e.NewZoomLevel;
// Load detailed markers when zooming in
if (zoomLevel >= DetailZoomThreshold && !detailsLoaded)
{
LoadDetailedMarkers();
detailsLoaded = true;
}
// Remove detailed markers when zooming out
else if (zoomLevel < DetailZoomThreshold && detailsLoaded)
{
ClearDetailedMarkers();
detailsLoaded = false;
}
}
private void LoadDetailedMarkers()
{
MainLayer.Markers.Clear();
// Add detailed city markers
foreach (var city in GetCityData())
{
MainLayer.Markers.Add(new MapMarker
{
Label = city.Name,
Latitude = city.Latitude,
Longitude = city.Longitude
});
}
}
private void ClearDetailedMarkers()
{
MainLayer.Markers.Clear();
}
private List<CityData> GetCityData()
{
return new List<CityData>
{
new CityData { Name = "New York", Latitude = "40.7128N", Longitude = "74.0060W" },
new CityData { Name = "London", Latitude = "51.5074N", Longitude = "0.1278W" },
new CityData { Name = "Tokyo", Latitude = "35.6762N", Longitude = "139.6503E" }
};
}
}
```
## Best Practices
1. **Check data type** - Cast `e.Items` to expected type before accessing properties
2. **Null checks** - Always verify event arguments are not null
3. **UI thread** - Update UI elements on dispatcher thread if needed
4. **Unsubscribe** - Remove event handlers when disposing controls
5. **Performance** - Avoid heavy operations in frequently-fired events (ZoomLevelChanged)
6. **State management** - Track selection state to avoid redundant updates
7. **Event coordination** - Use multiple events together for rich interactions
## Troubleshooting
### Event not firing
**Check:**
- Event handler is properly subscribed in XAML or code
- EnableSelection is true for selection events
- EnableZoom is true for zoom events
- Layer is visible and has data
### Cannot access data in event handler
**Verify:**
- ItemsSource is bound to data collection
- ShapeIDPath and ShapeIDTableField are correctly set
- Data object type matches expected type in cast
### UI not updating in event handler
**Fix:**
- Ensure UI updates are on dispatcher thread
- Check binding modes and property notifications
- Verify element visibility and parent container layout
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |