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
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;
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(
SimpleMarkerSymbol, SimpleLineSymbol,
PictureFillSymbol,
Graphic,
Color
) {
function zoomToPoint(pt, testo){
map.graphics.clear();
var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE,6, new SimpleLine Symbol(SimpleLineSymbol.STYLE_SOLID, new 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(pt, sms);
map.graphics.add(graphic);
//addLabel(pt, testo,0,5)
}
window.zoomToPoint=zoomToPoint;
});
Thanks for your help
I appreciate very much
Martina
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.
Thank you
You are very kind