Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Posts: 62
Registered: ‎11-17-2015
Accepted Solution

Geospatial Portal SDK: Add legend entries with a category

I am using Geospatial Portal SDK (2016 version) to build several custom analyses (based on WMPS) at a single time and then add them to the legend. I build an array of analysis configurations and then use $GP.queries.add to add them to the portal.


When all the queries are added, I developed a callback to add them to the legend, using $GP.legend.add. This is called with the array of analyses ids added, as config parameter. My problem is that these new legend entries appear in the Map Content Panel, Categories tab without any category associated making it confusing to the customer to identify the new legend entries added, as shown in the picture:AnalysesNoCategory.png


Is it possible to add these legend entries inside a new category (folder), with name specified by developer, using Geospatial Portal SDK?



Bruno Santos

Posts: 62
Registered: ‎11-17-2015

Re: Geospatial Portal SDK: Add legend entries with a category

If someones comes across with something similar to this requirement, I managed to set the created analysis to a new category created in the service corresponding to the analysis. I add all the analysis without adding them to legend, then in the last callback do $GP.legend.add. In the callback of this I do the following code:

//IPT-BS HACK: Create category with legendItems
var currAnalysis,
    i = 0,

if (result.success && result.ids.length > 0) {
    mapState = $mapStateManager.findMapState("map");
    legend = mapState.get_legend();
    currAnalysis = $analysisManager.findAnalysis(result.ids[0]);
    stub = {
        mapServiceId: currAnalysis._mapServiceId,
        legendItemDefinitionId: Intergraph.WebSolutions.Core.WebClient.Platform.MapServices.MapService.dummyFolderId,
        name: String.format("Temáticos #{0}", $TematicoButtonApp._currThematicNumber),
        isLocatable: true,
        isVisible: true
    newLegendItem = new Intergraph.WebSolutions.Core.WebClient.Platform.MapContent.LegendItem(stub, legend);
    dstLegendItems = legend.get_legendItems();

    for (i = 0; i < result.ids.length; i++) {
        currAnalysis = $analysisManager.findAnalysis(result.ids[i]);
        li = legend.findLegendItemByDefinitionId(currAnalysis._mapServiceId, result.ids[i])[0];
        if (li) {
            li._parent = newLegendItem;
            currLiName = li.get_definition().get_name();
            newLiName = currLiName.substring(String.format("{0}_", $TematicoButtonApp._currThematicNumber).length);
            li.set_name(newLiName);  //IPT-BS HACK: as queries with same id or name are removed, this allows to have thematics with same names without remove (faster and les buggy)
    $event.notify("refreshMapLegendControl", {
        mapStateId: "map"
    }, this);

    Ext.Msg.alert(ThematicsUI.Translate.TematicoTitulo, "Temático adicionado com sucesso.")

This is done using internal GP code but is the only way I could achieve it (seems impossible in current SDK).