ThinkGeo.com    |     Documentation    |     Premium Support

MapSuite MVC View Model

Is there a way to return a View Model that either inherits from Map or contains a map property so that we can not only return the map in the controller to the view, but also custom properties in the Map VIew Model?

public class MapViewModel
{
    public Map Map2 { get; set; }
}

private MapViewModel InitializeMap()
    {
        Map map = new Map("Map1", new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage),
                          new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage));
        var myMap = new MapViewModel(){Map2 = map};
        //myMap.Temp = "this is a test";

        myMap.Map2.MapUnit = GeographyUnit.Meter;
        myMap.Map2.MapTools.Logo.Enabled = true;
        myMap.Map2.MapBackground = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
        myMap.Map2.CurrentExtent = new RectangleShape(-12939426.6371, 6201997.4056, -7812401.86, 2626987.386962);

        // base map layers
        GoogleOverlay googleOverlay = new GoogleOverlay("GoogleOverlay", GoogleMapType.Normal);
        googleOverlay.JavaScriptLibraryUri = new Uri("https://maps.google.com/maps/api/js?sensor=false&key=" + GoogleKey);
        myMap.Map2.CustomOverlays.Add(googleOverlay);


        ShapeFileFeatureLayer zipCodeLayer = new ShapeFileFeatureLayer(PathFilename);
        zipCodeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(70, 220, 220, 220), 1);
        zipCodeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        LayerOverlay staticOverlay = new LayerOverlay("ZipCodeOverlay");
        staticOverlay.IsBaseOverlay = false;
        staticOverlay.Layers.Add("ZipCodeLayer", zipCodeLayer);

        Proj4Projection proj4 = new Proj4Projection();
        proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4269);
        proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
        zipCodeLayer.FeatureSource.Projection = proj4;
        ShapeFileFeatureLayer.BuildIndexFile(PathFilename);

        InMemoryFeatureLayer highlightLayer = new InMemoryFeatureLayer();
        highlightLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, 60, 180, 60), GeoColor.GeographicColors.DeepOcean);
        highlightLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        LayerOverlay dynamicOverlay = new LayerOverlay("HighLightOverlay");
        dynamicOverlay.Layers.Add("HighLightLayer", highlightLayer);
        dynamicOverlay.IsBaseOverlay = false;

        myMap.Map2.CustomOverlays.Add(staticOverlay);
        myMap.Map2.CustomOverlays.Add(dynamicOverlay);

        myMap.Map2.Popups.Add(new CloudPopup("information", myMap.Map2.CurrentExtent.GetCenterPoint()) {AutoSize = true, IsVisible = false});
      
        return myMap;
    }

I think this person is trying to do something similar with a view model and are running into a similar issue where the ClickEvent is not able to accept a ViewModel, only the Map as parameter. Is there a way to pass the entire view model to the click event via the Map.ajaxCallAction ?

enter link description here

Hi Jmarshall,

Please refer the reply in post: Shapefile click event

Regards,

Ethan