ThinkGeo.com    |     Documentation    |     Premium Support

Adding Markers to An InMemmory Marker Overlay & Debugging Javascript Contained .axd Resource Files

Hello, 



I am working with Map Suite MVC 7.0 in Visual Studio 2012 . I am trying to add markers to an InMemoryMarkerOverlay, but the markers are failing to show on the map.  The issue is caused by an exception occurring in the opl_GeoResource.axd, however, I am finding this extremely difficult to debug as it is minified. I have included the error below.



Is there a way to view and debug the resources in a readable manner?



Here is the exception object thrown:


a:  Syntax error
description:    "Syntax error"
message:    "Syntax error"
number: -2146827286
stack:  "SyntaxError: Syntax error\n   at AddMarkersByAjax (<a href="localhost">localhost</a>:50708/ACCESSBeta2/helper_GeoResource.axd:162:5)\n   at onComplete (<a href="localhost">localhost</a>:50708/ACCESSBeta2/parser_GeoResource.axd:675:25)\n   at respondToReadyState (<a href="localhost">localhost</a>:50708/ACCESSBeta2/opl_GeoResource.axd:1021:587)\n   at onStateChange (<a href="localhost">localhost</a>:50708/ACCESSBeta2/opl_GeoResource.axd:1019:421)\n   at Anonymous function (<a href="localhost">localhost</a>:50708/ACCESSBeta2/opl_GeoResource.axd:19:167)"



Hi Michael,

We tried to recreate your issue on our end but failed. There are two options to resolve this:


1. Provide us some code snippets or provide us a demo for us to recreate your issue? Below code shows you how to add marker to InMemoryMarkerOverlay.



    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
            Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46);
            Map1.MapUnit = GeographyUnit.DecimalDegree;
 
            WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay(“WorldMapKitOverlay”);
            Map1.CustomOverlays.Add(worldMapKitOverlay);
 
            InMemoryMarkerOverlay markerOverlay = new InMemoryMarkerOverlay(“MarkerOverlay”);
            markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageWidth = 21;
            markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageHeight = 25;
            markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageOffsetX = -10.5f;
            markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageOffsetY = -25f;
            markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            Map1.CustomOverlays.Add(markerOverlay);
 
            Map1.WebConfigRegisterMode = WebConfigRegistrationMode.Manual;
 
            Map1.ResourceDeploymentMode = ResourceDeploymentMode.Manual;
        }
    }
 
    protected void Map1_Click(object sender, MapClickedEventArgs e)
    {
        InMemoryMarkerOverlay markerOverlay = (InMemoryMarkerOverlay)Map1.CustomOverlays[“MarkerOverlay”];
        markerOverlay.FeatureSource.InternalFeatures.Add(“marker” + DateTime.Now.ToString(“mmssms”), new Feature(e.Position));
    }
}





2. If you need to debug this. The opl_GeoResource.axd is OpenLayers source code of version 2.13, we’ve made some modifications on it. But the marker will still work based on the original 2.13 version. What you need is set IsDefaultJavascriptLibraryDisabled as false, and reference these JavaScript code manually.




Waiting for your response.




Regards,

Kevin

I am using the following code to setup the Overlay:


