How To Highlight Map Features
Use the features and highlight APIs to highlight items in the map. An MAPublisher expression is passed as a parameter to features to specify which items to highlight.
If you require more complex logic to determine which features to highlight, you can use the forEach API. On large, complex maps forEach is slower than passing an expression to features, only use it if you really need to.
<html>
<head>
<script type="text/javascript" src="map_data/swfobject.js"></script>
<script type="text/javascript" src="map_data/avenza.js"></script>
<script type="text/javascript">
var theMap = AVENZA.embedViewer("map", "750", "500",
{
baseURL:"map_data/",
flashSecuritySandbox: AVENZA.AUTO_SANDBOX
}
);
function highlightUsingForEach() {
theMap.features().forEach(function(feature) {
if (feature.attributes.STATE_NAME.substr(0, 1) == "M") {
feature.highlight.visible = true;
return feature;
}
});
}
function highlight() {
theMap.features('TIMEZONE="CST"').highlight();
}
function clearHighlight() {
// clear layers even if they're hidden
theMap.features(null, false).highlight({visible: false});
}
</script>
</head>
<body>
<div style="position:relative">
<div id="map">
</div>
<hr>
<button type="button" onclick="highlight()">Highlight CST</button>
<button type="button" onclick="highlightUsingForEach()">Highlight "M" States Using forEach</button>
<button type="button" onclick="clearHighlight()">Clear</button>
</div>
</body>
</html>
You can see live examples here.
