Hi - I'm trying to make a info window appear on my map like the sample shown here: Show an info window | ArcGIS API for JavaScript 3.23
The only difference is that I'm using dojo templates in my app -- my html template (Start.htm) is:
<div>
<div id="mapDivStart" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"
style="width: 100%; height: 100%; margin: 0;">
</div>
</div>
my javascript code is:
define([
"esri/map",
"dojo/_base/declare",
"dojo/_base/lang",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!Templates/Start.htm"
], function (
Map,
declare, lang, _WidgetBase, _TemplatedMixin,
_WidgetsInTemplateMixin, StartTpl) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: StartTpl,
map: "",
postCreate: function () {
//map
map = new Map("mapDivStart", {
basemap: "topo",
center: [-117.8, 34.0],
//center: [-122.4, 34.2],
zoom: 9,
});
map.on("load", function () {
map.infoWindow.resize(250, 100);
});
map.on("click", this.addPoint);
},
addPoint:function(evt){
var latitude = evt.mapPoint.getLatitude();
var longitude = evt.mapPoint.getLongitude();
map.infoWindow.setTitle("Coordinates");
map.infoWindow.setContent(
"lat/lon : " + latitude.toFixed(2) + ", " + longitude.toFixed(2) +
"<br>screen x/y : " + evt.screenPoint.x + ", " + evt.screenPoint.y
);
map.infoWindow.show(evt.mapPoint, map.getInfoWindowAnchor(evt.screenPoint));
}
});
});
When I debug in the console I get no errors and I see values for all the variables (evt, map, etc..) The infoWindow just never appears
Any idea what could be happening here?
Thanks
Solved! Go to Solution.
I found out what it was -- I have 2 maps in my app, both defined as global variables named 'map' -- once I changed the name of the second map it worked fine
Pete,
So is this being used in a larger parent code project or some iFrame? Have you tried to put a console.log in your map click event handler to see if you are getting the click event?
Hi Robert - yes, this is part of a larger project. I've confirmed that the addPoint function fires, and I see no errors in any of the code that runs in the function. I have several other maps in the project that run pop-ups off clicks of feature layers -- this one is puzzling
Pete,
Just try using:
map.infoWindow.show(evt.mapPoint);
Robert - the popup doesnt appear when I just use the code you suggest above (although it does run). I guess I'll try removing this page from the rest of my application and try running it by itself
I found out what it was -- I have 2 maps in my app, both defined as global variables named 'map' -- once I changed the name of the second map it worked fine