From 49ac7edf70536f6c0719d99f1a42a50c67c590da Mon Sep 17 00:00:00 2001
From: Brandon Tilley
Q: I'm getting "Cannot read property 'geo' of undefined" or "Cannot call method 'feature' of undefined."
-A: Ensure you're requiring the D3 and TopoJSON libraries before Planetary.js
+A: Ensure you're requiring the D3 and TopoJSON libraries before Planetary.js.
+Q: Can I use Planetary.js with AMD or CommonJS?
+A: Yes and no. Planetary.js uses a universal module definition, and so is compatible with AMD and CommonJS. However, neither D3 nor TopoJSON support AMD, and TopoJSON's CommonJS package (as installed with npm) uses Node-specific functionality, so you can't, for instance, browserify it directly.
+This example uses RequireJS. Since neither D3 nor TopoJSON support AMD, we will use RequireJS's shim configuration.
+<body>
+ <canvas id='globe' width='500' height='500'></canavs>
+ <script src='//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.9/require.min.js'
+ data-main='/app.js'></script>
+</body>
+requirejs.config({
+ // Tell RequireJS to use `window.d3` and `window.topojson`
+ // for those libraries, respectively
+ shim: {
+ d3: { exports: 'd3' },
+ topojson: { exports: 'topojson' }
+ },
+ paths: {
+ 'd3': 'path/to/d3.v3.min',
+ 'topojson': 'path/to/topojson.v1.min'
+ }
+});
+
+requirejs(['planetaryjs'], function(planetaryjs) {
+ // Use Planetary.js here
+});
+To use Planetary.js with a tool like Browserify, you will need to create a shim for TopoJSON (D3 includes a Browserify-compatible script). Take a look at browserify-shim for more information.