ThinkGeo.com    |     Documentation    |     Premium Support

Map from Controller not displying

I’m trying to build a map in the controller and pass it as the Model into the view. Here’s my View:

 <div class="twelve columns" id="main">
    @Html.ThinkGeo().Map(Model).Render();
</div>

When I run this controller action, the map comes up empty; and when I try to zoom in on the empty map, I get a message saying “parameter is not valid” :

  public ActionResult Index()
    {
        var currentlocation = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
        var map = new Map("Map1", new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 512)
        {
            MapBackground = new BackgroundLayer(new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))),
            CurrentExtent = currentlocation,
            MapUnit = GeographyUnit.DecimalDegree
        };

        var osmLayer = new OpenStreetMapLayer { TileCache = new FileBitmapTileCache(@"C:\Test\OSMTileCache") };
        LayerOverlay osmOverlay = new LayerOverlay("OSMOverlay")
        {
            Name = "OSM Map",
            IsVisible = true,
            ServerCache = new ServerCache(@"C:\Test\ServerCache"),
            IsBaseOverlay = true
        };

        osmOverlay.Layers.Add(osmLayer);
        map.CustomOverlays.Add(osmOverlay);
        return View(map);

    }

… if I run this in the controller instead, the map shows up fine, but I haven’t found anywhere to set the caching properties using this approach:

       var osmOverlay = new OpenStreetMapOverlay("osmoverlay");
        map.CustomOverlays.Add(osmOverlay);
        return View(map);

My goal is to get create the map from the controller with server-side tile caching.
Any help would be appreciated.

Thanks,
Eric

Hi Eric,

The reason why “parameter is not valid” is that the “currentlocation” is invalid for the current map unit,
please set the MapUnit property of Map to “GeographyUnit.Meter”.

And the first code snippet you provided can implement server-side tile caching. usually we just need a cache, it means you can choose any one of “osmLayer” and “osmOverlay”.

Hope it works for you.
Thanks,
Emil

Thanks Emil, I figured it was something simple. Changing the map unit fixed the problem.
All the best,
Eric

Hi Eric,

You’re welcome. Very glad to hear it works.

Thanks,
Emil