JavaScript SVG 错误

标签 javascript jquery html css svg

我有一系列用 jquery 显示的 SVG map 。 进入第一页时,左侧显示美国 map ,右侧显示初始状态,并突出显示县域属性。 如果你点击任何其他状态,然后回到原来的状态,属性就消失了。 我如何更改此处的代码,使每个州的属性在右侧显示县,当用户单击左侧的州时? 我不希望属性消失。 这是代码和正在发生的事情的屏幕截图。在第三个屏幕上,我需要像第一个屏幕一样显示属性。

-----代码-----

<script type="text/javascript">

            $('#mapsvg-usa').mapSvg({source: 'maps/usa.svg', width: 1200, responsive: 1,
            colors: {background: 'transparent', hover: 4, selected: 10, stroke: '#ffffff'},
            tooltipsMode: 'names',
            regions: {'CO': {selected: true}},
            onClick: function(){

               var file = 'usa-'+this.name.toLowerCase()+'.svg';

               console.log($('#mapsvg-states').html());

               if($('#mapsvg-states').find('svg').length){
                $('#mapsvg-states').mapSvg().destroy();
               }

               $('#mapsvg-states').mapSvg({
                    source : 'maps/counties/'+file,
                    //responsive: 1,
                    colors: {background: 'transparent', base: "#DDDDDD", stroke: '#ffffff'},
                    width: $('#mapsvg-usa').width(),
                    height: $('#mapsvg-usa').height(),
                    tooltipsMode: 'combined',
                    zoomButtons: {show: true, location: 'right'},
                    zoom: 1,
                    pan: 1
               });

            }
            });

           $('#mapsvg-states').mapSvg({
                source : 'maps/counties/usa-co.svg',
                responsive: 1,
                colors: {background: 'transparent', stroke: '#ffffff'},
                width: $('#mapsvg-usa').width(),
                tooltipsMode: 'names',
                zoomButtons: {show: true, location: 'right'},
                zoom: 1,
                pan: 1,
                regions: {
                    Douglas: {tooltip: 'RFC Submitted', attr: {fill: '#fc0'}},
                    Jefferson: {tooltip: 'RFC Submitted', attr: {fill: '#fc0'}}}
           });


        </script>

        <script type="text/javascript">

            $('#maplinks a').on('click', function(e){
               e.preventDefault();
               var file = $(this).attr('data-svg');


               if($('#mapsvg-other').find('svg').length){
                $('#mapsvg-other').empty().mapSvg().destroy();
               }

               $('#mapsvg-other').mapSvg({
                    source : 'maps/'+file,
                    responsive: 1,
                    width: $('#mapsvg-other-cont').width(),
                    height: $('#mapsvg-other-cont').height(),
                    tooltipsMode: 'names',
                    zoomButtons: {show: true, location: 'left'},
                    zoom: 1,
                    pan: 1
               });

            });

        </script>

Here are the 3 screen captures show how the attributes disappear

最佳答案

单击某个州时正在加载的 map 不像最初加载的 map 那样包含区域数据。 将区域代码复制到其中

regions: {
             Douglas: {tooltip: 'RFC Submitted', attr: {fill: '#fc0'}},
             Jefferson: {tooltip: 'RFC Submitted', attr: {fill: '#fc0'}}
}

希望对您有所帮助。

关于JavaScript SVG 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24267467/

相关文章:

javascript - 使用 svg 格式的 D3.js 预渲染饼图服务器时出错

javascript - 增加可为 null int 的值(int?)

javascript - jQuery 动画无法正常工作

javascript - 确认窗口的问题

javascript - Jquery Autocomplete 小部件与同一页面上的 ajax post

jquery - 以编程方式选择节点时自动滚动 Kendo Treeview

php - 需要保存两次提交的 $_POST 数据

javascript - JQuery Mobile Javascript 复杂方程

javascript - 在 Telerik MVC 网格中展开/折叠 DetailView

javascript - 如何使用 javascript 以编程方式为用户订阅谷歌日历?