|
POST
|
Has anyone found or written a function to take a featureSet and sort it based on a specified attribute? The only way I can think of right now would be to: create a dojo dGrid via code provide the featureSet as it's store sort the dGrid based on the appropriate column create a new featureSet based on the sorted store Thanks- Steve
... View more
10-10-2012
07:07 AM
|
0
|
5
|
3071
|
|
POST
|
Many thanks to everyone's input in this thread. Getting this to work has been one of the toughest challenges for me since I started working with the javascript API. I do have things finally working but I did have to rethink my entire process. As several people pointed out, the callback routines were critical so I re-wrote my code to be less linear and more "modular." I had resisted this because of another constraint (this whole process will update an HTML template opened via an onClick event) but I did find a way. So to recap my solution... My button's onClick event starts everything by calling this function: function getProjectReport2(param) {
var theParam = param.split(",");
var theShape;
var query = new esri.tasks.Query();
query.where = "FID=" + theParam[0];
query.outFields = ["*"];
query.returnGeometry = true;
//Specify the appropriate point/line map service depending on what was clicked
switch (theParam[1]) {
case "point":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");
break;
case "polyline":
var queryTask = new esri.tasks.QueryTask("URL to Map Servce");
break;
}
//The new browser window must be opened in the function called by the 'onClick' event so
//the new window is created here and its associated variable is created with a global scope.
//Calculate the center of the screen for placement of the new window
var center_left = (screen.width / 2) - (1000 / 2);
var center_top = (screen.height / 2) - (600 / 2);
newWindow = window.open('','mywindow','width=1000,height=600,menubar=yes,scrollbars=yes,left=' + center_left + ',top=' + center_top);
var dQuery = queryTask.execute(query,createDeferredResults);
} ...which then passes the feature onto a separate callback function. I decided to use a deferredList as Kelly had suggested: function createDeferredResults(featureSet) {
var dTractRace, dTractIncome, dTractLep;
dojo.forEach(featureSet.features, function(feature) {
theTipProject = feature;
});
var query = new esri.tasks.Query();
query.outFields = ["*"];
query.returnGeometry = true;
query.geometry = theTipProject.geometry;
qTractRace = new esri.tasks.QueryTask("URL Service #1");
qTractIncome = new esri.tasks.QueryTask("URL Service #2");
qTractLep = new esri.tasks.QueryTask("URL Service #3");
dTractRace = qTractRace.execute(query);
dTractIncome = qTractIncome.execute(query);
dTractLep = qTractLep.execute(query);
defQuery = new dojo.DeferredList([dTractRace,dTractIncome,dTractLep]);
defQuery.then(handleCensusResults);
} Finally, another callback function where I finally get down to the task of updating my HTML template: function handleCensusResults(results) {
var raceResults, incomeResults, lepResults;
raceResults = results[0][1].features;
incomeResults = results[1][1].features;
lepResults = results[2][1].features;
.
.
.
processRaceResults(raceResults);
} Once again, thank you ALL for helping me! Cheers, Steve
... View more
10-08-2012
07:06 AM
|
0
|
0
|
223
|
|
POST
|
Ok, my apologies. The light bulb went off with Wyatt's description as to what's happening. So my problem is waiting until the callback finishes and it sounds like the deferredList that Kelly was suggesting might be the way to do this? Here's my attempt to incorporate deferredList- function getProjectReport(theFid) {
var theDocument, theGraphic
theGraphic = returnTipShape(theFid);
console.log(theGraphic.attributes.PROJECT);
.
.
.
}
function returnTipShape(param) {
var theParam = param.split(",");
var query = new esri.tasks.Query();
query.where = "FID=" + theParam[0];
query.outFields = ["*"];
query.returnGeometry = true;
var theShape;
//Specify the appropriate point/line map service depending on what was clicked
switch (theParam[1]) {
case "point":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsPoint/MapServer/0");
break;
case "polyline":
var queryTask = new esri.tasks.QueryTask("http://dmc-arcgis.snoco.co.snohomish.wa.us/SnocoGISdev/rest/services/transportation/tipProjectsLine/MapServer/0");
break;
}
dQuery = queryTask.execute(query);
var dList = new dojo.DeferredList([dQuery]);
dList.then(function(results) {
var featureSet = results[0];
dojo.forEach(featureSet.features, function(feature) {
theShape = feature;
});
});
return theShape;
}
I thought that if I put the queryTask and deferredList calls into a function, that would isolate the process until it finishes. Of course, I get the same error so it looks like I've just moved the same issue around.
... View more
10-04-2012
08:23 AM
|
0
|
0
|
1239
|
|
POST
|
Yes- I understand what Bill (and you) are saying. What I'm not doing a good job of saying is that I want/need to access theGraphic variable AFTER the conclusion of the queryTask.Execute routine. I need to re-use the geometry and some of it's attributes for subsequent queries on additional datasets. As my code currently exists, I can't- and I don't know what to change to get it to behave in the manner I need. I thought by declaring theGraphic as a variable at the beginning of the function it would persist and be accessible throughout the entire function but it's not (or I'm using it wrong).
... View more
10-03-2012
01:41 PM
|
0
|
0
|
1239
|
|
POST
|
Hi Bill, There is only one item return via the query so that part is fine. The reason I included the console.log code line outside of the loop was to reinforce the point that my variable is not persisting beyond the scope of the forEach loop. This is something I want it to do.
... View more
10-03-2012
12:57 PM
|
0
|
0
|
1239
|
|
POST
|
This is probably pretty easy but I can't seem to get what I'm doing wrong. I have a function, kicked off via a button click, that queries a particular layer, and then does some additional queries & data retrieval against three other layers. Basically, I have one location and I want to extract information from three other datasets that overlap its spatial extent. Anyways, what I've tried to do is an initial query to my layer which has my spatial location (using an FID which I pass to the function). Once I query that layer, I was to "save" the feature to a variable so I can quickly use it in my subsequent queryTask calls. Here's my simple code: function getProjectReport(theFid) { var theParam = theFid.split(","); var query = new esri.tasks.Query(); query.where = "FID=" + theParam[0]; query.outFields = ["*"]; query.returnGeometry = true; var theGraphic; //Specify the appropriate point/line map service depending on what was clicked switch (theParam[1]) { case "point": var queryTask = new esri.tasks.QueryTask("URL #1"); break; case "polyline": var queryTask = new esri.tasks.QueryTask("URL #2"); break; } queryTask.execute(query,function(featureSet) { dojo.forEach(featureSet.features, function(feature) { theGraphic = feature; }); }); console.log(theGraphic.attributes.PROJECT); } Now, the queryTask finds my record but when it gets to my "console.log" line, it errors out and tells me that my variable theGraphic is undefined. I've defined my variable at the beginning of my function so why doesn't my assignment persist after the end ofmy forEach loop? How do I fix this so I can re-use theGraphic later on in my function? Thanks again! Steve
... View more
10-03-2012
12:10 PM
|
0
|
10
|
1935
|
|
POST
|
I decided to re-publish my service with the standalone table tucked inside it. Just seems like the easiest way to do it. Thanks again for the ideas! Steve
... View more
10-02-2012
06:57 AM
|
0
|
1
|
2639
|
|
POST
|
John/Mike, Thanks for responding. My table is located in a FileGeoDatabase so I can certainly publish it via ArcGIS Server. How do I publish JUST the table in ArcGIS Server? I tried adding the table to a blank MXD and publishing the MXD but the table isn't listed in the published service. Worst comes to worse, I could add the table into another existing map service and then access it through that service but I'd like to know how to publish a stand alone table.
... View more
10-01-2012
10:55 AM
|
0
|
0
|
2639
|
|
POST
|
I'm looking for some guidance on how to proceed with a certain task I'd like to implement which would use a standalone table. My app works with Census data and so once the user clicks on a cenus tract, I'd like to load up some additional information (based on the census tract number) which is stored in a separate, stand alone table. That's what I want to do- now how do I do that? After reviewing the API, I'm not sure how you "add" the table as a layer so that you can query it. The table will have a one to many relationship so I can't just join the table to my census tracts feature layer before serving it up as a service. Thanks! Steve
... View more
09-28-2012
08:06 AM
|
0
|
8
|
12449
|
|
POST
|
Derek, Unfortunately, the feature layers being used in my map are services on our developmental server so any full code post wouldn't work for you. The good news is that I have got it working. The short story is that I believe the javascript code was fine and I was just missing a parameter on the HTML side of things. I changed my design from a dojo combo box to a dojo FilteringSelect. After making the change, it still didn't work. After some head scratching, I modified my HTML Input tag to read <input id="cboTipList" dojoType="dijit.form.FilteringSelect" searchAttr="PROJNAME" name="WidgetName" pageSize="12" placeHolder="Select A TIP Project" onChange="zoomRow(dijit.byId('cboTipList').value);"> and it *finally* worked. The key seems to be the "searchAttr" option, which I was originally missing. Whew!
... View more
09-24-2012
01:26 PM
|
0
|
0
|
643
|
|
POST
|
I would second Steve's suggestion about tying the popup to a feature layer. For example, in one of my maps, I define the popup content at the beginning of my initMap() function like this: var removalTemplate = new esri.InfoTemplate();
removalTemplate.setContent('<table cellspacing=\"5\" style=\"font-size:90%\"><tr><td style=\"vertical-align:top\"><b>Road Name:</b></td><td style=\"vertical-align:top\">${Name}</td></tr><tr><td style=\"vertical-align:top\"><b>Snow Removal Priority:</b></td><td style=\"vertical-align:top\">${Priority:formatPriorityLabel}</td></tr></table>');
removalTemplate.setTitle('${Name}'); Next, you specify the template when you create the feature layer: // Define the Snow Removal Route layer
theSnowRemovalLayer = new esri.layers.FeatureLayer("URL to feature layer", {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
infoTemplate:removalTemplate,
outFields: ["*"],
opacity:0.80,
visible: false
}); Towards the end, but still within the initMap() function, I associate the popup with the specific feature layer: dojo.connect(theSnowRemovalLayer,"onClick",function(evt){
//Listener event for feature selection and the popup info widow
var query = new esri.tasks.Query();
query.geometry = pointToExtent(map,evt.mapPoint,15);
var deferred = theSnowRemovalLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
map.infoWindow.resize(map.width * 0.55,map.height * 0.25);
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(evt.mapPoint);
}); Hopefully that makes sense. Good luck! Steve
... View more
09-24-2012
07:51 AM
|
0
|
0
|
584
|
|
POST
|
Hi Derek, I've tried that line as well with no luck. I should have mentioned that I'm specifying v2.8 of the API since I'm doing the initial development locally and not on a server. This hasn't been a problem with a dojo datagrid so I assumed it wouldn't be a problem with the combo box..
... View more
09-24-2012
07:35 AM
|
0
|
0
|
643
|
|
POST
|
In a web map I'm developing, I want a combo box populated with project names and FID so that once the user selects a project, I can zoom to that project's feature extent. Within my Init() function, I'm using a query task like this: //Push the attributes of the TIP Projects into the combo box
var query = new esri.tasks.Query();
query.where = "1=1";
query.outFields = ["*"];
var queryTask = new esri.tasks.QueryTask("my feature layer URL");
queryTask.execute(query,populateCbo); Later down the line, my function "populateCbo" attempts to populate the combo box: function populateCbo(results) {
//Populate the dropdown list box with unique values
var values = [];
var features = results.features;
dojo.forEach (features, function(feature) {
curProject = feature.attributes.PROJECT;
curFid = feature.attributes.FID;
values.push({'project':curProject,'fid':curFid});
});
//Sort the values list by project name
//values.sort(by('project'));
var dataItems = {
identifier: 'fid',
label: 'project',
items: values
};
var store = new dojo.data.ItemFileReadStore({data:dataItems});
dijit.byId("cboTipList").store = store;
} Everything seems to work just fine until the line which populates the store variable. The dataItems variable has information in it but after stepping through the "store = .." line, the data property for store is still null. Am I not formatting the contents of dataItems properly? I'm not sure why it's not getting populated. Thanks! Steve
... View more
09-24-2012
07:11 AM
|
0
|
4
|
1012
|
|
POST
|
Awesome. Thanks, Rich! Your suggestion finally makes it work. Marked as answered. Thanks again! Steve
... View more
08-30-2012
07:40 AM
|
0
|
0
|
1363
|
|
POST
|
Hi Rich, I tried adding another dojo connect on the mapPanel but it did not solve the issue: dojo.connect(dijit.byId('mapPanel'), 'resize', function(map) {
map.resize;
});
... View more
08-30-2012
07:20 AM
|
0
|
0
|
1363
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 2 | 11-13-2025 07:55 AM | |
| 1 | 09-11-2025 10:18 AM | |
| 1 | 09-11-2025 08:03 AM | |
| 1 | 08-13-2025 09:16 AM |