Leafletjs GeoJSON 层不适用于来自 Natural Earth 的地图数据
Leafletjs GeoJSON layer is not working for map data from Natural Earth
我正在使用 leafletjs 绘制使用 OSM 瓦片的地理地图。我使用以下 GeoJSON 作为地图层 http://code.highcharts.com/mapdata/1.0.0/custom/world.js,它使用来自 naturalearthdata.com
的数据
但它不起作用。瓷砖层显示正确。但未显示 GeoJSON 数据。我只能在地图上看到一条白线。
var worldMapData = {}; //the geoJson data from http://code.highcharts.com/mapdata/1.0.0/custom/world.js
var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
osm = L.tileLayer(osmUrl, {
noWrap: true,
attribution: "<a href='http://openstreetmap.org'>OpenStreetMap</a>"
});
var map = L.map('map').setView([0, 0], 1).addLayer(osm);
function style( feature ) {
return {
fillColor: '#FFEDA0',
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
map.addLayer(L.geoJson(worldMapData, {style: style}));
我错过了什么吗?上面的 GeoJSON 不符合规范吗?如果没有,我可以从哪里下载与 leafletjs 兼容的所有国家/地区的 GeoJSON?
[编辑] 这是上述问题的 jsfiddle http://jsfiddle.net/1x1p55fy/
GeoJSON 数据正在正确加载,并按预期显示。但是,就坐标参考系统而言,GeoJSON 数据不符合 GeoJSON 规范。让我引用 the GeoJSON specs:
The coordinate reference system for all GeoJSON coordinates is a
geographic coordinate reference system, using the World Geodetic
System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units
of decimal degrees. This is equivalent to the coordinate reference
system identified by the Open Geospatial Consortium (OGC) URN
urn:ogc:def:crs:OGC::CRS84. An OPTIONAL third-position element SHALL
be the height in meters above or below the WGS 84 reference
ellipsoid. In the absence of elevation values, applications
sensitive to height or depth SHOULD interpret positions as being at
local ground or sea level.
Note: the use of alternative coordinate reference systems was
specified in [GJ2008], but it has been removed from this version of
the specification because the use of different coordinate reference
systems -- especially in the manner specified in [GJ2008] -- has
proven to have interoperability issues. In general, GeoJSON
processing software is not expected to have access to coordinate
reference system databases or to have network access to coordinate
reference system transformation parameters. However, where all
involved parties have a prior arrangement, alternative coordinate
reference systems can be used without risk of data being
misinterpreted.
如果您仔细查看 https://code.highcharts.com/mapdata/custom/world-highres.geo.json (or http://code.highcharts.com/mapdata/1.0.0/custom/world.js 中的数据)您会发现,事实上,相对于 WGS84 大地水准面的坐标不在 latitude-longitude 中,并且存在对 EPSG:54003 坐标参考系统(圆柱铣刀)的引用,具有自定义比例和偏移变换。
正如 GeoJSON 规范已经指出的那样,我们不鼓励您在 GeoJSON 数据中使用除 EPSG:4326(latitude-longitude 中的 WGS84)以外的任何其他 CRS。
找一些符合规范的GeoJSON,在Leaflet中看起来就OK了。 Leaflet 不处理 GeoJSON 数据的重新投影,也不处理 highcharts 数据暗示的比例转换。
我正在使用 leafletjs 绘制使用 OSM 瓦片的地理地图。我使用以下 GeoJSON 作为地图层 http://code.highcharts.com/mapdata/1.0.0/custom/world.js,它使用来自 naturalearthdata.com
的数据但它不起作用。瓷砖层显示正确。但未显示 GeoJSON 数据。我只能在地图上看到一条白线。
var worldMapData = {}; //the geoJson data from http://code.highcharts.com/mapdata/1.0.0/custom/world.js
var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
osm = L.tileLayer(osmUrl, {
noWrap: true,
attribution: "<a href='http://openstreetmap.org'>OpenStreetMap</a>"
});
var map = L.map('map').setView([0, 0], 1).addLayer(osm);
function style( feature ) {
return {
fillColor: '#FFEDA0',
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
map.addLayer(L.geoJson(worldMapData, {style: style}));
我错过了什么吗?上面的 GeoJSON 不符合规范吗?如果没有,我可以从哪里下载与 leafletjs 兼容的所有国家/地区的 GeoJSON?
[编辑] 这是上述问题的 jsfiddle http://jsfiddle.net/1x1p55fy/
GeoJSON 数据正在正确加载,并按预期显示。但是,就坐标参考系统而言,GeoJSON 数据不符合 GeoJSON 规范。让我引用 the GeoJSON specs:
The coordinate reference system for all GeoJSON coordinates is a geographic coordinate reference system, using the World Geodetic System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units of decimal degrees. This is equivalent to the coordinate reference system identified by the Open Geospatial Consortium (OGC) URN urn:ogc:def:crs:OGC::CRS84. An OPTIONAL third-position element SHALL be the height in meters above or below the WGS 84 reference ellipsoid. In the absence of elevation values, applications sensitive to height or depth SHOULD interpret positions as being at local ground or sea level.
Note: the use of alternative coordinate reference systems was specified in [GJ2008], but it has been removed from this version of the specification because the use of different coordinate reference systems -- especially in the manner specified in [GJ2008] -- has proven to have interoperability issues. In general, GeoJSON processing software is not expected to have access to coordinate reference system databases or to have network access to coordinate reference system transformation parameters. However, where all involved parties have a prior arrangement, alternative coordinate reference systems can be used without risk of data being misinterpreted.
如果您仔细查看 https://code.highcharts.com/mapdata/custom/world-highres.geo.json (or http://code.highcharts.com/mapdata/1.0.0/custom/world.js 中的数据)您会发现,事实上,相对于 WGS84 大地水准面的坐标不在 latitude-longitude 中,并且存在对 EPSG:54003 坐标参考系统(圆柱铣刀)的引用,具有自定义比例和偏移变换。
正如 GeoJSON 规范已经指出的那样,我们不鼓励您在 GeoJSON 数据中使用除 EPSG:4326(latitude-longitude 中的 WGS84)以外的任何其他 CRS。
找一些符合规范的GeoJSON,在Leaflet中看起来就OK了。 Leaflet 不处理 GeoJSON 数据的重新投影,也不处理 highcharts 数据暗示的比例转换。