Pregunta

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>
¿Fue útil?

Solución

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>

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top