protected void SetupAVLOverlay()
{
    //Setup the FeatureSourceColumns.
    List<FeatureSourceColumn> columns = new List<FeatureSourceColumn>();
 
    //Add  the columns to the list.
 
    //Base AVL Info
    columns.Add(new FeatureSourceColumn(“Id”));
    columns.Add(new FeatureSourceColumn(“RouteId”));
    columns.Add(new FeatureSourceColumn(“TimeStamp”));
    columns.Add(new FeatureSourceColumn(“Longitude”));
    columns.Add(new FeatureSourceColumn(“Latitude”));
    columns.Add(new FeatureSourceColumn(“Speed”));
    columns.Add(new FeatureSourceColumn(“Heading”));
    columns.Add(new FeatureSourceColumn(“Route”));
    columns.Add(new FeatureSourceColumn(“Label”));
 
    //Extended AVL Info
    //columns.Add(new FeatureSourceColumn(“amOnboard”));
    //columns.Add(new FeatureSourceColumn(“wcOnboard”));
    //columns.Add(new FeatureSourceColumn(“nextStopId”));
    //columns.Add(new FeatureSourceColumn(“nextStopAM”));
    //columns.Add(new FeatureSourceColumn(“nextStopWC”));
    //columns.Add(new FeatureSourceColumn(“nextStopAddrName”));
    //columns.Add(new FeatureSourceColumn(“nextStopAddrStreet”));
    //columns.Add(new FeatureSourceColumn(“nextStopZone”));
    //columns.Add(new FeatureSourceColumn(“isLate”));
    //columns.Add(new FeatureSourceColumn(“vehNum”));
    //columns.Add(new FeatureSourceColumn(“driverName”));
 
    //Create the FeatureSourceMarkerOverlay.
    InMemoryMarkerOverlay avlDataOverlay = new InMemoryMarkerOverlay(“AVLOverlay”, columns);
 
    //Setup styles.
 
    //Create the ClassBreakMarkerStyle.
    ClassBreakMarkerStyle cbms = new ClassBreakMarkerStyle(“isLate”, BreakValueInclusion.IncludeValue);
 
    //Add MarkerClassBreak objects, they need to be added from smallest value to largest largest value.
 
    //Create the first MarkerClassBreak object, set it up, and add it to the collection.
    MarkerClassBreak onTime = new MarkerClassBreak();
    onTime.Value = 0;
    //Use the custom MarkerStyle for ontime.
    onTime.DefaultMarkerStyle.WebImage = new WebImage(@"~/Content/MapIcons/AVLMarkerOnTime.gif");
 
    cbms.ClassBreaks.Add(onTime);
 
    //Create the MarkerClassBreak object, set it up, and add it to the collection.
    MarkerClassBreak late = new MarkerClassBreak();
    late.Value = 1;
    //Use the custom MarkerStyle for late.
    late.DefaultMarkerStyle.WebImage = new WebImage(@"~\Content\MapIcons\AVLMarkerLate.gif");
 
    cbms.ClassBreaks.Add(late);
 
    avlDataOverlay.ZoomLevelSet.ZoomLevel01.CustomMarkerStyle = cbms;
    avlDataOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
 
    //Apply projection to layer.
    try
    {
        this.WGS84toSphMercator.Open();
        avlDataOverlay.FeatureSource.Projection = this.WGS84toSphMercator;
    }
    finally
    {
        this.WGS84toSphMercator.Close();
    }
 
    //Set the visibility and whether the overlay is visible in the overlay switcher.
    avlDataOverlay.IsVisible = true;
 
    avlDataOverlay.IsVisibleInOverlaySwitcher = false;
 
    //Add the overlay to the map.
    Map.CustomOverlays.Add(avlDataOverlay);
}

I am using the following method in the controller to populate the Overlay:


protected RectangleShape PopulateMapAVLOverlay(Map map, List<vAvlMapData> data)
{
    RectangleShape newExtent;
 
    //Get the overlay from the map.
    InMemoryMarkerOverlay avlOverlay = (InMemoryMarkerOverlay)map.CustomOverlays[“AVLOverlay”];
 
    try
    {
        //Open the featuresource and begin the transaction if we are not already in another transaction.
        avlOverlay.FeatureSource.Open();
 
        //Open the MappingUtility’s projection that we will use.
        MappingUtility.WGS84toSphMercator.Open();
 
        //Clear the internal features from the overlay.
        avlOverlay.FeatureSource.InternalFeatures.Clear();
 
        //Create features from data and add to the layer
        if (data != null && data.Count > 0)
        {
            foreach (vAvlMapData datum in data)
            {
                Dictionary<stringstring> dict = new Dictionary<stringstring>();
 
                //AVL data.
                dict.Add(“Id”, datum.avlId.ToString());
                dict.Add(“RouteId”, datum.avlrteId.ToString());
                dict.Add(“TimeStamp”, datum.avlTimeStamp.ToString(“HH:mm”));
                dict.Add(“Longitude”, datum.avlLongitude.ToString());
                dict.Add(“Latitude”, datum.avlLatitude.ToString());
                dict.Add(“Speed”, datum.avlSpeed.ToString());
                dict.Add(“Heading”, datum.avlHeading.ToString());
                dict.Add(“Route”, datum.rteName.ToString());
 
                string label = datum.rteName.ToString();
 
                dict.Add(“Label”, label);
 
                PointShape p = new PointShape(MappingUtility.ConvertDBCoordToMap(datum.avlLongitude), MappingUtility.ConvertDBCoordToMap(datum.avlLatitude));
 
                Feature newFeature = new Feature(p.X, p.Y, datum.avlId.ToString(), dict);
 
                avlOverlay.FeatureSource.InternalFeatures.Add(newFeature);
            }
        }
    }
    finally
    {
        //Get the bounding box for the Overlay.
        if (avlOverlay.FeatureSource.InternalFeatures.Count > 0)
        {
            newExtent = avlOverlay.FeatureSource.GetBoundingBox();
        }
        else
        {
            //Convert the extent to the projection.
            newExtent = MappingUtility.WGS84toSphMercator.ConvertToExternalProjection(MappingUtility.DefaultExtent);
        }
 
        MappingUtility.WGS84toSphMercator.Close();
 
        avlOverlay.FeatureSource.Close();
    }
 
    //Return new map extent
    return newExtent;
}


