How To Set Attributes in the Map at Run Time
Use the forEach API to specify a function to be run on features in the map. Update the attribute values in the function.
<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 update(feature) {
var s = feature.attributes.STATE_ABBR.substr(0, 2);
var d = new Date();
s = s + " Modified on " + d;
feature.attributes.STATE_ABBR = s;
return feature;
}
function updateAttributes() {
theMap.features().forEach(update);
}
</script>
</head>
<body>
<div style="position:relative">
<div id="map">
</div>
<hr>
<button type="button" onclick="updateAttributes()">Update Attributes</button>
</div>
</body>
</html>
To change to the feature object in the update function you return it. The features() API takes a MAPublisher expression that lets you filter down the list of feature objects that your update function will be called for (see here). It's faster to filter features before your update function is called than to use an if block inside.
You can see a live example here.
