Hello,
I looked at the HowTo-samples “Auto Refresh Overlay” and “Marker with Context Menu”.
Both samples deal with markers and utilize overlays to defined them. In the auto-refresh sample, how can I define individual webimages for the markers in the same layer? It seems to me that there’s only one Default Image for all the markers in the layer. Or do I Need to defined a separate overlay for each individual marker to resolve this?
In the Context Menu sample, there’s only a single marker in the overlay and the context menu seems to be defined to Show up for any of the markers in the same overlay. What if I have more than one marker in the overlay and I want individual menu items for each of them?
Thanks
Karsten
PS: Another requirement that I have is popup boxes for markers with individual Content…
Treating Markers individually?
Hi Karsten,
Thanks for you post.
SimpleMarkerOverlay is what you need, below code shows you how to add individual webimages, context meun and Popup for marker on the sample Overlay. Please have a try:
//Create a SimpleMarkerOverlay and add it to map.SimpleMarkerOverlay simpleMarkerOverlay =newSimpleMarkerOverlay();map.CustomOverlays.Add(simpleMarkerOverlay);//Define marker1Marker marker1 =newMarker(0, 0,newWebImage("imagepath1"));//Create contentxtmunu for marker 1.marker1.ContextMenu =newContextMenu("popup1", 200);//Add a menu item for context menu 1.marker1.ContextMenu.MenuItems.Add(newContextMenuItem("<b>Item for menu1</b>"));//Add an individual popup for Marker1.marker1.Popup =newCustomPopup("popup1",newPointShape(0, 0),"<a>google.com</a>", 150, 40);marker1.Popup.IsVisible =false;//Add the marker to markeroverlay.simpleMarkerOverlay.Markers.Add(marker1);
//Define marker2 and add to marker overlay.Marker marker2 =newMarker(10, 10,newWebImage("imagepath1"));marker2.ContextMenu =newContextMenu("popup2", 200);marker2.ContextMenu.MenuItems.Add(newContextMenuItem("<b>Item for menu2</b>"));
//Add the marker to markeroverlay.simpleMarkerOverlay.Markers.Add(marker2);
Hope this would be helpful and any other question please feel free to let us know.
Regards and thanks,
Kevin
Hi Kevin!
Thanks for your answer. I will try this.
However Don just wrote in a different thread that the InMemoryMarkerOverlay will perform better with many markers (and I will have many). Is it possible to utilize InMemoryMarkerOverlay in a similar way?
Karsten
Hi Karsten,
Just as what Don said, the
InMemoryMarkerOverlay has better performance than SimpleMarkerOverlay, because
we use FeatureSource to query markers from InMemoryMarkerOverlay, there are
many spatial query enhancement in FeatureSource.
We also can set individual
marker style for InMemoryMarkerOverlay with ValueMarkerStyle and
ClassBreakStyle, it’s a little complex than SimpleMarkerOverlay, Please try the
below code:
//Create a value marker style, and specifiy the value column name is "Value".ValueMarkerStyle valueMarkerStyle =newValueMarkerStyle("ValueColumn");
//Add a MakerValueItem, when the "Value"PointMarkerStyle markerStyle1 =newPointMarkerStyle(newWebImage("imagePath1"));//Add a context menu for makerStyle1;markerStyle1.ContextMenu =newContextMenu("menu1", 200);markerStyle1.ContextMenu.MenuItems.Add(newContextMenuItem("<b>Item1</b>"));
//When the value of "ValueColumn" is "Value1", the marker will be markerStyle1valueMarkerStyle.ValueItems.Add(newMarkerValueItem("Value1", markerStyle1));
PointMarkerStyle markerStyle2 =newPointMarkerStyle(newWebImage("imagePath2"));//Add Popup for maerkerStyle2markerStyle2.Popup =newCustomPopup("popup2",newPointShape(0, 0),"Popup 2");markerStyle2.Popup.IsVisible =false;
//When the value of "ValueColumn" is "Value2", the marker will be markerStyle2valueMarkerStyle.ValueItems.Add(newMarkerValueItem("Value2", markerStyle2));
//Create a InMemoryMarkerOverlay and containd one feature column named "ValueColumn"InMemoryMarkerOverlay markerOverlay =newInMemoryMarkerOverlay("Markers",newFeatureSourceColumn[] {newFeatureSourceColumn("ValueColumn") });
//Set CustomMarkerStyle for markerOverlay.markerOverlay.ZoomLevelSet.ZoomLevel01.CustomMarkerStyle = valueMarkerStyle;markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;map.CustomOverlays.Add(markerOverlay);
markerOverlay.FeatureSource.BeginTransaction();
Dictionary<string,string> feature1ColumnValues =newDictionary<string,string>();//Marker for this feature will be makerStyle2 because Value of "ValueColumn" is "Value1"feature1ColumnValues.Add("ValueColumn","Value1");//Add this feature to featuresource.markerOverlay.FeatureSource.AddFeature(newPointShape(0, 0), feature1ColumnValues);
markerOverlay.FeatureSource.CommitTransaction();
Hope this would be helpful and any other question please feel free to let us know.
Thanks,
Kevin
Hi Kevin,
thanks for this sample!
Is it also possible to assign individual Menus and Popups to the markers, or to customize a menus/popups Content in the moment it opens, when using the InMemoryMarkerOverlay following this approach?
Thanks
Karsten
Hi Karsten,
Yes, the ValueMarkerStyle display different MarkerStyle depends
on different column value, while ClassBreakMarkerStyle depends on different
class break we defined. We can set customized popup/menus for every MarkerStyle,
as sample shows you in my last reply.
Any other question please feel free to let us know.
Thanks,
Kevin
Hi can you give me the same example but for desktop edition
thanks
Hi Daniel,
Unfortunately, the “ValueMarkerStyle” isn’t supported now, but I have a work around on the sample, I think you can create a new class which is inherited from “InMemoryMarkerOverlay” and you will override “GetMarkersForDrawingCore” as following codes:
protected override GeoCollection<Marker> GetMarkersForDrawingCore(RectangleShape boundingBox)
{
GeoCollection<Marker> markers = base.GetMarkersForDrawingCore(boundingBox);
foreach (var item in markers)
{
if (item.ToolTipText.Contains(“ColumnValue”))
{
item.Image = new Bitmap(“PicturPath”);
}
}
return markers;
}
Thanks,