javascript - D3地图没有从json文件中显示
问题描述
我正在尝试使用代码显示伦敦地图
<script type="text/javascript">
var w = 1400;
var h = 700;
var svg = d3.select("div#container").append("svg").attr("preserveAspectRatio", "xMinYMin meet").style("background-color","#c9e8fd")
.attr("viewBox", "0 0 " + w + " " + h)
.classed("svg-content", true);
var projection = d3.geoMercator().translate([w/2, h/2]).scale(2200).center([0,40]);
var path = d3.geoPath().projection(projection);
var london = d3.json("london.geojson");
Promise.all([london]).then(function(values){
// draw map
svg.selectAll("path")
.data(values[0].features)
.enter()
.append("path")
.attr("class","borough")
.attr("d", path)
});
我的 json 文件的这一部分
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"id": 0,
"properties": {
"id": 1,
"name": "Kingston upon Thames",
"code": "E09000021",
"area_hectares": 3726.117,
"inner_statistical": 0
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[-0.330679062942453, 51.3290110106029],
[-0.330594448736231, 51.3290880398783],
[-0.330506117851447, 51.3291488295065],
这种情况在伦敦的多个地方都存在。
但是,当我运行它时,它不会显示任何内容或给出任何错误。谁能看到我在这里做错了什么或者我错过了什么?
解决方案
推荐阅读
- html - (Tailwind - DaisyUI) 有没有办法改变下拉项目的悬停和活动颜色?
- javascript - 使用节点缓存更新缓存数据
- spring - 如何连接Spring和Oracle db(oracle cloud)19c
- spring-boot - springboot服务的Junit5测试用例如何调用repository的真实方法
- javascript - 编辑嵌套 iframe react-native-webview 中元素的属性
- cmsis - STM32F10x Flash 大小不匹配
- php-7.2 - Laravel 临时空白页对某些用户没有错误
- javascript - JS Electron 解码 base 64 Uint8array
- c# - 新的 WIn UI 项目崩溃
- javascript - 使用lookbehind忽略两个匹配项之间的字符串,但无论如何都要捕获它