Snippets

Piotr Szrajber Geospatial Portal SDK - Updatable Styled Query

Created by Piotr Szrajber last modified
/**
 * Updatable Styled Query
 * 
 * This example adds a toolbar button which creates an updatable styled query or updates it
 * if it is already created. Each update modifies query's filter and its style.
 * Query legend item can be saved in the workspace (explicitly in the user interface or from
 * code using $GP.user.workspaces)
 * 
 * Try with http://demo.hexagongeospatial.com/communityportal/Examples.aspx?gpw=85da87cf-2a3a-47cf-b69e-7cf5372421e8
 * 
 * Please note that:
 *   - this link may soon expire
 *   - the code below must be pasted manually in the javascript console  
 *
 * 2017-03-22 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
 */
var queryName = "Updatable Styled Query",
    queryIndex = 0,
    featureClassId = "{http://www.intergraph.com/geomedia/gml}OM_USA_STATES",
    serviceUrl = "http://demo.hexagongeospatial.com/GWM_WFS_NonTransactional/service.svc/get",
    scenes = [{
        title: "First Scene",
        filters: [{
            operator: "OR",
            operands: [{
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Washington"]
            }, {
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Ohio"]
            }, {
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "California"]
            }]
        }],
        style: {
            styles: [{
                type: "SimpleLineStyle",
                color: "#ff0000",
                size: 3
            }, {
                type: "SimpleFillStyle",
                color: "#00cc00",
                translucency: 0.2
            }]
        }
    }, {
        title: "Second Scene",
        filters: [{
            operator: "OR",
            operands: [{
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Texas"]
            }, {
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Utah"]
            }, {
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Arizona"]
            }]
        }],
        style: {
            styles: [{
                type: "SimpleLineStyle",
                color: "#00ff00",
                size: 5
            }, {
                type: "SimpleFillStyle",
                color: "#cc0000",
                translucency: 0.2
            }]
        }
    }, {
        title: "Third Scene",
        filters: [{
            operator: "OR",
            operands: [{
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Florida"]
            }, {
                operator: "=",
                operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", "Georgia"]
            }]
        }],
        style: {
            styles: [{
                type: "SimpleLineStyle",
                color: "#0000ff",
                size: 3
            }, {
                type: "SimpleFillStyle",
                color: "#0000cc",
                translucency: 0.2
            }]
        }
    }];

function executeQuery(scene, callback, errback) {
    $GP.queries.add({
        featureClassId: featureClassId,
        url: serviceUrl,
        definitionName: "WFS",
        queryName: queryName,
        addToLegend: false,
        filters: scene.filters,
        style: new Intergraph.WebSolutions.Core.WebClient.Platform.Style.AreaStyle(null, scene.style)
    }, callback, errback);
}

function executeNextQuery(b) {
    executeQuery(scenes[queryIndex++ % 3], function(result) {
        if (result.updated) {
            $GP.ui.info("Analysis updated #" + (queryIndex + 1));
            return;
        } else {
            $GP.ui.info("Analysis created!");
        }
        $GP.queries.find({
            analysisId: result.analysisId,
        }, function(result2) {
            result2.analysis.addToLegend(function() {
                $GP.legend.find({
                    name: queryName
                }, function(ret) {
                    ret.legendItems[0].fitLayer();
                });
            });
        });
    }, function() {
        $GP.ui.info("Something went wrong");
    });
}

$GP.ui.toolbar.add({
    categoryIndex: 0,
    xtype: "tbbutton",
    text: "Update query",
    handler: executeNextQuery
});

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.