Setting Zoom/Extent for Attribute table Zoom To

361
4
Jump to solution
08-01-2019 07:57 AM
JohnHovanec
New Contributor

I'm trying to set the zoom level for the 'Zoom to' feature from the attribute table using WAB 2.12. I believe the same method is shared when using the enable pop-up feature from the attribute table, or at least I hope it is shared. The default setting zooms in too close and I would like to set the zoom level so that it is farther out.  I have tried modifying /jimu.js/zoomToUtils.js to set the extentFactor in the zoomToFeatureSet method:

mo.zoomToFeatureSet = function(map, featureSet, /*optional*/extentFactor) {
var layer = featureSet.features &&
featureSet.features.length > 0 &&
featureSet.features[0].getLayer &&
featureSet.features[0].getLayer();
var layerId = layer ? layer.id : null;
extentFactor = 1.2; // Added this to set the zoom level extent
var extent = mo.graphicsExtent(featureSet.features, extentFactor);
console.log("In the zoomToUtils. extentFactor: " + extentFactor + " featureSet.features: " + featureSet.features + " extent: " + extent);

return mo.zoomToExtent(map, extent, layerId);
};‍‍‍‍‍‍‍‍‍‍‍‍

This seems to have no effect. I feel like I'm close but not quite there to get this working. Any help or advice would be appreciated.

Thanks,

John

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

   In the zoomToUtils.js if the feature is a single point then it goes down a code route that does not use the zoomFactor.

See line 15 below.

  mo.graphicsExtent = function(graphicsParam, /* optional */ factor){
var ext = null;
try {
var graphics = graphicsParam;
if(graphics &&
graphics.length === 1 &&
graphics[0].geometry.declaredClass === "esri.geometry.Multipoint" &&
graphics[0].geometry.points.length === 1) {

var mPoint = graphics[0].geometry.points[0];
var point = new Point(mPoint[0], mPoint[1], graphics[0].geometry.spatialReference);
graphics = [new Graphic(point)];
}

if(graphics && graphics.length === 1 && graphics[0].geometry.declaredClass === "esri.geometry.Point") {
var geometry = graphics[0].geometry;
ext = new Extent(geometry.x - 0.0001,
geometry.y - 0.0001,
geometry.x + 0.0001,
geometry.y + 0.0001,
geometry.spatialReference);
ext.isSinglePoint = true;
} else if(graphics && graphics.length > 0){
ext = graphicsUtils.graphicsExtent(graphics);
if (ext) {
if(typeof factor === "number" && factor > 0){
ext = ext.expand(factor);
}
}
}
} catch (e) {
console.error(e);
}
return ext;
};

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

   An extent Factor of 1.2 means that the zoom is set to 120% (i.e. 20% bigger then the norm). Normally you would want the factor larger then that. Also where I make the change for the AT widget is in the _FeatureTable.js file:

    // differect with layer.selectFeatures
selectFeatures: function(method, result) {
if (result && result.length > 0) {
if (method === "rowclick" || method === "selectall") {// ignore selectall
this._setSelection(result); // call selectionManager
} else if (method === "zoom" || method === "row-dblclick") {
var gExtent = jimuUtils.graphicsExtent(result);
var featureSet = jimuUtils.toFeatureSet(result);
// use "zoom-end" and "pan-end" to catch zooming animation complete callback
// more precisely than the callback from "jimuUtils.zoomToFeatureSet"
var onMapZoomOrPan = on(this.map, 'zoom-end, pan-end', lang.hitch(this, function() {
onMapZoomOrPan.remove();
if (method !== "row-dblclick" || !this.domNode) {
return;
}
this._showMapInfoWindowByFeatures(gExtent, result);
}));
// use "zoomToFeatureSet" method in jimu/utils to zoom to feature(s)
jimuUtils.zoomToFeatureSet(this.map, featureSet, 2.0).then(null, function(err) {
...
0 Kudos
JohnHovanec
New Contributor

Robert, 

Thanks for your response. I added your changes and can see in the console that the extentFactor is being set correctly but for some reason I don't see any difference in the zoom level. I've played around with a number of different values but it seems to not cause any difference in the actual zoom level. 

I'm trying to zoom layers that have been added dynamically so perhaps there is something off with the extent for those layers. 

Thanks,

John

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

John,

   In the zoomToUtils.js if the feature is a single point then it goes down a code route that does not use the zoomFactor.

See line 15 below.

  mo.graphicsExtent = function(graphicsParam, /* optional */ factor){
var ext = null;
try {
var graphics = graphicsParam;
if(graphics &&
graphics.length === 1 &&
graphics[0].geometry.declaredClass === "esri.geometry.Multipoint" &&
graphics[0].geometry.points.length === 1) {

var mPoint = graphics[0].geometry.points[0];
var point = new Point(mPoint[0], mPoint[1], graphics[0].geometry.spatialReference);
graphics = [new Graphic(point)];
}

if(graphics && graphics.length === 1 && graphics[0].geometry.declaredClass === "esri.geometry.Point") {
var geometry = graphics[0].geometry;
ext = new Extent(geometry.x - 0.0001,
geometry.y - 0.0001,
geometry.x + 0.0001,
geometry.y + 0.0001,
geometry.spatialReference);
ext.isSinglePoint = true;
} else if(graphics && graphics.length > 0){
ext = graphicsUtils.graphicsExtent(graphics);
if (ext) {
if(typeof factor === "number" && factor > 0){
ext = ext.expand(factor);
}
}
}
} catch (e) {
console.error(e);
}
return ext;
};

View solution in original post

0 Kudos
JohnHovanec
New Contributor

Robert,

Thanks so much for your help on that, it now works. I set the following in zoomToUtils.js which now allows for a better zoom level:

ext = new Extent(geometry.x - 0.1219, // These were all set to 0.0001
geometry.y - 0.1219,
geometry.x + 0.1219,
geometry.y + 0.1219,
geometry.spatialReference);
ext.isSinglePoint = false; // Was set to true

My values for the above were just guesses, but it works great now and unless you have pointers I will go with them.

Thanks again for your help, you have again saved me on this project!

John

0 Kudos