|
POST
|
Never mind, I figured that out too. When making my array of field names, I just needed to exclude OBJECTID with an if statement.
... View more
07-03-2014
08:40 AM
|
0
|
0
|
2180
|
|
POST
|
I don't know why, but this did not work for me in my initial grid creation. I ended up with data that loaded into my grid that started with "C" and not "A". But I took the lines of code and put them in my saveGridCSV function and they behaved just fine there.
function saveGridCSV(gridData){
var fName;
if (gridData) {
var gridLength = gridData.store.data.length;
dataArray.length = 0;
fieldNames.length = 0;
var fieldValue = "";
var gridColumns = gridData.columns;
var fieldHeaders = ["ID", "County", "Acres Treated", "Pct Area Treated", "Pct Change 2002-2007"];
for (var col in gridColumns) {
fieldNames.push(col);
}
var lastCol = fieldNames.length -1;
var lastField = fieldNames[lastCol];
dataArray.push(fieldHeaders.toString()+ " \n");
var gridStore = gridData.store;
var object = gridStore.query(function (item) {
return item;
}, { sort: [{ attribute: "NAME" }] });
var newStore = new Memory({ data: object });
//steps through each record, pushes the values into an array that is formatted for CSV compatibility
for (var i = 0; i < gridLength; i++) {
var gridRow = newStore.data;
arrayUtils.forEach(fieldNames, function(fieldName){
fieldValue = gridRow[fieldName];
var stringValue = String(fieldValue);
if (stringValue.indexOf(",") > 0) { //removes any commas from data
stringValue = stringValue.replace(/,/g, " ");
}
if (stringValue.indexOf('\'') != -1 || stringValue.indexOf('\"') != -1) { //removes any slashes from data
// console.log ("Data has a slash in it. Not sure of this section of the code!");
if (stringValue.indexOf('\"') != -1) {
stringValue = stringValue.replace("\"", "\"\"");
}
stringValue = "\"" + stringValue + "\"";
}
if (fieldName == lastField) {
dataArray.push(stringValue + " \n");//adds a new line when value is from the last field
} else {
dataArray.push(stringValue);//otherwise just adds the value
}
});
}//one row pushed to array
var data = dataArray.join();
var inputData = data.replace(/\n,/g, "\n");//some clean up to get rid of the leading commas in the data
submitCSVprint(gridData.id, inputData);
} else { //nothing to save
alert ("Error saving data.");
}
}
The only thing left I want to do is drop off the OBJECTID out of the store in this function. I need it for my initial grid because I have a click event using that ID. I don't really want it in my CSV output. Now that my data is sorted alphabetically by county, that OBJECTID looks even more out of place.
... View more
07-03-2014
08:26 AM
|
0
|
0
|
2180
|
|
POST
|
I hadn't thought of that. I feel like the documentation for dGrid and store is scattered all over various sites. I wasn't sure what I should put in my query since I want all records. Since I make a store for the initial grid creation, I thought sorting it before I put it in the grid in the first place seemed like a good idea. Then when I pull the store again to make my CSV, it will already be sorted.
var featureAttributes = arrayUtils.map(results.featureSet.features, function(feature){
return feature.attributes;
});
var currentMemory = new Memory ({data:featureAttributes, idProperty:'OBJECTID'});
currentMemory.query({NAME:"*"}, {
sort: [{attribute: "NAME"},
descending: false]
});
This didn't give any errors, but it didn't sort my data either. I threw in the descending argument, I'm not sure if that's the default already or not.
... View more
07-03-2014
06:51 AM
|
0
|
0
|
2180
|
|
POST
|
I have a grid I'm creating that needed to be sorted, and also be able to save the grid to a CSV file and retain the sort I have on the grid. The grid is created in the results handler of queryTask. At this point, I simply run sort on the field I want and the grid looks fine. But that's a sort on the grid, not on the underlying data. grid = new (declare([Grid, ColumnHider, DijitRegistry, ColumnResizer]))({ id:"myGrid', columns: gridcolumns, store: currentMemory }); grid.startup(); grid.sort('NAME'); Next I have a button that will allow the user to save this information to a CSV. It's getting created into the same container the grid is, so I can pass the argument of the grid name to it. var saveButton = new Button({ label: "Save List", onClick: function(){ saveGridCSV(grid); } }, "btnSave"); registry.byId("gridContainer").addChild(saveButton); registry.byId("gridContainer").addChild(grid); Within my saveGridCSV, I'm going back to the store of the grid and using it to get the values formatted for the CSV. //functions for saving to Excel function saveGridCSV(gridData){ var fName; if (gridData) { var gridLength = gridData.store.data.length; dataArray.length = 0; fieldNames.length = 0; var fieldValue = ""; var gridColumns = gridData.columns; var fieldHeaders = ["ID", "County", "Acres Treated", "Pct Area Treated", "Pct Change 2002-2007"]; for (var col in gridColumns) { fieldNames.push(col); } var lastCol = fieldNames.length -1; var lastField = fieldNames[lastCol]; dataArray.push(fieldHeaders.toString()+ " \n"); // dataArray.push(fieldNames.toString()+ " \n"); var gridStore = gridData.store; //steps through each record, pushes the values into an array that is formatted for CSV compatibility for (var i = 0; i < gridLength; i++) { var gridRow = gridStore.data; arrayUtils.forEach(fieldNames, function(fieldName){ fieldValue = gridRow[fieldName]; var stringValue = String(fieldValue); if (stringValue.indexOf(",") > 0) { //removes any commas from data stringValue = stringValue.replace(/,/g, " "); } if (stringValue.indexOf('\'') != -1 || stringValue.indexOf('\"') != -1) { //removes any slashes from data // console.log ("Data has a slash in it. Not sure of this section of the code!"); if (stringValue.indexOf('\"') != -1) { stringValue = stringValue.replace("\"", "\"\""); } stringValue = "\"" + stringValue + "\""; } if (fieldName == lastField) { dataArray.push(stringValue + " \n");//adds a new line when value is from the last field } else { dataArray.push(stringValue);//otherwise just adds the value } }); }//one row pushed to array var data = dataArray.join(); var inputData = data.replace(/\n,/g, "\n");//some clean up to get rid of the leading commas in the data submitCSVprint(gridData.id, inputData); } else { //nothing to save alert ("Error saving data."); } } This is working well, except that I still want the data sorted on my NAME field and now it's not. The sorting I performed early was on the grid, not on the underlying Memory. My question is, how do I sort the Memory instead so the CSV output matches what the user sees in the grid?
... View more
07-02-2014
01:46 PM
|
0
|
5
|
7340
|
|
POST
|
I have a generateRendererTask and generateRendererParameters defined and I want to be able to format my labels to only have 2 decimal places.
function generateClassBreaks(c1, c2) {
var classDef = new ClassBreaksDefinition();
classDef.classificationField = classBreakField;
classDef.classificationMethod = "quantile";
classDef.breakCount = interval; //defined as 5
var colorRamp = new AlgorithmicColorRamp();
colorRamp.fromColor = new Color.fromHex(c1);
colorRamp.toColor = new Color.fromHex(c2);
colorRamp.algorithm = "hsv"; // options are: "cie-lab", "hsv", "lab-lch"
classDef.baseSymbol = new SimpleFillSymbol("solid", null, null);
classDef.baseSymbol = defaultSymbol;
classDef.colorRamp = colorRamp;
var params = new GenerateRendererParameters();
params.classificationDefinition = classDef;
params.precision = 2;
params.formatLabel = true;
var clauseInput = classDef.classificationField;
params.where= clauseInput + " > 0";
var generateRenderer = new GenerateRendererTask(myLayer.url+"/0");
generateRenderer.on("error", taskErrorHandler);
generateRenderer.execute(params, applyRenderer);
}
This is then used to generate my legend. In my legend, the values are not rounded to two decimal places like I expected. Instead they round to a whole number. They're this way because that's how the label got generated from the generateRendererTask. I have worked around this by creating my own labels using the minValue and maxValue for each class, but I don't feel like I should have had to do this. I read in the API reference that precision is only for ClassBreakRenderers, but it seems like should be inclusive of the tools that let you generate those renderers dynamically. This seems like a bug to me. I didn't get an error defining a precision parameter, just this unintended format. Has anyone else had a similar experience?
... View more
07-02-2014
11:48 AM
|
0
|
8
|
4781
|
|
POST
|
Sorry I misread your question. I thought you were asking about dynamically generating symbology for a selected layer. My instructions were for that.
... View more
07-02-2014
08:42 AM
|
0
|
0
|
2104
|
|
POST
|
When I was trying to create some charts, I found these sites to be useful: http://www.ibm.com/developerworks/library/wa-moredojocharts/ http://www.sitepen.com/blog/2012/11/09/a-beginners-guide-to-dojo-charting-with-amd-part-1-of-2/#more-5407 http://www.sitepen.com/blog/2012/11/09/dive-into-dojo-charting-again/
... View more
07-02-2014
08:38 AM
|
2
|
1
|
1730
|
|
POST
|
I have been working through the sample https://developers.arcgis.com/javascript/jssamples/renderer_dynamic_layer_change_attribute.html which allows the user to select a field from the specified service and generate a classification based on that field. It is based on a ArcGISDynamicMapServiceLayer. In order to activate the 'dynamic layers' functionality you have create a geodatabase or shape file workspace and author that as a geodata service Check the box under Capabilities > Mapping in Properties to "Allow per request modification ..." click "Manage" to browse the the geodata service you just made. The geodata service is just a temporary workspace, near as I can tell. It doesn't have anything in it. In my data, I have some values of -999 which indicates 'No data'. I didn't want these to be included when I generated my renderer, so I needed a where clause. In the sample, the function classBreaks is where the GenerateRendererParameters is defined. I added a where clause, shown in red, which takes the field the user selected and excludes the -999 data so it doesn't get used when I generate the renderer. I also needed to round my numbers, since some have too many decimals. It seems to be working just fine. I still need to figure out if you can symbolize this excluded data, with maybe a gray color or something.
function classBreaks(c1, c2) {
var classDef = new ClassBreaksDefinition();
classDef.classificationField = registry.byId("fieldNames").get("value") || "CROP_2002_ACRES_TREATED";//this is a field in my data
classDef.classificationMethod = "natural-breaks";
classDef.breakCount = 5; // always five classes
var colorRamp = new AlgorithmicColorRamp();
colorRamp.fromColor = new Color.fromHex(c1);
colorRamp.toColor = new Color.fromHex(c2);
colorRamp.algorithm = "hsv"; // options are: "cie-lab", "hsv", "lab-lch"
classDef.baseSymbol = new SimpleFillSymbol("solid", null, null);
classDef.colorRamp = colorRamp;
var params = new GenerateRendererParameters();
params.classificationDefinition = classDef;
params.precision = 2;
params.formatLabel = true;
var clauseInput = classDef.classificationField;
params.where= clauseInput + " > 0";
var generateRenderer = new GenerateRendererTask(app.dataUrl);
generateRenderer.execute(params, applyRenderer, errorHandler);
}
I just happened to be working on this for the first time this AM, so I don't know much more than "I got it to work". You must have ArcGIS Server version 10.1 or higher to use this.
... View more
07-01-2014
07:14 AM
|
0
|
0
|
2104
|
|
POST
|
I'm glad you got it straightened out. There are queryTask examples that show both methods, but I don't think the documentation is clear at all that you were getting different objects returned, depending on which you go with.
... View more
06-30-2014
05:21 AM
|
0
|
0
|
537
|
|
POST
|
If you're going to remove the queryTask.on ('complete', handlerFunction), and stick with queryTask.execute(query, handlerFunction) then you want to leave your showResults function as function showResults(featureSet){ var features = featureSet.features; If you want to want to go with queryTask.execute(query, handlerFunction); That's where you'd have your results function as function showResults (results) { var features = results. featureSet.features; I also think your for statement looks a little weird. Maybe it should be for (var i=0; i<features.length; i++){
... View more
06-27-2014
01:43 PM
|
0
|
0
|
6891
|
|
POST
|
You shouldn't combine a queryTask.on('complete', showResults) with a queryTask.execute(query, function ....). You have already specified your results handler, putting something different in the execute line just confuses things. Also, if you execute with a listener on the 'complete' event, I believe the resultant output is generically 'results' and not a featureSet. You end up having to change your code up slightly to get to the featureSet, something like
function showResults(results) {
var features = results.featureSet.features
....
Pay attention to what is really getting returned from your query handler, I don't think it's a featureSet.
... View more
06-27-2014
01:30 PM
|
0
|
0
|
3377
|
|
POST
|
I have a map that accepts an incoming parameter and based on the value, loads a particular data layer, sets the title etc. I need to handle the possibility of no incoming argument, presenting the user with a pick list comparable to the values of the incoming parameter. I will always have a county boundary layer, so I have a load event on the county layer, which checks to see if there is a parameter on the URL. It will either load additional data or open the floating pane of category choices if there is no parameter provided. My problem is that the floating pane loads first, and ends up under my map instead of on top of it. I've tried setting the z-index to 999 for my floating pane, but that didn't help. I feel like I'm missing something obvious, but I haven't spotted it yet.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Sample - Floating Pane if no URL parameter</title>
<link type="text/css" rel="stylesheet" href="https://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.9/js/esri/dijit/css/Popup.css">
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.9/js/dojo/dojox/layout/resources/FloatingPane.css">
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.9/js/dojo/dojox/layout/resources/ResizeHandle.css">
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.9/js/esri/css/esri.css" >
<link type="text/css" rel="stylesheet" href="css/style.css">
<script type="text/javascript">
var dojoConfig = {
parseOnLoad: false,
async:true
};
</script>
<script type="text/javascript" src="https://js.arcgis.com/3.9compact/"></script>
<script type="text/javascript">
var pathName = "https://ogitest.oa.mo.gov";
var map, countyLayer, NCDM, ncdmLayer;
require(["dojo/parser", "esri/map", "esri/domUtils","esri/urlUtils",
"dojo/dom", "dijit/registry", "dojo/on", "dojo/dom-construct", "dojo/query",
"esri/layers/FeatureLayer", "esri/layers/ArcGISDynamicMapServiceLayer",
"esri/renderers/SimpleRenderer", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
"esri/graphic", "dojo/_base/Color", "dojo/_base/array","dojo/aspect",
"dijit/form/Form", "dijit/form/RadioButton", "dijit/form/Button","dijit/form/TextBox",
"dijit/form/Select", "dijit/TitlePane", "dijit/layout/BorderContainer",
"dojox/layout/FloatingPane","dojox/layout/Dock",
"dojo/domReady!"],
function(parser, Map, domUtils, urlUtils, dom, registry, on, domConstruct, query,
FeatureLayer, ArcGISDynamicMapServiceLayer,SimpleRenderer, SimpleLineSymbol, SimpleFillSymbol, Graphic, Color,
arrayUtils, aspect){
parser.parse();
var countyFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([149,149,149]), 2));
map = new Map("mapDiv", {
basemap: "topo",
center: [-92.593, 38.5],
zoom: 7
});
countyLayer = new FeatureLayer(pathName + "/ArcGIS/rest/services/BaseMap/county_simple/MapServer/0", {
id: "countyLayer",
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["COUNTYNAME"]
});
countyRenderer = new SimpleRenderer(countyFillSymbol);
countyLayer.on('load', checkURL);//checks for NCDM in URL, loads data based on parameter provided
map.addLayers([countyLayer]);
//load this category specified in the incoming URL parameter
function loadData(ncdm){
var ncdmPath, layerName;
cleanUpLayers();
switch (ncdm) {
case "AMI":
ncdmPath = pathName + "/ArcGIS/rest/services/DHSS/EPHT_ami_county/MapServer";
layerName = "AMILayer";
break;
case "CO":
ncdmPath = pathName + "/ArcGIS/rest/services/DHSS/EPHT_carbon_county/MapServer";
layerName = "COLayer";
break;
}
ncdmLayer = new ArcGISDynamicMapServiceLayer(ncdmPath, {
id: layerName,
opacity: '0.7'
});
map.addLayers([ncdmLayer]);
}
function cleanUpLayers(){
var layers = map.getLayersVisibleAtScale(map.getScale());
arrayUtils.forEach(layers, function(layer){
if (layer.id !== 'layer0' && layer.id !== 'countyLayer') {
map.removeLayer(layer);
}
});
}
//get the URL parameter, either load the data or if there isn't a parameter, open the floating pane
function checkURL(){
NCDM = getNCDMFromUrl(document.location.href);
if (!NCDM) {
openFloatingPane('floater_pick');
} else {
loadData(NCDM);
}
}
function getNCDMFromUrl(url){ //extracts the parameter from the url
var urlObject = urlUtils.urlToObject(url);
if (urlObject.query && urlObject.query.ncdm) {
return urlObject.query.ncdm;
} else {
return null;
}
}
//functions for managing floating panes
function openFloatingPane(paneId){
var fp = registry.byId(paneId);
if ((fp.style == "visibility: hidden;") || (fp.style = "VISIBILITY:hidden;")) {
fp.style.visibility = "visible";
fp.show();
}
}
});
</script>
</head>
<body class="claro">
<div id='mainWindow' data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false"
style="width:100%;height:100%;margin:0;">
<div id="mapDiv" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center',gutters:'false'">
<div id="dock_pick" data-dojo-type="dojox/layout/Dock" ></div>
<div id="floater_pick" data-dojo-type="dojox/layout/FloatingPane"
data-dojo-props= "title:'Choose a category', dockTo:'dock_pick', closable:false, resizable:true, dockable:true"
style="visibility:hidden;" >
<div id="pickDiv" >
category picking goes here
</div>
</div>
</div>
</div>
</body>
</html>
css:
#floater_pick{
z-index: 999;
top:80px;
left: 80px;
width: 100px;
height: 100px;
}
... View more
06-27-2014
09:12 AM
|
0
|
3
|
4328
|
|
POST
|
I've been having strange Firefox behavior this week, so this morning I decided to trace down the problem I was having (Firefox thought it had an instance already running when I come in in the mornings. I didn't.). Through tracking down that problem, I followed steps to reset Firefox. This turned out to be a bad idea, but as a consequence, I noticed that I too was seeing a problem with my code not even getting into the lines for dojo.require before it bombed. Not only that, but my security certificates files Firefox uses wouldn't let me add Firebug back in again. Like I said 'Bad idea'. I dug the certificates out of the backup I had and put them in my new profile. Lo and behold, I could get my Firebug added back in, but also my dojo.require was OK again. If the internal help person who deals with the certificates for the web browsers gets back with me, maybe we'll get to the bottom of this and I'll post our findings.
... View more
06-26-2014
11:25 AM
|
0
|
0
|
1666
|
|
POST
|
This was the return from an IdentifyTask, so I added the suggested line into my result handler:
feature.geometry.spatialReference = map.spatialReference;
... View more
06-26-2014
08:44 AM
|
0
|
0
|
1186
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-02-2017 02:38 PM | |
| 2 | 03-18-2022 10:14 AM | |
| 2 | 02-18-2016 06:28 AM | |
| 1 | 03-18-2024 07:29 AM | |
| 4 | 08-02-2023 06:08 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-25-2025
01:56 PM
|