|
POST
|
It's the code you posted that had codeList as a local variable. There's enough posts here they are a little out of sequence. I was replying to comments at the same time other people were posting. I do have two different codeLists stored under "app". I'm not sure these are going to be available in all the places I need them, though. I need to work a little further and see.
... View more
08-11-2015
08:11 AM
|
0
|
7
|
2347
|
|
POST
|
That didn't do it. And I'm mistaken, they aren't both populated with the values of the first pass, they're both populated with the values from the 2nd time I called it.
... View more
08-11-2015
07:56 AM
|
0
|
9
|
2347
|
|
POST
|
I added an app variable and passing it to myMap.js. This lets me do this with my codeLists: myPopulateCodeList.populateCode('spec', specUrl).then(function (codeList) { app.specCodeList = codeList; console.log(codeList); }, function (err) { console.error(err); }); myPopulateCodeList.populateCode('prov', provUrl).then(function (codeList) { app.provCodeList = codeList; console.log(codeList); }, function (err) { console.error(err); }); }); I have two objects in app, but when I look at them more closely, they contain the exact same thing - the values from the first table I processed.
... View more
08-11-2015
07:42 AM
|
0
|
2
|
2347
|
|
POST
|
Maybe I need to also incorporate the idea that Steve brought up. I need these codeList to continue to be available throughout the application. I'm actually using them as a lookup table, so every time I create a grid or info tag, I need them to look up what the description is to go with the code. In my index.html I have defined var app = {}; I guess I need to continue to make this available to my other .js files by passing it as a parameter?
... View more
08-11-2015
07:31 AM
|
0
|
1
|
2947
|
|
POST
|
I can definitely see that I need to handle this is in a my async manner. The calling script myMap.js is getting to the console.log ('UR here') way before it finishes the results of the queryTask. I should mention the external table is a DB2 business table, nothing in geodatabase format, and I always operate under the assumption it's going to take longer to process any query. Listing myPopulateCodeList.codeList in the console log displays an empty array. I should also mention for anyone who wants to use this code for themselves that the queryTask results must be referenced as results.features, not results.featureSet.features. In my original posting, I had a separate results handler. When you call a separate results handler, that's when you need to results.featureSet.features to get to the individual features.
... View more
08-11-2015
06:50 AM
|
0
|
1
|
2947
|
|
POST
|
I'm trying not to have too many global variables, because once I have this code broken up, I know I'll have problems keeping track of where I'm settnig them. I have two tables I need to process, and both arrays needs to be persistent. I have a field for specialty code and a field for provider type and each has a corresponding lookup table. Since that's the case, I can't just re-use codeList. I need something like specCodeList and providerCodeList. Technically you don't have to have your code divided into modules to use AMD syntax. I switched from legacy to AMD a couple years ago. When I did it, though, I left it all in one file the same as I had it before. My projects aren't generally very big, so I felt OK about leaving that at that state. The project I have now is working just great, but it is now 1200 lines long and I'm tired of scrolling. Even if I've not fully embraced AMD, if I could get it into manageable chunks, I'd be better off.
... View more
08-11-2015
06:31 AM
|
0
|
0
|
2947
|
|
POST
|
I would expect the 'mo' that is returned to be the codeList array, but when I call it from myMap.js as var specCodeList = myPopulateCodeList.populateCode('spec',specUrl); it is still undefined.
... View more
08-11-2015
06:22 AM
|
0
|
4
|
2947
|
|
POST
|
I have two external tables that contain an ID and a description. They are the basis for a set of menus, and since they are very similar in their schema, I'm attempting to create one tool for creating an array of code and description pairs. In addition, I'm using this as a learning tool for defining modules and it's not going so well. These these will eventually be input for menus, as well as look These are two different tables and the field names are not identical, so I need to account for that as well. In my Map module, myMap.js, I have defined this variable, which is a table I have loaded as a featureLayer, along with several other layers. var specUrl = specialtyTable.url; added a listener for the map load event: myPopulateCodeList.populateCode('spec',specUrl); The function populateCode is getting called, but I need to keep the codeList array as a variable, because I'll use it again in more than one place. myPopulateCodeList.js define([
"dojo/on",
"esri/tasks/QueryTask",
"esri/tasks/query"
], function(
on,QueryTask, Query){
var codeList = [];
return {
populateCode: function(codeType, url){
switch (codeType) {
case "spec":
codeAtt = 'ID_SPECIALTY_PK';
specAtt = 'TX_SPECIALTY_DESC';
break;
default:
codeAtt = 'ID_PROV_TYPE_PK';
specAtt = 'TX_PROV_DESC';
break;
}
var queryTask = new QueryTask(url);
var query = new Query();
query.outFields = ["*"];
query.where = "1=1";
query.returnGeometry = false;
on(queryTask, 'complete', this.codeResultsHandler);
on(queryTask, 'error', this.errorHandler);
queryTask.execute(query);
},
//builds codeList object containing codes and descriptions
codeResultsHandler: function(results){
var numResults = results.featureSet.features.length;
for (var j = 0; j < numResults; j++) {
var code = results.featureSet.features .attributes[codeAtt];
var desc = results.featureSet.features .attributes[specAtt];
codeList.push({
code: code,
desc: desc
});
}
console.log('end of codeList array build');
return codeList;
},
errorHandler: function(err){
console.log("error in myPopulateCodeList, error: " + err.details);
}
}
return codeList;
}); I can see that codeList is getting populated with values from the results handler of the queryTask, but I can't figure out how to pass this result back to the calling function. This doesn't work: var specCodeList = myPopulateCodeList.populateCode('spec',specUrl); When I had it all in one big file, this was working, but I'm trying to learn how to break my work up into smaller bits.
... View more
08-10-2015
02:29 PM
|
0
|
26
|
9951
|
|
POST
|
I wasn't even thinking that the graphic would know what map it came from. I was making it too complicated.
... View more
08-10-2015
06:22 AM
|
0
|
0
|
1716
|
|
POST
|
How? Defining the infoContent of an infoTemplate with a function automatically passes 'graphic' as a parameter, it's not something I'm doing . If I add in 'map' as a 2nd parameter it just fails. No errors, the page just doesn't load.
... View more
08-07-2015
02:41 PM
|
0
|
1
|
1716
|
|
POST
|
I have a complicated definition for infoTemplate content which I'm populating with a function. Because I'm using bootstrap-map, there's some issue with the 'Zoom to' not getting applied in the footer the way you'd expect. I've managed this with code, but now I'm attempting to split this functionality out into it's own myinfoTemplate.js file. ( I'm attempting to break free of my spaghetti code habits.) define ([
"dojo/dom-construct",
"dojo/on",
"dojo/dom",
"dojo/query",
] , function (domConstruct,on,dom,query) {
return {
generateInfoContent: function(graphic){
var currentGraphic = graphic;
var formatString = "";
var addrTest = graphic.attributes.AD_LINE1;
var addr2Test = graphic.attributes.AD_LINE2;
var provCode = graphic.attributes.ID_PROV_TYPE_FK;
var specCode = graphic.attributes.ID_SPECIALTY_FK;
var locTest = graphic.attributes.LOC_CODE.substring(0, 1);
var phoneTest = phoneFormatter(graphic.attributes.PH_NUMBER);
formatString = "<b>" + graphic.attributes.NA_PROVIDER + "</b>";
if (addrTest.length > 1) {
formatString += "<br>" + addrTest;
}
if (addr2Test.length > 1) {
formatString += "<br>" + addr2Test;
}
formatString += "<br>" + graphic.attributes.AD_CITY + ", " + graphic.attributes.AD_STATE + " " + graphic.attributes.AD_ZIP_CODE +
"<br>" //+ phoneTest;
if (locTest) {
formatString = formatString + "</br> ** Location Approximate ** ";
}
//popup from bootstrap doesn't display Zoom To link, so add it here
if (!dom.byId('zoomLink')) {
var link = domConstruct.create("a", {
"class": "action zoomTo myZoom",
"id": "zoomLink",
"title": "My Zoom",
"innerHTML": "Zoom To", //text that appears in the popup for the link
"href": "javascript: void(0);"
}, query(".sizer", map.infoWindow.domNode)[1]); //fails on this line, cannot read property 'infoWindow' of undefined
on(link, "click", this.zoomTo);
//dom.byId('toMessage').innerHTML = "Address for: " + graphic.attributes.NA_PROVIDER;
//formats phone number to contain () and dash - used by setInfoContent and queryHandler_populateProviders
function phoneFormatter(input){
var area = input.substr(0, 3);
var pre = input.substr(3, 3);
var suf = input.substr(6, 4);
return "(" + area + ") " + pre + "-" + suf;
}
function zoomTo(){
var geom = currentGraphic.geometry;
var lod = map.getLevel();
if (lod < 8) {
map.centerAndZoom(geom, 8);
}
else {
map.centerAndZoom(geom, lod + 1);
}
map.infoWindow.setFeatures(currentGraphic);
map.infoWindow.show(currentGraphic.geometry);
}
return formatString;
}
}
}); Now that's it's separate, it gets hung up on }, query(".sizer", this.map.infoWindow.domNode)[1]);. How do I tell it what 'map' is? I'm calling this from my map.js file as var infoTemplate = new InfoTemplate();
infoTemplate.setTitle("Site Information");
infoTemplate.setContent(myInfoTemplate.generateInfoContent); This all works when I comment out the lines that deal with the link. But I need that part!
... View more
08-07-2015
01:36 PM
|
0
|
5
|
4597
|
|
BLOG
|
I have to agree with Evelyn. Technically, my code uses AMD. But it's all still in one big file, because I can't figure out how to separate it out. Every person who posts about AMD and modules. provides the same few links - to ESRI and to DOJO documentation. I have read all of these dozens of times, but I just don't get how it applies to my work. I get the core concepts, but applying it to my existing code is a completely different story.
... View more
08-06-2015
11:30 AM
|
2
|
0
|
1100
|
|
POST
|
When I've set these up, I've had to use a path like "http://oursite.mo.gov", not the server name.
... View more
08-05-2015
02:27 PM
|
1
|
1
|
5032
|
|
POST
|
Would there be a way to somehow define 'element'? When you look at it, it's always the same format: element: div#gridDiv-row-1641.dgrid-row.dgrid-row-even.ui-state-default Where 1641 corresponds to the OBJECTID. I know I'm just making stuff up. Maybe there is something different I can use in the original construction of the grid?
... View more
08-04-2015
02:13 PM
|
0
|
0
|
2072
|
|
POST
|
I don't feel like this is a large data set, and it's just a sample I had small enough to easily pull together. My final project has many more records (39K), so it must be a solution that works with a larger data set. Your solution of scrollIntoView works some of the time anyway.
... View more
08-04-2015
01:44 PM
|
0
|
0
|
2072
|
| 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
|