jvectormap

Want to get region name from drill down map of jvectormap


I am unable to get region name from code of region. My region click event work fine and I also get code properly. My code is:

<div id="map" style="width: 600px; height: 400px"></div>
<script type="text/javascript">
    $(function () {
        new jvm.MultiMap({
            container: $('#map'),
            maxLevel: 1,
            main: {
                map: 'us_lcc_en'
            },
            mapUrlByCode: function (code, multiMap) {
                return 'js/counties/jquery-jvectormap-data-' +
                   code.toLowerCase() + '-' +
                   multiMap.defaultProjection + '-en.js';
            }
        });


        $('#map').bind('regionClick.jvectormap', function (event, code) {
            var map = $('#map').vectorMap('get', 'mapObject');
            alert(map.getRegionName(code));
        });
    });
</script>

Solution

  • Add this code

    onRegionClick:function(event, code) {                        
            var name = (code);                        
            alert(name);                    
            }
    

    All Script Like This

     <div id="map" style="width: 600px; height: 400px"></div>
    <script type="text/javascript">
        $(function () {
            new jvm.MultiMap({
                container: $('#map'),
                maxLevel: 1,
                main: {
                    map: 'us_lcc_en'
                },
                mapUrlByCode: function (code, multiMap) {
                    return 'js/counties/jquery-jvectormap-data-' +
                       code.toLowerCase() + '-' +
                       multiMap.defaultProjection + '-en.js';
                }
            });
    
    
         onRegionClick:function(event, code) {                        
            var name = (code);                        
            alert(name);                    
            }
        });
    </script>