Tom,
Below is the sample. What I did was to replace two methods on the sample: MapShapes\FinishTackShapeEvent. If you past the two methods below over the existing methods then it will run correctly and do what you want. I have also highlighted the main code I changed. To answer your questions..
-
When track shapes are finished drawing they will raise an event on the client side called FinsihedTrackShape. On the client side you need an asp.net button that goes server side. In the server side code you need something like Map1.Mode = ModeType.TrackPolygon. When the code returns client side it will be in a track polygon mode. The sample I modified shows this.
protected void buttonDrawPolygon_Click(object sender, ImageClickEventArgs e)
{
Map1.Mode = ModeType.TrackPolygon;
}
-
To make the track shape disappear you need to clear it from the Map1.EditLayers.Features.Clear. What happens is that when you draw track shapes on the client side we add them to this Map1.EditLayers which is an in memory layer. You can add/remove features and it will reflect that on the client side. This is kind of the link the client has with the server.
-
As far as the selected set goes there inst a version of this. If you want to add to the selected set you can loop through the items to add and then check if the current list contains the value. I do this in the sample with code like.. If(!highlightLayer.Features.ContainsKey(feature.Id) then add the item to the feature. If you want a new set you can simple call highlightLayer.Features.Clear()
-
On the Layer Switcher currently we dont support many layers. We only support Static and Dynamic layers. We will be enhancing this in the future. We will have a sample on how to build your own switcher and specify whatever you want. The current switcher has some limitation.
Thanks again, as we implemented the sample we saw some opportunities to make some API modifications to make this easier.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.BackgroundFillBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));
Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
Map1.MapUnit = GeographyUnit.DecimalDegree;
// The following two lines of code enable the client and server caching.
// If you enable these features it will greatly increase the scalability of your
// mapping application however there some side effects that may be counter intuitive.
// Please read the white paper on web caching or the documentation regarding these methods.
// Map1.ClientCache.CacheId = "WorldLayer";
// Map1.ServerCache.CacheDirectory = MapPath("~/ImageCache/" + Request.Path);
ShapeFileLayer worldLayer = new ShapeFileLayer(MapPath("~/SampleData/world/cntry02.shp"));
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.GetSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1);
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
ShapeFileLayer citiesLayer = new ShapeFileLayer(MapPath("~/SampleData/USA/cities_a.shp"));
citiesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City3;
citiesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
citiesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("AREANAME", new GeoFont("Verdana", 9), new GeoSolidBrush(GeoColor.StandardColors.Black));
citiesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);
InMemoryLayer highlightLayer = new InMemoryLayer();
highlightLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(200, GeoColor.SimpleColors.PastelRed)));
highlightLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Red;
highlightLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Map1.StaticLayers.Add("WorldLayer", worldLayer);
Map1.StaticLayers.Add("CitiesLayer", citiesLayer);
Map1.DynamicLayers.Add("HighlightLayer", highlightLayer);
}
}
protected void Map1_FinishedTrackShape(object sender, EventArgs e)
{
InMemoryLayer highlightLayer = (InMemoryLayer)Map1.DynamicLayers["HighlightLayer"];
VectorLayer worldLayer = (VectorLayer) Map1.StaticLayers["WorldLayer"];
highlightLayer.Features.Clear();
//Loop though all the track shapes and highlight the items that intersect it.
foreach (string key in Map1.EditLayer.Features.Keys)
{
Feature trackShape = Map1.EditLayer.Features[key];
Collection<Feature> features = worldLayer.QueryTools.GetFeaturesIntersecting(trackShape, new string[] { });
//Loop though all the spatial query results and add them to the highlight layer
foreach (Feature feature in features)
{
if(!highlightLayer.Features.ContainsKey(feature.Id))
{
highlightLayer.Features.Add(feature.Id, feature);
}
}
}
// Clear the track shape..
Map1.EditLayer.Features.Clear();
}
David