Hello,
I’m new to MapSuite and am working through some proof-of-concept testing with the trial MVC edition. I’m trying to load around 1500 markers into a Google map from a list of entities in my controller. For some reason the markers never show up. Here are the relevant bits of my code:
View
@using ThinkGeo.MapSuite.MvcEdition
@using ThinkGeo.MapSuite.Core
@using System.Configuration;
@{
ViewBag.Title = “GIS Test”;
}
<
script
>
function convertCoords(lon, lat) {
var fromProjection = new OpenLayers.Projection(“EPSG:4326”); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection(“EPSG:900913”); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(parseFloat(lon), parseFloat(lat)).transform(fromProjection, toProjection);
return position;
}
$(document).ready(function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
MainMap.setCenter(convertCoords(position.coords.longitude, position.coords.latitude), 13);
});
}
MainMap.ajaxCallAction(“gis/gis.aspx”, “GetLocations”, { StartDate: Date.now(), EndDate: Date.now() }, function (ajaxResponse) {
MainMap.redrawLayer(“DynamicOverlay”);
});
});
</
script
>
<
div
>
@{
Html.ThinkGeo().Map(“MainMap”, new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 900)
.MapBackground(new BackgroundLayer(new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))))
.CurrentExtent(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962)
.MapUnit(GeographyUnit.Meter)
.MapTools(mapTools =>
{
mapTools.OverlaySwitcherMapTool().Enabled(true);
mapTools.MouseCoordinateMapTool().Enabled(true);
})
.CustomOverlays(overlay =>
{
overlay.GoogleOverlay(“Google Map”).GoogleMapType(GoogleMapType.Normal).JavaScriptLibraryUri(new Uri(ConfigurationManager.AppSettings[“gisGoogleUri”]));
overlay.InMemoryMarkerOverlay(“DynamicOverlay”)
.ZoomLevelSet(z =>
{
z.ZoomLevel01.DefaultMarkerStyle.WebImage = new ThinkGeo.MapSuite.MvcEdition.WebImage(21, 25, -10.5f, -25f);
z.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
});
})
.Render();
}
</
div
>
Controller
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
System.Runtime.Serialization.Json;
using
GIS.Models;
using
ThinkGeo.MapSuite.Core;
using
ThinkGeo.MapSuite.MvcEdition;
using
System.IO;
namespace
GIS.Controllers
{
public
class
GISController : Controller
{
//
// GET: /GIS/
public
ActionResult Index()
{
return
View();
}
[MapActionFilter]
public
void
GetLocations(Map map, GeoCollection<
object
> args)
{
var locationEntities =
new
GIS.Models.GISdb();
if
(map !=
null
)
{
IEnumerable<Location> Locations = locationEntities.GetLocations(46, DateTime.Now, DateTime.Now);
InMemoryMarkerOverlay markerOverlay = map.CustomOverlays[
“DynamicOverlay”
]
as
InMemoryMarkerOverlay;
foreach
(Location location
in
Locations)
{
if
(!markerOverlay.FeatureSource.InternalFeatures.Contains(location.LocationID.ToString()))
{
markerOverlay.FeatureSource.InternalFeatures.Add(location.LocationID.ToString(),
new
Feature(location.Latitude, location.Longitude));
}
}
}
}
}
}
I’ve confirmed that the expected Location objects are being returned by my DAL.
When I debug the page using firebug, I see that the result of the GET call to markers_GeoResource.axd… returns:
[{“id”:“DynamicOverlay”, “markers”:[]}]
I’m assuming this should be populated with the markers, no?
Maybe I’m missing something simple, but I put this together based on the marker display sample.
Thanks!