esriRequest export PNG zoom

721
6
Jump to solution
08-19-2019 09:24 AM
GregoryBologna
Occasional Contributor II

I am using esriRequest to export a map to PNG. How would I set a dynamic zoom level in mapOptions so that the entire selected parcel is zoomed in with some padding, as shown in the bottom image? If I include a scale value, the parcel zoom level is not dynamic, and is either zoomed in too much, or too little.

0 Kudos
1 Solution

Accepted Solutions
BenElan
Esri Contributor

Hi Gregory,

You could try using your min max values to create an extent. Then expanding that extent and passing those new extent min max values to your JSON.

var extent = new Extent({"xmin":-122.68,"ymin":45.53,"xmax":-122.45,"ymax":45.6})
   
extent.expand(1.3);

console.log('Afer expand: ' + extent.xmin + ', ' 
                            + extent.ymin + ', ' 
                            + extent.xmax + ', ' 
                            + extent.ymax)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Gregory,

   You would set the maps zoom to your desired extent before you consider doing the export request. In all my apps I get the selected parcels geometry and expand it by 30%.

map.setExtent(pPoly.getExtent().expand(1.3), true).then(lang.hitch(this, function() {
  //print the map
}));
GregoryBologna
Occasional Contributor II

Is there a translation to use "expand" using json? I am building a json Web_Map_as_JSON request.

        var symbol = {
            "type": "simple",
            "symbol": {
              "type": "esriSFS",
              "style": "esriSFSNull",
              "outline": {
                "type": "esriSLS",
                "style": "esriSLSSolid",
                "color": [66, 244, 206],
                "width": 4
              }
            }
        }; // end symbol
        var drawingInfo = {
          "renderer": symbol
        }; // end drawingInfo
        var webParcelLinesLayers = {
          "id": "WebLayers_2139",
          "title": "WebLayers_2139",
          "opacity": 1,
          "minScale": 0,
          "maxScale": 0,
          "url": mapLayerAndLabelsUrl,
          "layers": [
            {
              "id": 4,
              "layerDefinition": {
                "drawingInfo": drawingInfo,
                "source": {
                  "type": "mapLayer",
                  "mapLayerId": 4                 
                },                
                "definitionExpression": "PARID = '" + parid + "'"
              }
            }
          ]
        }; // end webParcelLinesLayers
        var operationalLayers = [{
          "id": "World_Street_Map_417",
          "title": "World_Street_Map_417",
          "opacity": 1,
          "minScale": 0,
          "maxScale": 0,
          "url": latestYearAerialUrl        
        }]; // end operationalLayers
        operationalLayers.push(webParcelLinesLayers);
        var json = {
          "mapOptions": {
            "showAttribution": false,             
            "extent": {
              "xmin": xmin,
              "ymin": ymin,
              "xmax": xmax,
              "ymax": ymax,             
              "spatialReference": {
                "wkid": wkid,
                "latestWkid": latestWkid
              }
            },
            "spatialReference": {
              "wkid": wkid,
              "latestWkid": latestWkid
            },
            // "scale" : 100.0,
           "rotation" : 0
          },
          "operationalLayers": operationalLayers,         
          "exportOptions": {
            "outputSize": [840, 840],
            "dpi": 96
          }
        }; // end json
        var Web_Map_as_JSON = JSON.stringify(json);
        var urlB = "Web_Map_as_JSON=" + encodeURIComponent(Web_Map_as_JSON);
        var urlC = "&Format=png32&Layout_Template=map_only&env:outSR=&env:processSR=&returnZ=false&returnM=false&returnTrueCurves=false&returnFeatureCollection=false&context=&f=pjson";
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Not that I am aware of.

0 Kudos
BenElan
Esri Contributor

Hi Gregory,

You could try using your min max values to create an extent. Then expanding that extent and passing those new extent min max values to your JSON.

var extent = new Extent({"xmin":-122.68,"ymin":45.53,"xmax":-122.45,"ymax":45.6})
   
extent.expand(1.3);

console.log('Afer expand: ' + extent.xmin + ', ' 
                            + extent.ymin + ', ' 
                            + extent.xmax + ', ' 
                            + extent.ymax)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
BenElan
Esri Contributor

If the min/max values in your code snippet above are not for the parcel, you can get those values through the REST API with a query:

https://gis.manateepao.com/arcgis/rest/services/Website/WebLayers/MapServer/6/query?where=parid+%3D+...

So just replace the parcel id (I hard coded it as 1101902509) with your parid variable to get the extent dynamically. Then you can expand as I showed above.

0 Kudos
GregoryBologna
Occasional Contributor II

Yes! Thank you, Ben. I am able to expand the extent prior to adding it to json using your method.

          xmin = results.features[0].geometry.extent.xmin;
          ymin = results.features[0].geometry.extent.ymin;
          xmax = results.features[0].geometry.extent.xmax;
          ymax = results.features[0].geometry.extent.ymax;

          var extent = new Extent({"xmin":xmin,"ymin":ymin,"xmax":xmax,"ymax":ymax});
          extent.expand(1.3);

          xmin = extent.xmin;
          ymin = extent.ymin;
          xmax = extent.xmax;
          ymax = extent.ymax;

// later on...add the expanded extent to json
 "mapOptions": {
            "showAttribution": false,             
            "extent": {
              "xmin": xmin,
              "ymin": ymin,
              "xmax": xmax,
              "ymax": ymax,             
              "spatialReference": {
                "wkid": wkid,
                "latestWkid": latestWkid
              }
            }