rveciana - spam-js-error-with-d3-composite-projections

spam.js error with d3-composite-projections

Open raw page in new tab

The following code gives

TypeError: ring[0] is undefined

when clicking on the prefactures.

The code is taken from this example

The error was solved using the

topojson.presimplify(d);

function. More information in this block, which is a new Topojson 1.3 function.

<!DOCTYPE html>
<meta charset="utf-8" />
<body>
<script src="d3.min.js"></script>
<script src="topojson.min.js"></script>
<script src="rbush.min.js"></script>
<script src="spam.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-composite-projections/0.3.5/conicEquidistantJapan.min.js"></script>
<script type='text/javascript'>
var hover = null


d3.json("empty.json", function(error, d) {
    
    topojson.presimplify(d);
    
    var map = new ZoomableCanvasMap({
        element: "body",
        width: 960,
        height: 500,
        projection: d3.geo.conicEquidistantJapan(),
        data: [
            {
                features: topojson.feature(d, d.objects["japan"]),
                static: {
                    paintfeature: function(parameters, d) {
                        parameters.context.lineWidth = 1 / parameters.scale
                        parameters.context.stroke()
                    }
                },
                dynamic: {
                    postpaint: function(parameters) {
                        if (!hover)
                            return

                        parameters.context.beginPath()
                        parameters.context.lineWidth = 2 / parameters.scale
                        parameters.context.fillStyle = "rgb(241, 205, 151)"
                        parameters.path(hover)
                        parameters.context.stroke()
                        parameters.context.fill()
                    }
                },
                events: {
                    hover: function(parameters, d) {
                        hover = d

                        parameters.map.paint()
                    },
                    click: function(parameters, d) {
                        parameters.map.zoom(d)
                    }
                }
            }
        ]
    })
    map.init()
})
</script>