Set Extent of Map from Value in Database Table

1518
6
Jump to solution
07-23-2014 08:54 AM
KeithAnderson
New Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
ReneWoy
New Contributor III

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;

                }

            }

        });

  

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

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);

ReneWoy
New Contributor III

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;

                }

            }

        });

  

KeithAnderson
New Contributor III

Thank you for the reply's!

Very grateful to both of you.

Keith

0 Kudos
KeithAnderson
New Contributor III

Rene

If you get a chance....

Trying to pull out database values on startup of the application.

Added another dojo/Deffered as you did for GetURLValue().

Stuck.

Thanks

Keith

0 Kudos
ReneWoy
New Contributor III

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

...

...}

0 Kudos
KeithAnderson
New Contributor III

Rene

I did get an answer to this.

Thank you for you reply.

Keith Anderson

LOGIS GIS

5750 Duluth St

Golden Valley MN 55422

763-543-2641(w)

763-226-7061(c)

kanderson@logis.org<mailto:kanderson@logis.org>

0 Kudos