diff --git a/amd/index.html b/amd/index.html new file mode 100644 index 0000000..b35ef3c --- /dev/null +++ b/amd/index.html @@ -0,0 +1,10 @@ + +
draw
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.