Thanks for your quick response and a great sample to get me going in the right direction. I have a few more questions.
1. If I have the average ( lat, long) for a state NY,42.1497,-74.9384 . How do I place multiple markers in the state without over lapping . The only thing I could come up with is to generate a random lat , long in a 2 degree radius from this average.
Also from the states.shp file can I some how get the lat long from a feature.
2. I could implement the markers using SimpleMarkerOverLay like you mentioned in the sample. I also did it in another way using ValueMarkerStyle and adding Features to MarkerOverLay of the Map Control . My question is what is the difference between them and what is he preferred method to add markers .
Hi Savy, Just as you have mentioned, I recommend you using ValueMarkerStyle and adding Features into MarkerOverlay of map control, it will give us a better performance than SimpleMarkerOverlay, because it always load the markers in view export only rather than all the markers like SimpleMarkerOverlay. Additionally, we can use ClusterMarkerStyle to filter the markers based on the screen distance to make sure there isn’t any overlapping. Here is the demo code:
ValueMarkerStyle valueMarkerStyle = new ValueMarkerStyle();
MarkerValueItem item1 = new MarkerValueItem("value"); ClusterMarkerStyle clusterMarkerStyle = new ClusterMarkerStyle(10d, Map1..WidthInPixels, Map1.HeightInPixels); clusterMarkerStyle.MarkerStyle = new PointMarkerStyle(new WebImage())); item1.CustomMarkerStyle = clusterMarkerStyle;
valueMarkerStyle.ValueItems.Add(item1);
To get the lat/long from a feature in “states.shp”, we can loop all the features in the featureSource and get the center point using “feature.GetShape().GetCenterPoint()”.
Thanks for the clarification regarding the SimpleMarkerOverlay. I used GetCenterPoint to get the lat long of the state feature and generated a random value between (-1,1) and used this to offset the placement of the multiple marker. I did not want to cluster them as I have not more than five markers per state . Just want to make sure that this the best way to do .
Also , I am using states.shp file to display my map I have statesLayer added to the Map control's StaticOverlay.layers collection and a markerOverLay added to CustomOverLays collection . Is this the right way to use Layers ?
The map displays as a flat image without the projection . How do I use a projection on the states.shp file so that its layout is similar google maps. I am in a disconnected network without internet connection .
HI Savy, Please check the answers: 1. Maybe there is a problem if we generate the random values between (-1,1), because I’m not sure whether there is any state which is smaller than (-1,1) like (-0.5, 0.5.), if in that case, we will get a marker outside of the state, right? I strongly recommend you checking the width of state with (-1,1) before generation. 2. Yes, absolutely it’s the right way to display the map and markers. 3. To get the projected map like Google’s, we just need to assign the projection to the stateLayer, please check the code as following: