- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在过去的两天里,我一直在尝试在 Leaflet 上制作一个非常简单的 map ,但正在撞墙。
我有一个由以前的 geoJSON 文件组成的两层 topoJSON 文件:美国 5 个州的邮政编码,以及 5 个州的多边形。
我想在 Leaflet 上显示这些,由于邮政编码层的文件大小较小,因此使用 topoJSON 而不是 geoJSON 很重要。
问题是我一生都无法在我的 topoJSON 文件中将较小的州图层显示在 map 上。我在网上看了很多例子,并遵循了 Mike Bostock 的例子:https://github.com/mbostock/bost.ocks.org/blob/gh-pages/mike/leaflet/index.html#L131-171 .
我可以仅使用 d3 就可以在 Web 浏览器中显示该文件,因此该文件没有问题。我在脚本中使用了 topoJSON 的 v1 和 topojson.feature 方法。代码如下。我无法使 topoJSON 文件可用,但我假设它没问题,因为我之前将它与 d3 一起使用。如果有人能发现脚本的异常之处,那就太好了。
谢谢。
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.6.2/leaflet.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://d3js.org/d3.v2.min.js?2.9.3"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<title>Gulf Zip Codes</title>
</head>
<div id="map"></div>
<style type="text/css">
#map {
height: 800px;
}
path {
fill: #000;
fill-opacity: .1;
stroke: #fff;
stroke-width: 1.5px;
}
path:hover {
fill: #1f77b4;
fill-opacity: .4;
}
</style>
<body>
<script>
var map = L.map('map').setView([32.546813, -88.374023], 6);
L.tileLayer('http://{s}.tile.cloudmade.com/1a1b06b230af4efdbb989ea99e9841af/998/256/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var svg = d3.select(map.getPanes().overlayPane).append("svg"),
g = svg.append("g").attr("class", "leaflet-zoom-hide");
d3.json("states_and_codes.json", function(error, states_and_codes) {
var bounds = d3.geo.bounds(states_and_codes);
path = d3.geo.path().projection(project);
var feature = g.selectAll("path")
.data(topojson.feature(states_and_codes, states_and_codes.objects.claim_states).features)
.enter().append("path")
.attr("class", "path")
.attr("d",path);
map.on("viewreset", reset);
reset();
// Reposition the SVG to cover the features.
function reset() {
var bottomLeft = project(bounds[0]),
topRight = project(bounds[1]);
svg .attr("width", topRight[0] - bottomLeft[0])
.attr("height", bottomLeft[1] - topRight[1])
.style("margin-left", bottomLeft[0] + "px")
.style("margin-top", topRight[1] + "px");
g .attr("transform", "translate(" + -bottomLeft[0] + "," + -topRight[1] + ")");
feature.attr("d", path);
}
// Use Leaflet to implement a D3 geographic projection.
function project(x) {
var point = map.latLngToLayerPoint(new L.LatLng(x[1], x[0]));
return [point.x, point.y];
}
});
</script>
</body>
最佳答案
如果您仍在搜索,或寻找任何其他人,这应该是缺少的部分 - TopoJson 的边界;
var bounds = d3.geo.bounds(topojson.feature(states_and_codes, states_and_codes.objects.claim_states));
关于d3.js - 如何使用 d3 在传单中显示 topojson 层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17662530/
我有一个带有 LeafletJS 的项目。 例如,我在 map 中有 2 个点 (A, B)。我将其显示为 2 个标记 我必须画一条从 A 到 B 的折线。 我移动了标记 A,我想将标记 A 的折线的
是否可以向自定义图标标记添加文本?我想避免在图像编辑器中编辑图标只是为了添加文本。 我已经像这样创建了我的自定义图标标记: var airfieldIcon = L.icon({ ic
我想要一个 Leaflet 图层控件,选中/取消选中时必须显示/隐藏主图层内的所有子图层。我还想独立检查/取消选中子层。我浏览了 Leaflet 文档和论坛,但找不到任何引用资料。我应该为此编写一个自
如何处理 Leaflet map 库中的重叠线? 我从服务器 sid 下载 geoJSON 并将其绘制到 map 上。如果有两个相同的条目,Leaflet 会绘制它们两次。这可以通过在服务器端查找完全
我在项目中使用 leafletjs。在 map 上我有几个多边形和标记。当其中一个被点击时,所有这些都有一个点击事件来显示一些信息。如果用户单击 map 的“空白”部分(而不是任何多边形或标记),我想
我正在尝试对下一个边界的外观做出预测。这是一个plunkr: https://plnkr.co/edit/sk6NRh51WZA2vpWP 这就是我让它工作的方式,但它不是很有效: const ori
我是 Leaflet 的新手,目前我正在努力学习教程。到目前为止,我设法创建了一个交互式 clorophet map ,就像示例中的 http://leafletjs.com/examples/cho
我很难弄清楚为什么我无法在 map 上绘制正确的国家/地区。我已经完成了所有代码,但我仍然不明白为什么不能正常工作。 如果您看到任何问题,请告诉我。我很欣赏。 这是数据集 Country
是否可以在使用 Stamen Toner-lite tiles 的 Leaflet map 上设置中间(2.5、3.5、4.5 等)缩放级别? ?这是我到目前为止计算缩放级别的代码: leafletm
早上、下午或晚上。 我有以下位置数据(从'Count of sampling points within a grid cell'调整) # Demo data set.seed(123) # lat
大家好,我正在开发一个具有 map 功能的网站。我的目标是,如果您单击标记,则使其拖动。 这是我的代码 else if (select1.value === "Arson"){ var note =
我正在开发一个应用程序,用户可以在其中上传KML文件,并使用Leaflet,toGeoJSON和Angular-Leaflet-Directive在屏幕上呈现路径。 我使用toGeoJSON.kml(
我需要在多边形要素中实现多色填充。填充将根据要素属性进行有条件的格式化。 假设我需要一个具有 3 色图案的多边形,如下所示: let fillPalette = ['orange', 'green',
我从 javascript 开始,并试图解决这个问题。 我希望当用户单击 map 时出现一个表单。当他们填写表单时,我想在该位置创建一个标记,并将该标记的弹出内容设置为表单中的值。添加表单完成后,我还
我已经在地理服务器中发布了一个功能,我可以通过传单及其 basemap 成功访问该功能。现在我需要在弹出窗口中获取feature onclick的属性信息。 我按原样使用了示例( https://gi
我正在使用带有一些标记的传单 map 。我还有一个侧边栏,可以在其中看到标记的名称,如果单击标记的名称, map 将缩放到标记的 lnglat。它已经可以工作,但我的问题是,当我刷新页面并在侧边栏中选
我正在使用 Leaflet 和 Mapbox,我想设置 map 的 View : 所有标记均可见 中心设置为特定点 使用 setView 和 fitbounds 单独完成每个点很容易,但我不知道如何同
是否有所有潜在 map 源的列表?在示例页面上,可以浏览四种类型的 map 。外面还有什么? http://tombatossals.github.io/angular-leaflet-directi
我正在使用 Leaflet 制作交互式 map 。我在 map 上有标记(基于其经度和纬度坐标),并且我希望某些标记具有与其他标记不同的颜色。例如,某些坐标我给它的分数是“10”,我希望它是粉红色的,
我可能忽略了如何在 map 上更改 LeftletJS 的光标。 http://leafletjs.com/reference.htm 我尝试设置map_div.style.cursor = 'cro
我是一名优秀的程序员,十分优秀!