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 1984var toProjection = new OpenLayers.Projection(“EPSG:900913”); // to Spherical Mercator Projectionvar 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
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Mvc;usingSystem.Runtime.Serialization.Json;usingGIS.Models;usingThinkGeo.MapSuite.Core;usingThinkGeo.MapSuite.MvcEdition;usingSystem.IO;
namespaceGIS.Controllers{publicclassGISController : Controller{//// GET: /GIS/
publicActionResult Index(){returnView();}
[MapActionFilter]publicvoidGetLocations(Map map, GeoCollection<object> args){var locationEntities =newGIS.Models.GISdb();
if(map !=null){IEnumerable<Location> Locations = locationEntities.GetLocations(46, DateTime.Now, DateTime.Now);InMemoryMarkerOverlay markerOverlay = map.CustomOverlays[“DynamicOverlay”]asInMemoryMarkerOverlay;
foreach(Location locationinLocations){if(!markerOverlay.FeatureSource.InternalFeatures.Contains(location.LocationID.ToString())){markerOverlay.FeatureSource.InternalFeatures.Add(location.LocationID.ToString(),newFeature(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!