Select to view content in your preferred language

Can I define different Infowindows on separate layers ?

873
2
06-19-2011 09:47 PM
GeorgieCassar
Frequent Contributor
I have 2 map layers in the same map service representing different bus routes.  (Route 1 and Route 4)

My Aim: 
to display them on a map and when user hovers over Route 1, a range of attributes display in an infowindow.  When user hovers on Route 4, an info window displays containing a hyperlink to another page. 

My problem:
I can get Route 1 to work properly on hover.
When I try and apply an Infotemplate to Route 4, it exits the iteration of graphics (with no error).
I am wondering if there can only be one Infowindow defined per map ?????

I started with the sample called "Load query results and show on hover" http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm

This sumarises what I do:
Map is initialised, relevant layers added
When map is loaded, a function runs that defines a query for each route. Each with a callback function. The 2 Info Templates are defined also. 
Query of Route 1 is executed.  (and its associated callback)
Query of Route 4 is executed (and its associated callback)
(end of function.)

Each callback routine is a function that:
{
1. Defines a new graphic layer
2. Loops through the query result featureset graphics and for each one sets the relevant Infotemplate to the graphic and adds to a graphic layer.
3. Sets up an event listener for a Mouseover on that graphic layer that displays the map infowindow of the feature that has been hovered over.
}

All works well for Route 1 but after using lots of 'alerts' I find that Route 4 bombs out of the graphic iteration (in step 2 above) at the point of setting the infotemplate. 
ie.  othgraphic.setInfoTemplate(infoTemplateOther);    
No error appears.

Before I include any code, perhaps someone can tell me if I am trying to do something that is not possible.  In particular, can different info windows be defined for events on different map layers ? (simultaneously)
0 Kudos
2 Replies
StephenLead
Honored Contributor
Hi Georgie,

Can you define the layers as Feature Layers? This will potentially make it easier to display the infoWindows on hover, as you won't need to go through the rigmarole with the graphics.

One of the parameters of the featureLayer is the infoTemplate, so you would define the infoTemplate's contents (the attributes for Route1, the URL for Route4) and apply it to the layer. Then set a listener for the onMouseOver event of each layer, to display the infoWindow on hover.

The pseudo-code would be:

- define a new infoTemplate
- set the infoTemplate's content
- define route1FeatureLayer as a new featureLayer, referencing the infoTemplate
- set a listener to display the infoTemplate on mouse-over
- repeat for Route4

The sample at http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/fl_ondemand.html shows how to define the infoTemplate for a featureLayer, and the sample you referenced shows the onMouseOver syntax, which will apply to the featureLayer too:

dojo.connect(route1FeatureLayer, "onMouseOver", function(evt) {
0 Kudos
GeorgieCassar
Frequent Contributor
THANKS !

A long time ago I created browser favourites to the ArcGIS Javascript API Reference.  (Before the days of Featurelayers)

Your links made me realise I was looking at old documentation.  (Doh!)  I wonder why the olds links still work.

Feature layers are great !
0 Kudos