M.App Enterprise Discussions

Discuss topics with other M.App Enterprise Product pioneers and experts to get the most out of it.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Contributor
Posts: 28
Registered: ‎04-21-2017
Accepted Solution

Adding WMS Layer programatically

[ Edited ]

Hi,

 

I'm trying to add a new WMS layer programmatically from the custom JS of a BI Map panel, using the gsp.legend.add() API. I'm following one of the examples which I found in the M.App Studio cloud version, called "Add WMS layer to the legend":

 

var wmsUrl = "http://www2.demis.nl/worldmap/wms.asp",
   legendDefinition = {
       definitionName: "WMS",
       url: wmsUrl,
       id: "Bathymetry,Countries,Topography,Hillshading",
       name: "Demis Map",
       bbox:  [0, 0, 0, 0],
       bboxCrs: "EPSG:4326",
       supportedCrses: ["EPSG:4326", "EPSG:3857"]
   };

gsp.legend.add(legendDefinition);

this code (using our WMS instead of the example's one) works properly on the cloud M.App Studio, but it doesn't on M.App Enterpise. No error is returned in the console, nor in the network tab of the DevTools, basically no HTTP call is issued towards the WMS itself. 

I noticed that in the M.App Enterprise examples, the WMS one is not present by the way, so I was wondering: is the gsp.legend.add() API not working/deprecated on M.App Enterprise?

 

Thanks for your help,

Giorgio

 

AA
Highlighted
Staff
Posts: 1,108
Registered: ‎10-18-2015

Re: Adding WMS Layer programatically

Hi Giorgio,

 

it is almost correct, the main difference with the cloud version is that we do not have a WMS service preconfigured in the platform, so in order to make it to work we have to provide the service metadata. Here is a call I'm using in one app (I'm sending parameters from a custom panel in this case):

 

    var legendDefinition = {
            definitionName: messageParams.definitionName,
            url: messageParams.url,
            id: messageParams.layerName,
            name: messageParams.name,
            bbox:  messageParams.bbox,
            bboxCrs: messageParams.bboxCrs,
            supportedCrses: messageParams.supportedCrses,
            serviceMetadata: {
            "version": "1.3.0",
            "operationsMetadata": {
                "getMap": {
                    "parameters": {
                        "formats": [
                            "image/png",
                            "image/jpeg"
                        ]
                    },
                    "endpoints": {
                        "get": messageParams.url
                    }
                }
            },
            "rootLayer": {
                "crs": [
                    "EPSG:3857"
                ],
                "layers": [{
                    "title": messageParams.name,
                    "name": messageParams.layerName
                }]
            },
            "type": "wmsServiceMetadata"
            }
};

HTH,

Stefano

Stefano Turcato
Presale Engineer
Hexagon Geospatial
Highlighted
Technical Evangelist
Posts: 1,313
Registered: ‎09-11-2015

Re: Adding WMS Layer programatically

Hi Stefano,

 

Thanks, I've been playing with it for several minutes now and your code really helped. Here's my fully working sample:

var legendDefinition = {
   definitionName : "WMS",
   url : "https://demo.hexagongeospatial.com/DemoTimeZones/service.svc/get",
   id : "Time_zones",
   name : "WMS Time zones",
   supportedCrses : ["EPSG:3857"],
   serviceMetadata : {
      "version" : "1.3.0",
      "operationsMetadata" : {
         "getMap" : {
            "parameters" : {
               "formats" : ["image/png"]
            },
            "endpoints" : {
               "get" : "https://demo.hexagongeospatial.com/DemoTimeZones/service.svc/get"
            }
         }
      },
      "rootLayer" : {
         "crs" : ["EPSG:3857"],
         "layers" : [{
               "title" : "WMS Time zones",
               "name" : "Time_zones"
            }
         ]
      },
      "type" : "wmsServiceMetadata"
   }
};

$GP.legend.add(legendDefinition,
function(cb) {console.log(cb)},
function(eb) {console.log("ERROR"); console.log(eb)}
);

 

 

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Contributor
Posts: 28
Registered: ‎04-21-2017

Re: Adding WMS Layer programatically

Thanks Stefano for the reply and solution!

 

Regards,

Giorgio

AA
Highlighted
New Contributor
Posts: 10
Registered: ‎02-12-2020

Re: Adding WMS Layer programatically

Can You provide the code in c# ?

Highlighted
Technical Evangelist
Posts: 1,313
Registered: ‎09-11-2015

Re: Adding WMS Layer programatically

This is a browser application running JS, why a need for C# code?

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
New Contributor
Posts: 10
Registered: ‎02-12-2020

Re: Adding WMS Layer programatically

[ Edited ]

I want to add WMS layer programmatically in geomedia desktop using c#.

Highlighted
Technical Evangelist
Posts: 1,313
Registered: ‎09-11-2015

Re: Adding WMS Layer programatically

This is discussion board related to M.App Enterprise product. For product API/SDK questions please use Developer Discussions: https://community.hexagongeospatial.com/t5/Developer-Discussions/bd-p/HGDDevDiscussions

 

Thanks

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial