|
POST
|
Yes seems like your getting a reference to myPopulateCodeList.codeList. If your going to store those codeLists in the global scope then I would recommend modifying the module a little so codeList is not a property of myPopulateCodeList to prevent issues like this. Here is an example of the original sample I posted with some changes to make codeList not a property of myPopulateCodeList module. define([
"dojo/on",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dojo/_base/lang",
"dojo/Deferred"
], function(
on, QueryTask, Query, lang, Deferred){
var mo = {
//codeList: [], We don't want this as a property here, it should be a local variable in function below
populateCode: function(codeType, url){
var codeAtt, specAtt, codeList = []; // Added local codeList here
var deferred = new Deferred();
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;
queryTask.execute(query, lang.hitch(this,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];
// push to the local codeList and not this.codeList
codeList.push({
code: code,
desc: desc
});
}
console.log("end of codeList array build");
deferred.resolve(codeList);
}), function(err){
console.log("error in myPopulateCodeList, error: " + err.details);
deferred.reject(err);
});
return deferred;
}
};
return mo;
}); What was happening was that when you called the populateCode function, it was updating the myPopulateCodeList.codeList property. So when you call populateCode function it just updates the same property no matter what you pass into it. Doing it this way returns a new codeList each time and then you can append it to your global codeLists
... View more
08-11-2015
07:56 AM
|
0
|
0
|
2738
|
|
POST
|
Ok, sounds like you may want to step through the callback to the query task as that may not be populating your codeList array, if it is, then you will want to figure out the best way for you to return it or return a signal that the query task is complete and the data is available.
... View more
08-11-2015
07:02 AM
|
0
|
0
|
1130
|
|
POST
|
Here is an example of Robert Scheitlin, GISP code but with deferred in it define([
"dojo/on",
"esri/tasks/QueryTask",
"esri/tasks/query",
"dojo/_base/lang",
"dojo/Deferred"
], function(
on, QueryTask, Query, lang, Deferred){
var mo = {
codeList: [],
populateCode: function(codeType, url){
var codeAtt, specAtt;
var deferred = new Deferred();
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;
queryTask.execute(query, lang.hitch(this,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];
this.codeList.push({
code: code,
desc: desc
});
}
console.log("end of codeList array build");
deferred.resolve(this.codeList);
}), function(err){
console.log("error in myPopulateCodeList, error: " + err.details);
deferred.reject(err);
});
return deferred;
}
};
return mo;
}); Then you can use this in your code like so: myPopulateCodeList.populateCode('spec', specUrl).then(function (codeList) {
console.log(codeList);
}, function (err) {
console.error(err);
}); Note this is not tested but should work fine. Anytime you want to make asynchronous requests, dojo/Deferred can be a great utility to have if you know how to use it. There is a lot of information on them here: dojo/Deferred — The Dojo Toolkit - Reference Guide
... View more
08-11-2015
06:44 AM
|
2
|
2
|
1608
|
|
POST
|
I think it returning undefined looks to be the correct behavior the way that Robert Scheitlin, GISP defined it. Calling that populateCode function does not actually return anything it is just updating the codeList property. So I think you could try something like this: myPopulateCodeList.populateCode('spec', specUrl); console.log(myPopulateCodeList.codeList); logging myPopulateCodeList.codeList should see some things have updated, but remember populateCode is an async function and may take time to complete so the data may not be available right away. Async operations are great to use dojo's deferred library.
... View more
08-11-2015
06:35 AM
|
2
|
0
|
1608
|
|
POST
|
I am just curious if it is possible to use web tile layers such as stamen or mapbox through: map.setBasemap('myBasemap'); I know I can do something like this to get it to recognize me calling map.setBasemap('myBasemap'): esri.basemaps['myBasemap'] = {
baseMapLayers: [{
url: 'http://{subDomain}.tile.stamen.com/watercolor/{level}/{col}/{row}.jpg'
}],
title: 'My Layer'
}; but the problem with this is it obviously wont treat the url as a tiled layer and ends up looking for something like the following: http://%7Bsubdomain%7D.tile.stamen.com/watercolor/%7Blevel%7D/%7Bcol%7D/%7Brow%7D.jpg Is there a good way to get the map to recognize tiled layers this way? I am trying to avoid adding this as a web tiled layer on top of a basemap as I would like to add this to a custom basemap gallery and to be able to use this layer the same way as other basemaps via map.setBasemap().
... View more
08-10-2015
06:31 AM
|
0
|
2
|
3941
|
|
POST
|
Ahh ok. It may be easier to just use what Dennis is suggesting. Load those scripts in the header and the esri javascript api at the end once those scripts have loaded. Not sure why it would point to something like the DropDownMenu. multipleDefine errors happen generally happen from loading modules via script tags and not the amd loader provided by dojo, or esri in this case, which results in a sort of race condition unless you load them how Dennis is suggesting. I dont think I have ever had the issue be with a dojo or esri module, its usually a 3rd party library. However I have noticed the error messages can be misleading, especially looking at the call stack because it may start loading some dojo modules, but then the 3rd party library tries to load, either from the script tag or through a define/require call or both, and it fails and you now have a call stack listing all these dojo modules when the error is really somewhere else. You can read here about the error, although its only a little snippet about it, just search mulipleDefine on this page: The Dojo Loader — The Dojo Toolkit - Reference Guide . Other than this, there is really not a lot of information floating around that really explains the issue well.
... View more
01-08-2015
01:10 PM
|
1
|
1
|
18136
|
|
POST
|
Almost every time I have seen this it has been due to jquery or some other external library. They often put shims in the code to make them compatible with AMD and Common JS module formats. I think it has to do with jquery or other being downloaded before (or after, havent dug into this too much after I figured out how to make it work) the Esri JS API. Are you referencing jQuery and knockout globally or inside your AMD modules. If your referencing them in your AMD modules you can try the following: 1. Remove the script tags pulling in JQuery and Knockout 2. Add the CDN to your aliases like so dojoConfig: {
...
aliases: [
['jquery', 'https://code.jquery.com/jquery-2.1.3.min.js '],
['knockout', 'http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.0.0.js ']
]
} 3. require them and use them that way require([
'jquery',
'knockout'
], function ($, ko) {
...
});
... View more
01-08-2015
08:08 AM
|
4
|
4
|
18136
|
|
POST
|
Try inspecting the error in the console, usually it will give you some clue as to which module is having this issue. I have seen it before and my solution may not be the same as yours but in our case, we were also loading jquery from a libs folder (this was actually an esri storymap template we were modifying), and in the console I could see the multipleDefine was referencing jquery. Our fix was in the dojoConfig you can specify aliases as an array, so we configured it to look something like this: var dojoConfig = {
packages: [
{ name: 'libs', location: location.pathname.replace(/\/[^/]+$/, "") + '/libs' }
],
aliases: [
['jquery', 'libs/jquery']
]
} If you can look at the multipleDefine and figure out which module specifically is giving the issue, that would be a good starting point.
... View more
01-08-2015
06:50 AM
|
2
|
7
|
18136
|
|
POST
|
Is there a way/example of how I can query the twitter api from a client application by using a proxy to store the secrets and keys. I know twitter discourages using their api from a client side application so rather then write a php or node.js application. Is it possible to authenticate to their api using esri's proxy.php and routing my requests through the proxy?
... View more
07-30-2014
08:46 AM
|
0
|
0
|
802
|
|
POST
|
Couple Things. You may want to read up on a AMD tutorial for Dojo or for Esri. When you put a function inside another function(aka your beginmeasure function inside the callback for require) it is not available globally. So that is why the code is throwing an error. Another thing is how to attach events in dojo. I recommend looking up how to use the dojo/on module (dojo/on view /dojo/on). It is perfect for attaching events. The way it works is you import the module via the require function, and then in your code you will call something like
on(document.getElementById("measurearea"), "click", function () {
// Run your code here
});
what that is doing is saying on, the measurearea button click event, call my function. This will allow you to listen to the button click event. Lastly you will want to look up the draw tools. They created the Draw toolbar, and attached the event for you and you don't want to change that part. What you want to do is on click, activate the toolbar, and then on draw end, run the getAreaAndLength function and deactivate the toolbar so for example:
on(document.getElementById("measurearea"), "click", function () {
tb.activate(Draw.FREEHAND_POLYGON);
});
and then in the getAreasAndLength function you will need to call tb.deactivate(); This way, map.on('load') the Draw toolbar is created, the function to get the areasAndLengths is attached to draw-end and ready to go. And then when the button is clicked, you can activate the toolbar. When they finish drawing, it will trigger the getAreasAndLength function and then you can deactivate the toolbar. Your going to need to get familiar with the AMD style of JavaScript programming to work with most of the samples.
... View more
07-29-2014
02:10 PM
|
1
|
1
|
599
|
|
POST
|
I think I have a solution for you. Try out this fiddle and see if it works, I was able to get it to not show the onAnimateEnd errors. I took the popup show out of the callback you had passed to selectFeatures and set the response as a deferred which you then pass into the popup via popup.setFeatures([def]); I then added a popup.clearFeatures() to the beginning of the queryLayer function to make sure there are no previously selected features there. Here is the fiddle url and the relevant code is below. http://jsfiddle.net/nPqS8/4/
function queryLayer(evt){
popup.hide();
popup.clearFeatures();
selectTariffLayer.clearSelection();
var point = evt.result.feature.geometry;
var query = Query();
query.geometry = point;
var def = selectTariffLayer.selectFeatures(query, selectTariffLayer.SELECTION_NEW, function(results){
var charge = results[0].attributes["Charge"];
var price = results[0].attributes["Cost"];
popup.setTitle("Parking tariffs");
popup.setContent(charge + "<br/>" + price);
});
popup.setFeatures([def]);
popup.show(point);
}
... View more
07-29-2014
01:45 PM
|
0
|
1
|
1045
|
|
POST
|
Hmmm, if you comment out popup.show(point) the error goes away, seems like the error is coming from the calling popup.show so it could be something funky with the point your passing to it although the json for that looks fine.
... View more
07-29-2014
01:30 PM
|
0
|
0
|
1045
|
|
POST
|
Ok never mind the question, I started messing with some of the tiled layer functions and finally made it work. Looks like calling this.onLoad(this) after I updated the initial and fullExtent caused the layer to reset those values and I am now no longer getting 404 errors.
... View more
07-29-2014
01:11 PM
|
0
|
0
|
1624
|
|
POST
|
Hi All, My project manager has set up some tiles on a S3 server for me. There are several sets of tiles (will be 9 when processing is done), that I want to be able to show. I have wrote a custom tiled layer and overridden the getTileUrl method and that part works great, it can fetch all the tiles it needs correctly and I have also added a property to the layer that I can set to alter the url in getTileUrl to switch between the various sets of tiles which also works fine. The issue I am having is that it is requesting tiles that the tile sets don't have resulting in 404 errors, it shows them all correctly and I'm not losing any functionality but my console is littered with these 404 errors. I have found that setting the initial extent to one of the tile set's extents will stop this from happening by only requesting tiles that set has, but this only applies to that specific set of tiles so when I switch to another set of tiles, the tiles won't even load because they are outside of that initial extent. I have tried resetting the initial extent and full extent via a helper method on the layer, I can see updated json but the layer still seems to use the original extent provided. Is there a way to update this extent value after the layer has been created ? or is there a good solution to prevent these 404's from showing in the console or even a way to prevent the request for a tile that is not part of the tile set from going out? (I was trying to avoid having to create separate layers for each tile set or have some massive lookup to know the min and max rows and columns per level for each set) As mentioned, the tiles load, no functionality is lost, just lots of 404 not founds in the console of trying to request tiles that don't exist.
... View more
07-29-2014
09:22 AM
|
0
|
1
|
4678
|
|
POST
|
hmmm, everything in the request looks ok and it even looks like all the rendering info is being passed in. Would you be able to put up a sample in JSFiddle if its not too much that I could look it. I was looking for some code samples on my mac and I realized on one of the apps, we have a custom image service layer and that we had to do a sort of trick to get a legend to appear where we put a dummy layer in a map service with a mock legend to represent the image service layer. All other apps I have built and are using print are using default symbology except for one which is showing full page map only with no legend, I know we have one or two at work built by some of my colleagues that have print functionality with custom renderers so I will check on them when I get in tomorrow to see if they are showing legends or if I can tweak the one I have to add a legend to it. I don't think this is impossible, if I recall correctly we have done it at our office in one of our apps but I will have to get back to you on that, been in school all day so my mind is not on GIS at the moment, maybe someone from Esri in the meantime can comment on this to maybe point out something I'm forgetting or point us to a sample.
... View more
01-28-2014
11:49 AM
|
0
|
0
|
2380
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-08-2015 01:10 PM | |
| 1 | 08-28-2015 08:59 AM | |
| 2 | 08-31-2015 12:26 PM | |
| 1 | 08-11-2015 08:52 AM | |
| 1 | 04-13-2016 09:04 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|