Popup focus

2065
10
03-10-2017 06:46 AM
MathewSuran
New Contributor III

I have a point feature that when clicked on, generates a popup with a graphic.  The graphic is rather large so the whole popup is always cut off.  I looked through the documentation and I am not really sure on what to call it so I don't really know what I am looking for, but I am looking to have the map resize to automatically when a popup is active to be able to refocus on the popup to show the whole thing.  Anyone have any idea? 

0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus

Mathew,

  You can use the Popup objects reposition method that is specifically designed for that:

https://developers.arcgis.com/javascript/3/jsapi/popup-amd.html#reposition 

0 Kudos
MathewSuran
New Contributor III

Ok, thanks.  How would this work for a PopupTemplate?  See example below:

currentLayer.on("click", function(evt) {

console.log(evt);
 featureId= evt.graphic.attributes.OBJECTID;
 currentLayer.queryAttachmentInfos(featureId, function(attach) {
 featureUrl=attach[0].url;
 currenttemplate = new PopupTemplate({
 title: "Current",
 fieldInfos: [{
 fieldName: "Name",
 label: "Name: ",
 visible: true
 },{
 fieldName: "X",
 label: "X: ",
 visible: true
 },{
 fieldName: "Y",
 label: "Y: ",
 visible: true
 }],
 mediaInfos:[{ //define the image
 "title": "",
 "caption": "",
 "type":"image",
 "value":{
 "sourceURL": featureUrl
 }
 }]
 });
 currentLayer.infoTemplate=currenttemplate;
 },
 function(errback) {
 console.log(errback);
 });
 });
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mathew,

  For that you will have to attach and event to the Popups show event and then call the repostion method.

0 Kudos
MathewSuran
New Contributor III

Would you be able to provide an example?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mathew,

  Something like:

map.infoWindow.on("show", function(){
  setTimeout(function(){
    map.infoWindow.reposition();
  }, 500);
});
0 Kudos
MathewSuran
New Contributor III

Maybe I am not placing it in the correct position, but it is not working.  I would want to place this after the layers and templates get loaded, correct?

0 Kudos
JimNoel
New Contributor III

Can you give an example for how to do the same in 4.3?  There doesn't seem to be a "show" event for the 4.3 Popup class.  Is this accessed in a different way?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jim,

   In 4.x API you would watch the view.popup.visible property

0 Kudos
JimNoel
New Contributor III

So my problem is actually a little different from Mathew's.  If the point feature is close to the edge of the display so that the popup in its original position extends beyond the display, the map pans to fit the popup.  I want to keep the original map extent, and move the popup to fit the current extent.  (If it makes a difference, the popup is triggered by a mouseover rather than a mouse click, using MapView.hitTest)

I tried watching the view.popup.visible property and using the reposition method in the callback, but that didn't work.

Question:  Will the callback function for view.popup.visible come up before the map extent changes?

Alternatively, is there some other setting I can use to prevent the map extent from changing?  Thanks.

0 Kudos