AnsweredAssumed Answered

Adjust view.goTo() scale/zoom based on polygon extent API 4.X

Question asked by ClintonLT16 on Apr 13, 2018
Latest reply on Apr 16, 2018 by ClintonLT16

I have a map that uses the search widget to select a parcel, then zoom to it. The problem that I am experiencing is that the resulting goTo() method zooms in too close. My initial thought was to alter the zoomScale property, but that will not work since I have many different sized parcels in my data. 



I have disabled the native SearchWidget zoom, and tried to insert a custom zoom once a search item is selected. However, the search-result I seem to receive is an extent, and the goTo() method accepts a zoom or scale value. Is there a way to convert the resulting extent to my desired scale or zoom?





<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="description" content="ArcGIS JS v4, Calcite Maps and Bootstrap Example">

  <title>PLI Zoom</title>

  <!-- Calcite Maps Bootstrap -->
  <link rel="stylesheet" href="">
  <!-- Calcite Maps -->
  <link rel="stylesheet" href="">

  <!-- ArcGIS JS 4 -->
  <link rel="stylesheet" href="">

      margin: 0;
      padding: 0;
      height: 100%;
      width: 100%;


<body class="calcite-maps calcite-nav-top">
  <!-- Navbar -->

  <nav class="navbar calcite-navbar navbar-fixed-top calcite-text-light calcite-bg-custom" style="background-color: #699999">
    <!-- Menu -->
    <div class="dropdown calcite-dropdown calcite-text-light calcite-bg-custom" role="presentation" style="background-color: #699999">
      <a class="dropdown-toggle" role="menubutton" aria-haspopup="true" aria-expanded="false" tabindex="0">
        <div class="calcite-dropdown-toggle">
          <span class="sr-only">Toggle dropdown menu</span>
      <ul class="dropdown-menu" role="menu">
        <li><a role="menuitem" tabindex="0" data-target="#panelInfo" aria-haspopup="true"><span class="glyphicon glyphicon-info-sign"></span> About</a></li>
        <li><a role="menuitem" tabindex="0" href="#" data-target="#panelLegend" aria-haspopup="true"><span class="glyphicon glyphicon-list-alt"></span> Legend</a></li>
        <li><a role="menuitem" tabindex="0" href="#" id="calciteToggleNavbar" aria-haspopup="true"><span class="glyphicon glyphicon-fullscreen"></span> Full Map</a></li>
    <!-- Title -->
    <div class="calcite-title calcite-overflow-hidden">
      <span class="calcite-title-main">PLI Zoom</span>
      <span class="calcite-title-divider hidden-xs"></span>
      <span class="calcite-title-sub hidden-xs">A PLI parcel zoom tool</span>
    <!-- Nav -->
    <ul class="nav navbar-nav calcite-nav">
        <div class="calcite-navbar-search calcite-search-expander">
          <div id="searchWidgetDiv"></div>

  <!--/.calcite-navbar -->

  <!-- Map  -->

  <div class="calcite-map calcite-map-absolute">
    <div id="mapViewDiv"></div>

  <!-- /.calcite-map -->

  <!-- Panels -->

  <div class="calcite-panels calcite-panels-right calcite-text-light calcite-bg-custom panel-group" style="background-color: #699999">

    <!-- Panel - Basemaps -->

    <div id="panelInfo" class="panel collapse in">
      <div id="headingInfo" class="panel-heading" role="tab">
        <div class="panel-title">
          <a class="panel-toggle" role="button" data-toggle="collapse" href="#collapseInfo"  aria-expanded="true" aria-controls="collapseInfo"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><span class="panel-label">About</span></a>
          <a class="panel-close" role="button" data-toggle="collapse" tabindex="0" href="#panelInfo"><span class="esri-icon esri-icon-close" aria-hidden="true"></span></a> 
      <div id="collapseInfo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingInfo">
        <div class="panel-body">
          <p>This is a parcel zoom tool that functions to zoom to any public land parcel within the state of Florida. Use the search widget by choosing the "Florida Public Land Inventories Parcels" option within the navigation bar to search for a parcel by ID, city, or parcel name.</p>

    <!-- Panel - Legend -->

    <div id="panelLegend" class="panel collapse">
      <div id="headingLegend" class="panel-heading" role="tab">
        <div class="panel-title">
          <a class="panel-toggle" role="button" data-toggle="collapse" href="#collapseLegend" aria-expanded="false" aria-controls="collapseLegend"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span><span class="panel-label">Legend</span></a>
          <a class="panel-close" role="button" data-toggle="collapse" tabindex="0" href="#panelLegend"><span class="esri-icon esri-icon-close" aria-hidden="true"></span></a>
      <div id="collapseLegend" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingLegend">
        <div class="panel-body">           
          <div id="legendDiv"></div>


  <!-- /.calcite-panels -->

  <script type="text/javascript">
    var dojoConfig = {
      packages: [{
        name: "bootstrap",
        location: ""
        name: "calcite-maps",
        location: ""

  <!-- ArcGIS JS 4 -->
  <script src=""></script>

      // ArcGIS

      // Widgets
      // Bootstrap

      // Calcite Maps
      // Calcite Maps ArcGIS Support

    ], function(Map, PopupTemplate, FeatureLayer, MapImageLayer, MapView, SimpleFillSymbol, SimpleLineSymbol, Graphic, Home, Zoom, Compass, Search, Legend, BasemapToggle, ScaleBar, Attribution, Locator, Collapse, Dropdown, CalciteMaps, CalciteMapArcGISSupport, Color, number) {

       * Create the map, view and widgets

      var parcelsTemplate = {
        title: 'Owner: {own_name}',
          "<p><b>Parcel ID:</b> {parcel_id}</p>" +
          "<p><b>State Parcel ID:</b> {state_par_}</p>" +
          "<p><b>PLI Code:</b> {pli_code}</p>" +
          "<p><b>Size:</b> {no_lnd_unt:NumberFormat(places: 2)} Acres<p>" +
          "<p><b>Value:</b> ${av_nsd:NumberFormat(places: 2)}</p>" + 
          "<p><b>TRS:</b> {twn} {rng} {sec}</p>" +
          "<p><b>Legal Description:</b> {s_legal}</p>" ,
        actions: [{
          title: "Visit the FL Public Lands Inventory Website",
          id: "pliWebsite",
          className: "esri-icon-launch-link-external"

      var parcelsSearchTemplate = {       
        title: 'Owner: {own_name}',
          "<p><b>Parcel ID:</b> {PARCEL_ID}</p>" +
          "<p><b>State Parcel ID:</b> {STATE_PAR_}</p>" +
          "<p><b>PLI Code:</b> {PLI_CODE}</p>" +
          "<p><b>Size:</b> {NO_LND_UNT} Acres<p>" +
          "<p><b>Value:</b> ${AV_NSD}</p>" + 
          "<p><b>TRS:</b> {TWN} {RNG} {SEC}</p>" +
          "<p><b>Legal Description:</b> {S_LEGAL}</p>" ,
        actions: [{
          title: "Visit the FL Public Lands Inventory Website",
          id: "pliWebsite",
          className: "esri-icon-launch-link-external"

      var highlightSymbol = new SimpleLineSymbol(
      new Color([66, 244, 217]), 1);

      var parcelsLayerURL = "";
      var parcelsLayer = new MapImageLayer ({
        url: parcelsLayerURL,
        title: "Parcels Layer",
        sublayers: [{
          id: 0,
          title: "PLI Parcels",
          visible: true,
          minScale: 100000,
          popupTemplate: parcelsTemplate

      // Map
      var map = new Map({
        basemap: "topo",
        layers: [parcelsLayer]
      // View
      var mapView = new MapView({
        container: "mapViewDiv",
        map: map,
        padding: {
          top: 50,
          bottom: 0
        center: [-82.28, 27.8],
        zoom: 7,
        ui: {components: []}

      // Popup and panel sync

      // Search - add to navbar
      var searchWidget = new Search({
        container: "searchWidgetDiv",
        view: mapView,
        allPlaceHolder: "Text search for Parcel ID",
        sources: [{
        featureLayer: {
          url: parcelsLayerURL,
          popupTemplate: parcelsSearchTemplate
        searchFields: ["PARCEL_ID", "STATE_PAR_", "OWN_CITY", "OWN_NAME"],
        suggestionTemplate: "PID: {parcel_id}, State PID: {state_par_}, City: {own_city}, Parcel Name: {own_name}",
        displayField: "PLI_CODE",
        exactMatch: false,
        outFields: ["PLI_CODE", "PARCEL_ID", "OWN_NAME", "OWN_STATE", "STATE_PAR_", "NO_LND_UNT", "AV_NSD", "TWN", "SEC", "S_LEGAL", "RNG"],
        name: "Florida Public Land Inventories Parcels",
        placeholder: "Search by Parcel ID, City, or County",
        resultGraphicEnabled: true,
        resultSymbol: {
          type: "simple-line",
          width: 2,
          color: [0, 255, 197, 1]
        autoNavigate: false

      }, {
        locator: new Locator({ url: "//" }),
        singleLineFieldName: "SingleLine",
        name: "Geocoder",
        localSearchOptions: {
          minScale: 300000,
          distance: 50000
        placeholder: "Search Geocoder",
        maxResults: 3,
        maxSuggestions: 6,
        suggestionsEnabled: true,
        minSuggestCharacters: 0,
        countryCode: "US"

      // Map widgets
      var home = new Home({
        view: mapView
      mapView.ui.add(home, "top-left");

      var zoom = new Zoom({
        view: mapView
      mapView.ui.add(zoom, "top-left");

      var compass = new Compass({
        view: mapView
      mapView.ui.add(compass, "top-left");
      var basemapToggle = new BasemapToggle({
        view: mapView,
        secondBasemap: "satellite"
      mapView.ui.add(basemapToggle, "bottom-right");         
      var scaleBar = new ScaleBar({
        view: mapView
      mapView.ui.add(scaleBar, "bottom-left");

      var attribution = new Attribution({
        view: mapView
      mapView.ui.add(attribution, "manual");

      // Panel widgets - add legend
      var legendWidget = new Legend({
        container: "legendDiv",
        view: mapView
      // Watch search result
      searchWidget.on("select-result", function(event){
          target: event.result.feature,

      // Popup Link event listener
      mapView.popup.on("trigger-action", function (event) {
      if ( === "pliWebsite") {"");