Error in Kartograph.js

时光毁灭记忆、已成空白 提交于 2019-12-25 02:53:29

问题


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>

回答1:


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>



回答2:


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...



来源:https://stackoverflow.com/questions/23370194/error-in-kartograph-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!