markmarkoh / datamaps

Customizable SVG map visualizations for the web in a single Javascript file using D3.js
http://datamaps.github.io
MIT License
3.78k stars 1.01k forks source link

Using the "USA" map throws an exception of "Cannot read property 'world' of undefined" #259

Open mattchoinski opened 8 years ago

mattchoinski commented 8 years ago

Using the following code, I get an exception of Cannot read property 'world' of undefined:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>Map Testing</title>
  </head>
  <body>
    <div id="container" style="position: relative; width: 500px; height: 300px;"></div>
    <script src="d3.min.js"></script>
    <script src="topojson.min.js"></script>
    <script src="datamaps.usa.js"></script>
    <script>
        var map =
          new Datamap(
            {
              element: document.getElementById('container'),
              responsive: true
            }
          );

          window.addEventListener('resize', function() { map.resize(); });
    </script>
  </body>
</html>

However, it works if I change the code to the following:

        var map =
          new Datamap(
            {
              element: document.getElementById('container'),
              responsive: true,
              scope: "usa"
            }
          );

I'm using Google Chrome Version 47.0.2526.106 m on a Windows 7 machine.

getup8 commented 8 years ago

You're only loading the USA-specific datamaps code () but the default scope is world which it won't find if you don't include the world-specific JS.

davidrhoden commented 8 years ago

I am getting the same error, though I have included scope: 'usa'. I am using the US-only map.

thomaskbird commented 8 years ago

I have the same issue as well and I also have scope: 'usa' set as well. Has anyone figured out a solution @davidrhoden

davidrhoden commented 8 years ago

I'm sorry; I did get it working but I'm not sure how. Leave the scope:usa, make sure you are loading the topojson. Try wrapping the code in document(ready).

thomaskbird commented 8 years ago

@davidrhoden Ha lol, yea I'm in your same boat, in the end I think I had conflicting dependencies which may have caused it. I had to nuke my node_modules and then rerun install process, that fixed it for me.

curiousPup commented 5 years ago

this is still an issue.