ThinkGeo.com    |     Documentation    |     Premium Support

GetBitmap with InMemoryMarkerOverlay Example

Hello ThinkGeo Support,

I am attempting to generate a bitmap image of a Map containing one or more InMemoryMarkerOverlays. Can you point me to any examples?

I can get my base layer to show up (LayerOverlay), but it does not contain any markers. Am I missing a step? Do I need to draw the marker layer serverside before calling GetBitmap?

Thank you in advance!

Hi Julian,

I think we should have a bug here for MVC, because we have related logic for print InMemoryMarkerOverlay.

For a workaround, please set scale for map before GetBitmap, as below is my test code, which print the InMemoryMarkerOverlay correct.

        map.CurrentScale = ExtentHelper.GetScale(map.CurrentExtent, (int)map.WidthInPixels, GeographyUnit.DecimalDegree);
        Bitmap bitmap = map.GetBitmap(1000, 800);
        bitmap.Save(@"C:\test.png");

If our developer have any news about this issue we will update here.

Regards,

Don

Hi Don,

I tried to set CurrentScale to the map like you did in your above code snippet but I get an error on the call to GetBitmap in System.Drawing that states “Parameter is not valid.” I used the same int values in your code snippet which I believe are the correct parameters for width and height respectively.

I am instantiating the Map server side - does that make a difference for GetBitmap?

Thanks again.

Hi Julian,

The int value is just my test value, I think your width and height shouldn’t be the same.

You can get your width and height from your map, or you can directly use the GetBitmap which without parameters.

Please make sure your dll had updated to the latest version.

Regards,

Don

Hi Julian,

As below is the updated reply.

The options of map are asynchronous on the client and server side, so you need to sent the map current extent and scale to server when you save map.
Please refer the following sample code:

Client side:
@using ThinkGeo.MapSuite;
@using ThinkGeo.MapSuite.Mvc;
@{
ViewBag.Title = “Index”;
}

@{Html.ThinkGeo().Map(Model).OnClientClick("mapClick").Render();}

Server side:
using System;
using System.Drawing;
using System.Web.Mvc;
using ThinkGeo.MapSuite;
using ThinkGeo.MapSuite.Layers;
using ThinkGeo.MapSuite.Mvc;
using ThinkGeo.MapSuite.Shapes;

namespace MapPrinter.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
Map map = new Map(“Map1”,
new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage),
new System.Web.UI.WebControls.Unit(1000, System.Web.UI.WebControls.UnitType.Pixel));

        map.MapUnit = GeographyUnit.DecimalDegree;

        map.CurrentExtent = new RectangleShape(-178.215027, 71.406647, -66.969849, 18.924782);

        InMemoryMarkerOverlay markerOverlay = new InMemoryMarkerOverlay();
        markerOverlay.FeatureSource.InternalFeatures.Add(new Feature(map.CurrentExtent.GetCenterPoint()));
        markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageWidth = 21;
        markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageHeight = 21;
        markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        map.CustomOverlays.Add(markerOverlay);
        return View(map);
    }

    [MapActionFilter]
    public void ClickEvent(Map map, GeoCollection<object> args)
    {
        double[] extentCell = Array.ConvertAll(args[0].ToString().Split(','), i => Convert.ToDouble(i));
        map.CurrentExtent = new RectangleShape(extentCell[0], extentCell[3], extentCell[2], extentCell[1]);
        map.CurrentScale = Convert.ToDouble(args[1]);
        Bitmap bitmap = map.GetBitmap();
        bitmap.Save(@"C:\result.png");
    }
}

}

If you have any questions, please email me.

Thanks,

Hi Don,

I could not get your example working properly. I get a 'World extent is not valid" error on GetBitmap on what should be valid parameters (I used the RectangleShape parameters you used for your CurrentExtent in the example above). Can you provide your client side function that calls the ClickEvent method? Is there anything else I could be doing incorrectly?

Thanks again for your help.

Hi Julian,

As below is a Mvc demo which shows how to call the ClickEvent method.

8614_MapPrinter.zip (483.2 KB)

Wish that’s helpful.

Any questions please let us know.

Thanks,

Don