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 147 148 149 150 151 152 153 154 155 | /**
* 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)
*
* The code below must be pasted manually in the javascript console
*
* 2018-04-14 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com>
*/
var featureClassId = "{http://www.intergraph.com/geomedia/gml}OM_USA_STATES",
serviceUrl = "http://demo.hexagongeospatial.com/GWM_WFS_NonTransactional/service.svc/get",
style1 = {
styles: [{
type: "SimpleLineStyle",
color: "#ff0000",
size: 3
}, {
type: "SimpleFillStyle",
color: "#00cc00",
translucency: 0.2
}]
},
style2 = {
styles: [{
type: "SimpleLineStyle",
color: "#00ff00",
size: 5
}, {
type: "SimpleFillStyle",
color: "#cc0000",
translucency: 0.2
}]
},
style3 = {
styles: [{
type: "SimpleLineStyle",
color: "#0000ff",
size: 3
}, {
type: "SimpleFillStyle",
color: "#0000cc",
translucency: 0.2
}]
},
progressions = [
createQueryProgression("First", [
["Washington", "Oregon"],
["Oregon", "California"],
["California", "Nevada"],
["Nevada", "Idaho"],
["Idaho", "Washington"],
], style1),
createQueryProgression("Second", [
["Arizona", "Utah"],
["Utah", "Wyoming"],
["Wyoming", "Colorado"],
["Colorado", "Arizona"]
], style2),
createQueryProgression("Second", [
["Mississippi", "Alabama"],
["Alabama", "Georgia"],
["Georgia", "Florida"],
["Florida", "Georgia"],
["Alabama", "Georgia"],
["Mississippi", "Alabama"]
], style3)
];
function createQuery(title, stateNames, style) {
return {
title: title,
filters: [{
operator: "OR",
operands: stateNames.map(function(stateName) {
return {
operator: "=",
operands: ["{http://www.intergraph.com/geomedia/gml}STATE_NAME", stateName]
};
})
}],
style: style
};
}
function createQueryProgression(titlePrefix, filters, style) {
// only the first one has an explicitly defined style
var ret = [createQuery(titlePrefix + "#0", filters[0], style)];
for (var i = 1; i < filters.length; i++)
ret.push(createQuery(titlePrefix + "#" + i, filters[i]));
return ret;
}
function executeQuery(queryName, 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 createProgressionHandler(queryName, progression) {
var progressionIndex = 0,
progressionLength = progression.length;
return function() {
executeQuery(queryName, progression[progressionIndex++ % progressionLength], function(result) {
if (result.updated) {
$GP.ui.info("Analysis updated #" + (progressionIndex + 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");
});
};
}
var p1 = createProgressionHandler("progression1", progressions[0]),
p2 = createProgressionHandler("progression2", progressions[1]),
p3 = createProgressionHandler("progression3", progressions[2]);;
function action() {
// if there's only one progression at time, it works. If they're executing simultanously, it loses style
p1();
p2();
p3();
}
$GP.ui.toolbar.add({
categoryIndex: 0,
xtype: "tbbutton",
text: "Update query",
handler: action
});
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.