Error in Kartograph.js

2019-09-02 03:40发布

I'm using Kartograph.js to load svg map. But I get the following error when page loads:

Uncaught TypeError: Cannot read property 'getAttribute' of undefined
View.fromXML
Kartograph._mapLoaded
j
k.fireWith 
x
b

Here is my Code:

<html>
<head>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="raphael-min.js"></script>
    <script type="text/javascript" src="kartograph.js"></script>
    <script type="text/javascript">
        function loadMap(){
            var map = kartograph.map('#map', 600, 0);

            map.loadMap('World.svg')
        }
    </script>
</head>
 <body onLoad="loadMap()">

    <div id="map"></div>
</body>
</html>

标签: kartograph
2条回答
叛逆
2楼-- · 2019-09-02 04:18

If you created the svg with kartograph.py, you might need to add the layers added in the svg as follow:

        function loadMap(){
            var map = kartograph.map('#map', 600, 0);

            map.loadMap('World.svg', function() {
                 map.addLayer('your_first_layer');
                 map.addLayer('your_second_layer');
            });
        }

To find the name of the layers to be added:

  • Open your svg file as text, for exemple in Firefox and use rightclick, page inspector.
  • On the second line you'll see : svg > g#something > ...

The name of one of the layer is the "something" after "g#". In the code it is the "id" of the "g" element.

Hope this might help you...

查看更多
看我几分像从前
3楼-- · 2019-09-02 04:41

You need to define the metadata on the svg file. For example:

<metadata><views><view h="604.816027229" padding="0" w="1000"><proj id="laea-usa" lat0="45" lon0="-100"/><bbox h="321.76" w="532.88" x="746.23" y="918.78"/></view></views></metadata>
查看更多
登录 后发表回答