I'm trying to create a map using JVectorMap that will put information to an #output div after the user clicks a given marker (for example, if the user clicks on a marker labeled Alaska, facts about Alaska pop up in the #output div). Elsewhere on here, I've seen this code example, which outputs the name of the label...
onMarkerLabelShow: function(event, label, code) {
$("#output").html("Some information about "+ label.html());
}
I'm trying to use a switch here...
onMarkerLabelShow: function(event, label, code) {
switch (label) {
case Alaska:
$("#output").html($("#alaska-facts");
[break;]
case North Carolina:
$("#output").html($("#nc-facts");
[break;]
default:
$("#output").html("Please select a job site");
[break;]
}
}
The map doesn't display when I run this code, and I may be on the wrong track altogether. Any help?
A couple of issues:
label
is an object and will not match the simple case
statements matching string values. You might want to evaluate against label.text()
case
should be quoted strings (i.e. "North Carolina"
, not North Carolina
)break;
should not be wrapped in []
(you don't want an array of break
, you want to break out of the switch
).)
for the lines setting the .html()
with jQuery ID selectorsCorrected example:
onRegionLabelShow: function(event, label, code) {
switch (label.text()) {
case "Alaska":
$("#output").html($("#alaska-facts"));
break;
case "North Carolina":
$("#output").html($("#nc-facts"));
break;
default:
$("#output").html("Please select a job site");
break;
}
}