jumpinjackie / mapguide-maestro

MapGuide Maestro
https://jumpinjackie.github.io/mapguide-maestro/
27 stars 20 forks source link

Creating a runtime map with a DWF layer does not work #87

Closed SoroTrestal closed 4 years ago

SoroTrestal commented 4 years ago

Hello Jackie, since I have tried several times registering at the osgeo mapguide forums, (don't know why my account doesn't get approved, so i'm posting it here).

When I use the MaestroAPI and I try to create a runtime map with a DWF layer in it, it does not render the layer, when I use the GETDYNAMICOVERLAYIMAGE (and use the session created through the CreateMap function) functionality (through openlayers), creating the map with CREATERUNTIMEMAP it does work.

Regards

jumpinjackie commented 4 years ago

What MapGuide version are you using?

SoroTrestal commented 4 years ago

Thank you for your response Jackie, i'm using MapGuide 3.1.0.9064.

I have this code on my API to create a runtime map, i'm returning the sessionid to the client:

[HttpGet]       public ActionResult<string> GetMapInfo(string sessionId, string mapDefinition)
        {
            //var connection = string.IsNullOrEmpty(sessionId) || sessionId == "undefined"
            //    ? ConnectionProviderRegistry.CreateConnection(Provider, "Url", Url, "Username", Username, "Password", Password)
            //    : ConnectionProviderRegistry.CreateConnection(Provider, "Url", Url, "SessionID", sessionId);
                      IServerConnection conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http",
                "Username", "Administrator",
                "Password", "admin",
                "Url", "http://localhost/mapguide/mapagent/mapagent.fcgi");

            IMappingService mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);

            ResourceIdentifier resId = new ResourceIdentifier(mapDefinition);
            IMapDefinition mdf = (IMapDefinition)conn.ResourceService.GetResource(resId.ToString());

            double metersPerUnit = 1.0;

            ResourceIdentifier rtMapId = new ResourceIdentifier(resId.Name, ResourceTypes.Map, conn.SessionID);

            var map = mapSvc.CreateMap(rtMapId, mdf, metersPerUnit);

            map.DisplayWidth = 1024;
            map.DisplayHeight = 768;
            map.DisplayDpi = 96;

            map.Save();

            return map.SessionId;
        }

I'm have this code on my client using open layers, when creating a mg based layer:

var layer = new ImageLayer({ extent: bounds, source: new ImageMapGuide({ url: agentUrl, useOverlay: true, metersPerUnit: 1, //value returned from mapguide params: { MAPNAME: "dwfmap", FORMAT: "PNG8", SESSION: resp.data, VERSION: "2.0.0", BEHAVIOR: 2 } }) });

Every layer shows up on my image returned from mapguide except the dwf one.

If I create a runtimemap through the mapagent, it works:

` var data = new FormData(); data.set("OPERATION", "CREATERUNTIMEMAP"); data.set("VERSION", "2.6.0"); data.set("USERNAME", "Administrator"); data.set("PASSWORD", "admin"); data.set("MAPDEFINITION", "Library://Maps/dwfmap.MapDefinition"); data.set("FORMAT", "application/json"); data.set("SEQ", "1");

    return axios({
        method: "POST",
        withCredentials: false,
        url: "http://localhost/mapguide/mapagent/mapagent.fcgi",
        data
    }).then(response => {
        console.log(response);
        return response;
    });`

image

SoroTrestal commented 4 years ago

Hi Jackie the problem is solved, I was setting the map size after the map.save().

This works for regular vector and raster layer definitions though.

Regards and thank you.