Folks
Please look at the example below. I am adding a map but would like to pass in the extent from an outside source...either a URL parameter or a QueryTask from a table. It seems that the order of operation for JavaScript is stumping me. The map requires the extent info prior to querying the extent. Please show me how to proceed. Thank you.
Keith
Solved! Go to Solution.
I think the problem is, the result is a string, not a array
that should work:
map = new Map("map", {
basemap: "topo",
center: JSON.parse(cityextent), // longitude, latitude
zoom: 13
});
if you want to be sure use a callback:
require(["esri/map", "dojo/Deferred", "dojo/domReady!"], function (Map, Deferred) {
GetUrlValue('extent').then(function (centerPoint) {
console.info(centerPoint);
map = new Map("map", {
basemap: "topo",
center: JSON.parse(centerPoint),
zoom: 13
});
});
function GetUrlValue(VarSearch) {
var deferred = new Deferred();
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');
for (var i = 0; i < VariableArray.length; i++) {
var KeyValuePair = VariableArray.split('=');
if (KeyValuePair[0] == VarSearch) {
deferred.resolve(KeyValuePair[1]);
}
return deferred.promise;
}
}
});
What I've done is to create the map with information from an external file (read into the parameters variable), then set its extent from the file after the map is loaded
map = new Map("divMap", { |
basemap: parameters.basemap,
//extent: new Extent(parameters.extent),
lods: parameters.lods,
logo: false,
showAttribution: false
}); |
map.on("load", function () { |
initialExtent = new Extent(parameters.extent);
map.setExtent(initialExtent, true);
I think the problem is, the result is a string, not a array
that should work:
map = new Map("map", {
basemap: "topo",
center: JSON.parse(cityextent), // longitude, latitude
zoom: 13
});
if you want to be sure use a callback:
require(["esri/map", "dojo/Deferred", "dojo/domReady!"], function (Map, Deferred) {
GetUrlValue('extent').then(function (centerPoint) {
console.info(centerPoint);
map = new Map("map", {
basemap: "topo",
center: JSON.parse(centerPoint),
zoom: 13
});
});
function GetUrlValue(VarSearch) {
var deferred = new Deferred();
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');
for (var i = 0; i < VariableArray.length; i++) {
var KeyValuePair = VariableArray.split('=');
if (KeyValuePair[0] == VarSearch) {
deferred.resolve(KeyValuePair[1]);
}
return deferred.promise;
}
}
});
Thank you for the reply's!
Very grateful to both of you.
Keith
Sorry for the delay.
Have you found a solution? If not, can you post the result of
qTask.execute(QT, function (results) {
console.log(results); // post the result
...
...}