Hi,
I’ve found that if I create a PopupOverlay in my MapClick event, then the popup is not shown until I pan the map. The code is shown below:
const string PopupOverlayName = “PopupOverlay”;
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
this.map1.MapClick += MapClick;
map1.MapUnit = GeographyUnit.Meter;
var layerOverlay = new LayerOverlay();
this.map1.Overlays.Add(layerOverlay);
var googleLayer = new GoogleMapsLayer();
layerOverlay.Layers.Add(googleLayer);
// UNCOMMENT THESE LINES AND THEN IT ALL WORKS
//var popupOverlay = new PopupOverlay { Name = PopupOverlayName };
//this.map1.Overlays.Add(popupOverlay);
}
private void MapClick(object sender, MapClickWpfMapEventArgs e)
{
var popupOverlay = (PopupOverlay)this.map1.Overlays.FirstOrDefault(i => i.Name == PopupOverlayName);
if (popupOverlay == null)
{
popupOverlay = new PopupOverlay { Name = PopupOverlayName };
this.map1.Overlays.Add(popupOverlay);
}
var popup = new Popup(e.WorldLocation) { Content = “nothing” };
popupOverlay.Popups.Clear();
popupOverlay.Popups.Add(popup);
popupOverlay.Refresh();
}
To reproduce, start the app, click anywhere on the map, and notice the popup does not show. Drag the map around, and then the popup appears. If I uncomment the lines noted above, then the popup does show without having to drag the map around.
Whilst, I can work around this for now, it would be nice if this was fixed in a future build…
Thanks,
Steve
Popups dont show when PopupOverlay is created in MapClick event
Hi Steve,
Thanks for your post, would you please replace
popupOverlay.Refresh();
With
Map1.Refresh(popupOverlay);
Now, it should work.
Hope it helps
Summer