Access to map object and function in web map application

266
4
05-24-2020 01:10 AM
VincenzoLisi
New Contributor II

Hello

I have an iframe with a downloaded web map application. How can I access to map object and map functions from another iframe?
And if I need to add some custom functions, where is the best place to write them?

Thanks Martina 

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Martina,

 

  Normally you have a global var that references the opener. Something like this:

document.winobj = window.open("someurl", "_blank", features);

Then that html file has public functions or methods that you call using document.winobj

 

Then in the html file I opened, it can get access back to the widget using something like this:

window.opener.document.myWidget.setLatLonHandler(pt.lat(), pt.lng());

The document.myWidget was set inside the widgets postCreate method:

document.myWidget = this;
VincenzoLisi
New Contributor II

Hi Robert

thanks for your answer!

I’m new in WAB developing and there are some not clear questions.

Do you mean that I have to write my custom function in a Widget?

For example, if I want call a function like “ZoomToPoint” (see below) from a button inside IframeA, which makes a map zoom in the webapplication in IframeB, have I necessarily to create a widget in the web app with public ZoomToPoint function? Is it not possible to write this function in a custom js file which accesses the map?

require([

  "esri/symbols/SimpleMarkerSymbol""esri/symbols/SimpleLineSymbol",

  "esri/symbols/PictureFillSymbol",

  "esri/graphic"

  "esri/Color"

], function(

  SimpleMarkerSymbolSimpleLineSymbol,

  PictureFillSymbol,

  Graphic

  Color

) {

 

 function zoomToPoint(pttesto){

  map.graphics.clear();

  var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE,6new SimpleLine Symbol(SimpleLineSymbol.STYLE_SOLIDnew Color([255,0,0]), 1), new Color([255,0,0,0.25]));  

  //goToScala(scala_punto);

  map.centerAt(pt,0.1);   

  var graphic = new esri.Graphic(ptsms);

  map.graphics.add(graphic);

  //addLabel(pt, testo,0,5)

}

window.zoomToPoint=zoomToPoint;

});

Thanks for your help

I appreciate very much

Martina

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Martina,

   No you may not need a custom widget. I was providing a method that I personally use as an example for you to understand and adjust to your workflow and use case. The big thing to takeaway is the use of global vars and functions.

0 Kudos
VincenzoLisi
New Contributor II

Thank you

You are very kind

0 Kudos