【问题标题】:Inline SVG to jvectormap内联 SVG 到 jvectormap
【发布时间】:2014-11-01 09:40:01
【问题描述】:

我必须自定义一个地图才能在 jvector 地图中使用它。所以我使用内联SVG 来制作地图。该地图显示完美,但我无法使用 jvectormap 对其进行操作。我只是 jvectormap 的初学者,所以我的代码可能有点错误。如果您有任何想法,请接受任何答案。

提前致谢。

这是我的代码:

<div id="pantsun" >
<svg title="well" width="500" height="300" style="border: 1px solid #000;background-color: lightgreen;" >
  <rect x="200" y="0" width="30" height="300" style="fill:white;" />
  <rect x="0" y="50" width="500" height="30" style="fill:white;" />
  <rect x="0" y="150" width="500" height="30" style="fill:white;" />
  <rect x="10" y="18" width="30" height="30" style="fill:darkgrey;" />
  <rect x="45" y="18" width="30" height="30" style="fill:darkgrey;" />
  Sorry, your browser does not support inline SVG.
  </svg>
</div>

<script>

$(function(){
 $('#pantsun').vectorMap({
  map: 'well',
  backgroundColor: 'transparent',
  markers: [{
    coords: [0, 50],
    name: 'well 1',
    style: {fill: 'white'}
  },{
    coords: [0, 150],
    name: 'well 2',
    style: {fill: 'white'}
}}};

</script>

我想做的是在这个link.

【问题讨论】:

    标签: javascript jquery svg jvectormap


    【解决方案1】:

    您传递给 vectorMap 的对象和其中的 markers 数组格式错误,缺少括号和闭包。如果你组织代码缩进,这种东西很容易被发现。

    文档和示例不是很好。这是我在测试您的代码时发现的how to solve the jvm is not defined error(这发生在他们的一个示例文件中)。

    此外,Mall example that you cite 没有提到需要load a mall-map.js(在您的情况下为well-map.js)。它会在您的代码中产生此错误:

    未捕获的错误:尝试使用未加载的地图:很好

    这是我测试的代码,地图没有呈现任何有意义的东西,因为我用mall-map.js 测试过,但是没有发生 JS 错误...

    <script src="assets/jquery-1.8.2.js"></script>
    <script src="../jquery-jvectormap-1.2.2.min.js"></script>
    <script src="../jquery-jvectormap.js"></script>
    <script src="mall-map.js"></script>
    <script>
    $(function(){
        $('#pantsun').vectorMap({
            map: 'mall',
            backgroundColor: 'transparent',
            markers: [
                { coords: [0, 50], name: 'well 1', style: {fill: 'white'} },
                { coords: [0, 150], name: 'well 2', style: {fill: 'white'} }
            ] // <-- missing
        });  // <-- mal formed
    });     // <-- mal formed
    </script>
    

    【讨论】:

      猜你喜欢
      • 2022-11-20
      • 2017-04-03
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 2014-04-12
      • 2017-03-01
      • 2012-11-26
      • 1970-01-01
      相关资源
      最近更新 更多