Select to view content in your preferred language

Map components Search zoom scale?

454
6
Jump to solution
04-02-2025 11:23 AM
JaredPilbeam2
MVP Alum

I don't see a way to control the zoom? I don't see a property to do so. This has no effect:

<arcgis-search position="top-left" zoom="10"></arcgis-search>

 

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Esri Frequent Contributor

You can do this by listening for the sources collection to change.

https://codepen.io/odoe/pen/gbOqrXv?editors=1000

const searchElement = document.querySelector("arcgis-search");
// component loaded, might still be loading data
await searchElement.componentOnReady();

searchElement.allSources.on("change", () => {
  searchElement.allSources.forEach((source) => {
    source.zoomScale = 100000;
  });
});

 

View solution in original post

6 Replies
Sage_Wall
Esri Regular Contributor

Hi @JaredPilbeam2 ,

The zoomScale is set in the zoom components sources property

<arcgis-search id="search" position="top-right"></arcgis-search>

<script type="module">
  const searchElement = document.getElementById("search");
  searchElement.addEventListener("arcgisReady", () => {
    searchElement.sources = [
      {
        url:
        "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer",
        name: "LocatorSearchSource",
        zoomScale: 1000000
      }
    ];
  });
</script>

 

0 Kudos
JaredPilbeam2
MVP Alum

Thanks for the reply. That doesn't seem to have any effect on the zoom either? And it's asking me to sign in. Does it need a token? Sample.

 

0 Kudos
Sage_Wall
Esri Regular Contributor

Yeah i think that service does require a token or to sign in, I just copied it from the doc and didn't try and run it.  I see a few layerview creation errors in your codepen, but I don't think that would affect the search.  I'm not sure what's going on I'll have to look into it more closely

0 Kudos
Noah-Sager
Esri Regular Contributor

Hi @JaredPilbeam2, you may need to use the widget property to do that currently. We're in a transition process with components and widgets. I believe you want the goToOverride property, 

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#goToOverride

 

JaredPilbeam2
MVP Alum

Hi @Noah-Sager, yes I am aware of the transition. My goal here is just that. I'm creating an app using components, not widgets, to get a leg-up on my functioning custom apps that will need transitioning.

0 Kudos
ReneRubalcava
Esri Frequent Contributor

You can do this by listening for the sources collection to change.

https://codepen.io/odoe/pen/gbOqrXv?editors=1000

const searchElement = document.querySelector("arcgis-search");
// component loaded, might still be loading data
await searchElement.componentOnReady();

searchElement.allSources.on("change", () => {
  searchElement.allSources.forEach((source) => {
    source.zoomScale = 100000;
  });
});