Snippets
Created by
Piotr Szrajber
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | /**
* Randomly update styles and filters for queries in the legend grouped under one node
*
* Assumption: A1, A2 and A3 queries are already in the Legend->Layers
*
* This script can be tested with the following workspace:
* http://demo.hexagongeospatial.com/communityportal/Examples.aspx?gpw=bc775c72-52cc-44a4-889c-d32070ef908b
*
* Paste this code in the javascript console. "A1", "A2" and "A3" buttons will appear in the Tools menu. Clicking
* on each of these buttons causes changing filter and style of the associated layer. Filter and style are chosen
* randomly.
*
* 2017-03-22 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
*/
var defaultLayerName = "Hexagon Geospatial OGC Web Feature Service",
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(queryName, filters, style, callback, errback) {
$GP.queries.add({
featureClassId: featureClassId,
url: serviceUrl,
definitionName: "WFS",
queryName: queryName,
addToLegend: false,
filters: filters,
style: new Intergraph.WebSolutions.Core.WebClient.Platform.Style.AreaStyle(null, style)
}, callback, errback);
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
function executeNextQuery(queryName, parentLayerName) {
var style = scenes[getRandomInt(0, scenes.length - 1)].style,
filters = scenes[getRandomInt(0, scenes.length - 1)].filters;
executeQuery(queryName, filters, style, function(result) {
if (result.updated) {
$GP.ui.info("Analysis updated");
return;
} else {
$GP.ui.info("Analysis created!");
$GP.queries.find({
analysisId: result.analysisId,
}, function (result2) {
result2.analysis.addToLegend({
parentLayerName: parentLayerName
});
});
}
}, function() {
$GP.ui.info("Something went wrong");
});
}
["A1", "A2", "A3"].forEach(function (item) {
$GP.ui.toolbar.add({
categoryIndex: 0,
xtype: "tbbutton",
text: item,
handler: function(b) {
executeNextQuery(item, defaultLayerName);
}
});
});
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.