1

I've been trying to create a map and have it's initial zoom and center position be the query result's coordinates (a polygon, in this case) but it just refuses to zoom in, both using zoom in the constructor and centerAndZoom(). Centering, however, works just fine, it seems.

    _onBtnPrintClicked: function() {
                console.log("Begin query test");
                var queryUrl = "https://portalURL/arcgis/rest/services/FEATURE/FEATURE/FeatureServer/0";
                var queryTask = new QueryTask(queryUrl);
                var query = new Query();
                query.returnGeometry = true;
                query.outFields = ["*"];
                query.where = "OBJECTID = 53";
                console.log("Running execute");

                queryTask.execute(query).then(function(results) {
                    newExtent = new Extent(results.features[0].geometry.getExtent());                        
                    fichaMap = new Map("mapDiv", {
                        extent: newExtent,                       
                        showLabels: true,
                        logo: false,
                        zoom: 20,
                        slider: false
                    });
                }

Using Extent, like this, i get it to be centered and zoomed, but it is not the desired result as i would like it zoomed out a bit more (and not have the polygon in question fit the entire map's div element. Now, i've already tried using center and zoom in the constructor and as well as using centerAndZoom and neither method works apart from centering.

What am I doing wrong?

0

If you give a value to the property extent, then the property zoom will give you a zoom level after the extent was set (center). You may be using a zoom level which is too large (20), and probably that's the reason it doesn't work.

I would get the actual zoom level from the map (which is the one from the extent), after map loads, and then modify it accordingly:

_onBtnPrintClicked: function() {
                console.log("Begin query test");
                var queryUrl = "https://portalURL/arcgis/rest/services/FEATURE/FEATURE/FeatureServer/0";
                var queryTask = new QueryTask(queryUrl);
                var query = new Query();
                query.returnGeometry = true;
                query.outFields = ["*"];
                query.where = "OBJECTID = 53";
                console.log("Running execute");

                queryTask.execute(query).then(function(results) {
                    newExtent = new Extent(results.features[0].geometry.getExtent());                        
                    fichaMap = new Map("mapDiv", {
                        extent: newExtent,                       
                        showLabels: true,
                        logo: false,
                        //
                        // Dont't give a zoom level, use the one from the extent
                        //
                        //zoom: 20,
                        slider: false
                    });

                    fichaMap.on("load, function() {
                        //
                        // Modify the Zoom level accordingly
                        //
                        map.setZoom(map.getZoom() - 1 );
                    });
                }
  • It sadly didn't work. I tried this: javascript fichaMap.on("load", function() { console.log(fichaMap.getZoom()); fichaMap.setZoom(fichaMap.getZoom() - 1); console.log(fichaMap.getZoom()); }); And get zoom retuns -1 on both console.logs – Matheus Vinicius Jul 5 at 12:52
  • If zoom is still -1, seems to be that the map wasn't loaded... I would double check the the extent, probably is not right because there is not a valid query result. – Katah Jul 9 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.