I have trail data.
I want to show map tips if the trail has a name.
Unfortunately, I cannot change the data. I want the Name to be displayed. If Name is Null then displayed the Group_ field if not the group then Route_2 and if not Route_2 then Route_1
My code right now looks like this:
dojo.connect(Layer, "onMouseMove", function (evt) {
if (evt.graphic) {
if (evt.graphic.attributes) {
ShowMapTip(evt, "<b>Name</b>: " + evt.graphic.attributes.NAME );
}
}
});
dojo.connect(Layer, "onMouseOut", CloseMapTip);
Any suggestions would be greatly appreciated!
Solved! Go to Solution.
Maybe there's an issue with your fields being blank vs NULL; hard to say from my end on the outside. Let's try evaluating your field values another way, Let's look at the length of the field's value.:
if (evt.graphic.attributes) {
var theString;
if(evt.graphic.attributes.NAME.length > 0) {
theString = "<b>Name1</b>: " + evt.graphic.attributes.NAME;
} else if (evt.graphic.attributes.GROUP_.length > 0) {
theString = "<b>Name2</b>: " + evt.graphic.attributes.GROUP_;
} else if (evt.graphic.attributes.ROUTE_2.length > 0) {
theString = "<b>Name3</b>: " + evt.graphic.attributes.ROUTE_2;
} else {
theString = "<b>Name4</b>: " + evt.graphic.attributes.ROUTE_1;
}
ShowMapTip(evt, theString);
}
How about something like....
if (evt.graphic.attributes) {
var theString;
if(!evt.graphic.attributes.NAME) {
theString = "<b>Name</b>: " + evt.graphic.attributes.NAME;
} else if (!evt.graphic.attributes.GROUP_) {
theString = "<b>Name</b>: " + evt.graphic.attributes.GROUP_;
} else if (!evt.graphic.attributes.ROUTE_2) {
theString = "<b>Name</b>: " + evt.graphic.attributes.ROUTE_2;
} else {
theString = "<b>Name</b>: " + evt.graphic.attributes.ROUTE_1;
}
ShowMapTip(evt, theString);
}
Thank you for the quick response!
I changed the code slightly (bold numbers) to see why it was not working correctly. The trails with NAME's displayed with a label of Name4. Every other trail had a label of Name4 but nothing after that. I am not sure why it is pull the label of the last option.
if (evt.graphic.attributes) {
var theString;
if(!evt.graphic.attributes.NAME) {
theString = "<b>Name1</b>: " + evt.graphic.attributes.NAME;
} else if (!evt.graphic.attributes.GROUP_) {
theString = "<b>Name2</b>: " + evt.graphic.attributes.GROUP_;
} else if (!evt.graphic.attributes.ROUTE_2) {
theString = "<b>Name3</b>: " + evt.graphic.attributes.ROUTE_2;
} else {
theString = "<b>Name4</b>: " + evt.graphic.attributes.ROUTE_1;
}
ShowMapTip(evt, theString);
}
Maybe there's an issue with your fields being blank vs NULL; hard to say from my end on the outside. Let's try evaluating your field values another way, Let's look at the length of the field's value.:
if (evt.graphic.attributes) {
var theString;
if(evt.graphic.attributes.NAME.length > 0) {
theString = "<b>Name1</b>: " + evt.graphic.attributes.NAME;
} else if (evt.graphic.attributes.GROUP_.length > 0) {
theString = "<b>Name2</b>: " + evt.graphic.attributes.GROUP_;
} else if (evt.graphic.attributes.ROUTE_2.length > 0) {
theString = "<b>Name3</b>: " + evt.graphic.attributes.ROUTE_2;
} else {
theString = "<b>Name4</b>: " + evt.graphic.attributes.ROUTE_1;
}
ShowMapTip(evt, theString);
}
Thank you!
The only thing i changed was the 0 to 1 and it worked! (in bold below)
if (evt.graphic.attributes) {
var theString;
if(evt.graphic.attributes.NAME.length > 1) {
theString = "<b>Name1</b>: " + evt.graphic.attributes.NAME;
} else if (evt.graphic.attributes.GROUP_.length > 1) {
theString = "<b>Name2</b>: " + evt.graphic.attributes.GROUP_;
} else if (evt.graphic.attributes.ROUTE_2.length > 1) {
theString = "<b>Name3</b>: " + evt.graphic.attributes.ROUTE_2;
} else {
theString = "<b>Name4</b>: " + evt.graphic.attributes.ROUTE_1;
}
ShowMapTip(evt, theString);
}