d3 js circleMarker未定义(...)

时间:2016-10-30 11:36:14

标签: d3.js

我正在尝试向d3.js地图添加标记。很遗憾,点击按钮'circleMarker未定义(...)'后出现错误。

这是我的代码:

 <!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>

<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/tile.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.quadtiles.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.geo.raster.js" type="text/javascript">
</script>
<script src="https://rawgit.com/emeeks/d3-carto-map/master/d3.carto.map.js" type="text/javascript">
</script>
<style>
.markerButton {
    position: fixed;
    top: 20px;
    cursor: pointer;
    z-index: 99;
  }

body {
  background: #fcfcfa;
}

.stroke {
  fill: none;
  stroke: #000;
  stroke-width: 3px;
}

.fill {
  fill: #fff;
}

.graticule {
  fill: none;
  stroke: #777;
  stroke-width: .5px;
  stroke-opacity: .5;
}

.land {
  fill: #222;
}

.boundary {
  fill: none;
  stroke: #fff;
  stroke-width: .5px;
}

</style>
<body onload="makeSomeMaps()">




<script>

var width = 960,
    height = 500;

var projection = d3.geo.mollweide()
    .scale(165)
    .translate([width / 2, height / 2])
    .precision(.1);

var path = d3.geo.path()
    .projection(projection);

var graticule = d3.geo.graticule();

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

svg.append("defs").append("path")
    .datum({type: "Sphere"})
    .attr("id", "sphere")
    .attr("d", path);

svg.append("use")
    .attr("class", "stroke")
    .attr("xlink:href", "#sphere");

svg.append("use")
    .attr("class", "fill")
    .attr("xlink:href", "#sphere");

svg.append("path")
    .datum(graticule)
    .attr("class", "graticule")
    .attr("d", path);

d3.json("world-50m.json", function(error, world) {
  if (error) throw error;

  svg.insert("path", ".graticule")
      .datum(topojson.feature(world, world.objects.land))
      .attr("class", "land")
      .attr("d", path);

  svg.insert("path", ".graticule")
      .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
      .attr("class", "boundary")
      .attr("d", path);
});

d3.select(self.frameElement).style("height", height + "px");

function makeSomeMaps() {
    map = d3.carto.map(); 
function circleMarker() {
    var sizeScale = d3.scale.linear().domain([0,100,2000]).range([2,10,20]).clamp(true);
    var randomDatapoint = "r" + Math.ceil(Math.random() * 7);
    d3.selectAll("g.marker").selectAll("*").remove();
    d3.selectAll("g.marker").append("circle")
    .attr("class", "metro")
    .attr("r", function(d) {return sizeScale(d[randomDatapoint])})
  }

function makeSomeMaps() {
    map = d3.carto.map();

    d3.select("#map").call(map);
    map.centerOn([-99,39],"latlong");
    map.setScale(4);

    map.refresh();

cityLayer = d3.carto.layer.csv();
    cityLayer
    .path("cities.csv")
    .label("Metro Areas")
    .cssClass("metro")
    .renderMode("svg")
    .x("x")
    .y("y")
    .clickableFeatures(true)
    .on("load", function(){console.log(cityLayer.dataset())});

    map.addCartoLayer(cityLayer);
}
}



</script>
<div id="map">
<button style="left: 340px;" class="markerButton" onclick="circleMarker();">Circle Marker</button>
</div>

</body>
</html>

我在这里关注示例表单: http://bl.ocks.org/emeeks/f8c0220c54ec8347ea95

也许它不起作用,因为我使用不同类型的地图而不是示例? 任何建议都非常感激。

非常感谢提前。

0 个答案:

没有答案