我面临谷歌地图认证不一致问题,当我运行我的应用程序时,它连接并完美地运行,但是当我再次重新运行它时它不会连接并抛出权限被拒绝错误。这个问题持续了很长时间,幸运的是它又恢复了连接。我已经尝试检查我的google api密钥,看起来很好,因为有时候应用会成功验证。
以下是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Sample Graph Rendring Using Canvas</title>
<script src="https://rawgit.com/gka/randomgraph.js/master/randomgraph.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script>
var graph = randomgraph.WattsStrogatz.beta(15, 4, 0.06);
var canvas = null;
var width = window.innerWidth,
height = window.innerHeight;
canvas = d3.select("body").append("canvas").attr("width", width).attr("height", height);
var context = canvas.node().getContext("2d");
force = d3.forceSimulation()
.force("link", d3.forceLink().id(function (d) {
return d.index;
})).force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2));
force.nodes(graph.nodes);
force.force("link").links(graph.edges).distance(200);
var detachedContainer = document.createElement("custom");
dataContainer = d3.select(detachedContainer);
link = dataContainer.selectAll(".link").data(graph.edges)
.enter().append("line").attr("class", "link")
.style("stroke-width", 2)
node = dataContainer.selectAll(".node").data(graph.nodes)
.enter().append("circle")
.attr("class", function (d) {
return "node node_" + d.index;
})
.attr("r", 5)
.attr("fill", 'red')
.attr("strokeStyle", 'black');
d3.timer(function () {
context.clearRect(0, 0, width, height);
// draw links
link.each(function (d) {
context.beginPath();
context.moveTo(d.source.x, d.source.y);
context.lineTo(d.target.x, d.target.y);
context.closePath();
context.strokeStyle = "#ccc";
context.stroke();
});
context.lineWidth = 2;
node.each(function (d) {
context.beginPath();
context.moveTo(d.x, d.y);
var r = this.getAttribute('r');
d.x = Math.max(30, Math.min(width - 30, d.x));
d.y = Math.max(30, Math.min(height - 30, d.y));
context.arc(d.x, d.y, r, 0, 2 * Math.PI);
context.closePath();
context.fillStyle = this.getAttribute('fill');
context.strokeStyle = this.getAttribute('strokeStyle');
context.stroke();
context.fill();
});
});
node.transition().duration(5000).attr('r', 20).attr('fill', 'orange');
canvas.node().addEventListener('click', function (event) {
// Its COMING ANY TIME INSIDE ON CLICK OF CANVAS
});
</script>
</body>
</html>