Setting Zoom/Extent for Query Widget Results

1351
11
Jump to solution
03-22-2019 09:19 PM
ArthurKay
New Contributor III

So I have been trying this evening to have a more "zoomed out" view when selecting results from a query. I believe I have located the relevant code in my apps folder under WebappBuilderforArcGIS>server>apps>[myapp]>widgets>Query>SingleQueryResult.js


I'm particularly looking at the polylines section of code as I am working with some Roads data atm, although learning the general method for other geometry types would be great too.


I've tried a few simple things including jacking up the extend.expand(10) which didn't seem to make a difference. I was able to break the results behavior of zooming to extent, so I think I am working on the right code block, but just unclear the best way to proceed.

Thanks in advance for any assistance!

this._selectResultTr(tr);

html.addClass(tr, 'jimu-state-active');
var feature = tr.feature;
var geometry = feature.geometry;
if (geometry) {
   var geoType = geometry.type;
   var centerPoint, extent;
if (geoType === 'point') {
   centerPoint = geometry;
} else if (geoType === 'multipoint') {
   if (geometry.points.length === 1) {
      centerPoint = geometry.getPoint(0);
    } else if (geometry.points.length > 1) {
     centerPoint = geometry.getPoint(0);
}

} else if (geoType === 'polyline') {
extent = geometry.getExtent();
extent = extent.expand(1.4);
centerPoint = extent.getCenter();
} else if (geoType === 'polygon') {
extent = geometry.getExtent();
extent = extent.expand(1.4);
centerPoint = extent.getCenter();
} else if (geoType === 'extent') {
extent = geometry;
extent = extent.expand(1.4);
centerPoint = extent.getCenter();
}
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Arthur,

   Yes you seem to be working in the correct file and No you do not have to reload WAB/Node each time you make a change you just need to refresh the browser. The issue is the code you have changed is not used in the zooming.

This is the line that controls zooming:

jimuUtils.zoomToFeatureSet(this.map, featureSet);

What you need to do is add a third property to this call. The zoomfactor.

jimuUtils.zoomToFeatureSet(this.map, featureSet, 1.8);

View solution in original post

11 Replies
ArthurKay
New Contributor III

Just a follow up question, and I apologize, as I am sure the answer is somewhere, but when I have webapp builder for developer running through node.js, and I make edits to the code of a file and save it, do I have to relaunch the node.js server or can I just refresh or re-open the app that I am currently working on?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Arthur,

   Yes you seem to be working in the correct file and No you do not have to reload WAB/Node each time you make a change you just need to refresh the browser. The issue is the code you have changed is not used in the zooming.

This is the line that controls zooming:

jimuUtils.zoomToFeatureSet(this.map, featureSet);

What you need to do is add a third property to this call. The zoomfactor.

jimuUtils.zoomToFeatureSet(this.map, featureSet, 1.8);
ArthurKay
New Contributor III

Thank you Robert, worked like a charm. You the hero that Gotham/ArcGIS community needs..the batman! But seriously I never would have figured this out... you are a life saver.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Glad to help.

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos
RobertPiatek
New Contributor II

Hi Robert,
I'm trying to change this third factor to zoom in result (when I do a query and get one point as a result I want to see this point more zoomed). Is this function still works? 

BR RobertP

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

@RobertPiatek 

Looking at 2.20 the code looks the same so yes it should still work.

RobertPiatek
New Contributor II

So what values this parameter takes? 0-100? Which value is closer zoom and which is further? 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

@RobertPiatek  1 is 100% 1.8 is 180% 

RobertPiatek
New Contributor II

That's strange because when I put 3 or 14 I haven't seen a difference. 

and to make sure that I'm describing it correctly 

RobertPiatek_0-1632322239990.png

I want to set the closer zoom to the searched point after choosing it from the result list on the left. Without having to click "Zoom in" in a popup window. 

0 Kudos