Hi Michael, 
  
 Thanks for your code, but unlucky we still cannot reproduced your issue. 
  
 I am not sure where is the problem, but could you please try the latest version of our dll first and let us know whether the issue still existing. 
  
 Regards, 
  
 Don

Actually, we just upgraded to version 8.0.336.0 to correct an issue we were having with the deployment and I am still seeing this issue. 
  
 I have been testing an alternate approach using a SimpleMarkerOverlay which works, though I have concerns over potential performance issues as there could be up to ~75 data points at a given time and this particular map will be refreshing data roughly every minute.

Hi Michael,



I created a sample with your codes and looks like the sample works fine without exception. Would you please try the sample and modify it to recreate the issue?



Actually the exception message "stack:  “SyntaxError: Syntax error\n   at AddMarkersByAjax” shows it happened at AddMarkersByAjax method, as I know this method is not minified. You should see the method at helper_GeoResource.axd file which is generated dynamically.



For SimpleMarkerOverlay, in map suite 8.0, as it is only initialized when page loaded, I don’t think it is easy to refresh every minutes. 



Thanks,



Troy

post12662.zip (117 KB)

I finally figured out what the issue was. I was setting up the ClassBreaks improperly. I ended up breaking the code setting those up into separate methods, which I will post below for completeness in case anyone else encounters a similar issue.


private MarkerClassBreak SetupOnTimeClassBreak()
{
    //Create the WebImage used for the styles.
    WebImage wi = new WebImage();
 
    //Setup the FontStyle and TextOffset.
    wi.FontStyle = new GeoFont(“Arial”, 12, DrawingFontStyles.Bold);
 
    wi.TextOffsetX = 20;
 
    //Set the Text property to use the value in the FeatureSource’s Route column.
    wi.Text = “[#Route#]”;
 
    //Offset the image displayed for the marker, this places the point of the teardrop at the location
    wi.ImageOffsetX = -10.5f;
    wi.ImageOffsetY = -25f;
 
    //Set the path for this image.
    wi.ImageVirtualPath = @"~/Content/MapIcons/AVLMarkerOnTime.gif";
 
    //Create the MarkerClassBreak with the break value.
    MarkerClassBreak mcb = new MarkerClassBreak(0);
 
    //Set the DefaultMarkerStyle’s WebImage property to our WebImage.
    mcb.DefaultMarkerStyle.WebImage = wi;
 
    return mcb;
}
 
private MarkerClassBreak SetupLateClassBreak()
{
    //Create the WebImage used for the styles.
    WebImage wi = new WebImage();
 
    //Setup the FontStyle and TextOffset.
    wi.FontStyle = new GeoFont(“Arial”, 12, DrawingFontStyles.Bold);
 
    wi.TextOffsetX = 20;
 
    //Set the Text property to use the value in the FeatureSource’s Route column.
    wi.Text = “[#Route#]”;
 
    //Offset the image displayed for the marker, this places the point of the teardrop at the location
    wi.ImageOffsetX = -10.5f;
    wi.ImageOffsetY = -25f;
 
    //Set the path for this image.
    wi.ImageVirtualPath = @"~/Content/MapIcons/AVLMarkerLate.gif";
 
    //Create the MarkerClassBreak with the break value.
    MarkerClassBreak mcb = new MarkerClassBreak(1);
 
    //Set the DefaultMarkerStyle’s WebImage property to our WebImage.
    mcb.DefaultMarkerStyle.WebImage = wi;
 
    return mcb;
}



Michael, 
  
 Great to hear you figure it out. 
  
 Thanks, 
  
 Troy