ThinkGeo.com    |     Documentation    |     Premium Support

SetDrawMode + Spatial Query

Running MVC Edition, I’m trying to create a button that will allow the user to draw a circle on the map and return all objects from a particular overlay that are within the circle. I have the button created, but I’m having issues getting the map to draw the circle and return the results. Any help and/or code to do this would be much appreciated.

Hi Chad,

Here are the code snippets meet your requirement, as shown below:

===cshtml===

<script language="javascript" type="text/javascript">
function saveMap() {
    var features = Map1.getEditFeaturesInJson();
    Map1.ajaxCallAction("Home", "SaveMap", { editFeatures: features }, function callback() {
        Map1.clearEditingFeatures();
        Map1.setDrawMode("Normal");
        Map1.redrawLayer("DynamicOverlay");
    });
}
</script>
<div>
@{
    Html.ThinkGeo().Map("Map1", new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510)
        .MapBackground(new BackgroundLayer(new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))))
        .EditOverlay(editOverlay =>
        {
            editOverlay.EditSettings(setting =>
            {
                setting.IsDraggable = false;
            });
        })
        .CurrentExtent(-131.22, 55.05, -54.03, 16.91)
        .MapUnit(GeographyUnit.DecimalDegree)
        .CustomOverlays(overlays =>
        {
            overlays.WorldMapKitWmsWebOverlay("WorldMapKitOverlay");

            InMemoryFeatureLayer shapeLayer = new InMemoryFeatureLayer();
            shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(180, 102, 255, 102), 10, GeoColor.StandardColors.DarkGreen, 1);
            shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 4, true);
            shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(180, 102, 255, 102), GeoColor.StandardColors.DarkGreen, 1);
            shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            shapeLayer.DrawingQuality = DrawingQuality.HighQuality;

            overlays.LayerOverlay("DynamicOverlay").Layer("shapeLayer", shapeLayer).IsBaseOverlay(false).TileType(TileType.SingleTile);
        })
        .Render();
}
</div>
<div>
<input id="drawCircle" name="group1" type="button" value="Draw Circle" onclick="Map1.setDrawMode('Circle'); return false;" />
<br />
<input id="saveMap" name="group1" type="button" value="Save Map" onclick="saveMap()" />
<br />
</div>

===HomeController.cs===

   [MapActionFilter]
   public void SaveMap(Map map, GeoCollection<object> args)
    {
        // Gets the circles as feature collection.
        Collection<Feature> features = MapHelper.ConvertJsonToFeatures(args[0].ToString());

        LayerOverlay dynamicOverlay = (LayerOverlay)map.CustomOverlays["DynamicOverlay"];
        InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"];

        foreach (Feature feature in features)
        {
            if (!shapeLayer.InternalFeatures.Contains(feature.Id))
            {
                shapeLayer.InternalFeatures.Add(feature.Id, feature);
            }
        }

        map.EditOverlay.Features.Clear();
    }

Also you can refer to
http://samples.thinkgeo.com/MvcEdition/HowDoISamples/InteractiveOverlays/DrawEditShapes/1,AllSamples
http://samples.thinkgeo.com/MvcEdition/HowDoISamples/InteractiveOverlays/TrackShapeFinishedEvent/1,AllSamples

Hope it’s helpful.

If something misunderstood here, please provide more inormation.
Thanks,
Emil