How To Get the Attributes for the Map Feature That Has Just Been Clicked On

After the map has loaded, add a mouse down handler to the map element. In the handler use the retrieve API to get the current feature.


<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/",
                loadedCB: onMapLoaded,
                flashSecuritySandbox: AVENZA.AUTO_SANDBOX
            }
        );

        function onMapLoaded() {
            var m = theMap.element();
            if (m) {
                if (window.addEventListener) {
                    m.addEventListener("mousedown", onMouseClick, false);
                } 
                else if (window.attachEvent) { // IE
                    m.attachEvent("onmousedown", onMouseClick);
                }
            }
        }

        function onMouseClick(event) {
            alert(theMap.retrieve(AVENZA.FEATURE).attributes.STATE_NAME);
        }       
    </script>

</head>
<body>
    <div style="position:relative"> 
        <div id="map">
        </div>
    </div>
</body>
</html>

It's important to use the element() function as opposed to document.getElementById() to get a reference to the map element. The way that the map element is added to the page will change depending on the browser type, element() ensures that the correct reference will be returned..

You can see a live example here.

 
Products Download Purchase Resources Support About Us

 

 

Follow us on Twitter

MAPublisher
MAP LabelPro
MAP FME Auto
Geographic Imager
MAPdata
MAPdataCanada
MAPdataUSA
MAPdataWorld
MajorCitiesUSA
PDF Maps
MAPublisher
Geographic Imager
MAPdataCanada
MAPdataUSA
MAPdataWorld
MajorCitiesUSA
Order by Phone
Order by Fax
Order by Email
Order Online
Direct Download
Resellers
Resources Blog
Map Gallery
Styles & Symbols
YouTube Channel
Web Author API
User Guides and Tutorials
User Forums & FAQ
Training Courses
Contact Support
Product Activation
Retrieve License File
Renew Maintenance
Maintenance Login
History
Careers
Contact
News
Events