使用QGIS将您的GPX轨道转换为GeoJSON。
假设您的GeoJSON看起来像这样。GeoJSON具有elevation
带有高程值的属性。
var yourGeoJSON = [
{ "type": "Feature", "properties": { "id": 2, "elevation": 50 }, "geometry": { "type": "LineString", "coordinates": [ [ 11.836395263671875, 47.75317468890147 ], [ 11.865234375, 47.73193447949174 ] ] } },
{ "type": "Feature", "properties": { "id": 1, "elevation": 750 }, "geometry": { "type": "LineString", "coordinates": [ [ 11.865234375,47.73193447949174 ], [ 11.881027221679688, 47.700520033704954 ] ] } },
{ "type": "Feature", "properties": { "id": 0, "elevation": 1700 }, "geometry": { "type": "LineString", "coordinates": [ [ 11.881027221679688, 47.700520033704954 ], [ 11.923599243164062, 47.706527200903395 ] ] } },
{ "type": "Feature", "properties": { "id": 0, "elevation": 3000 }, "geometry": { "type": "LineString", "coordinates": [ [ 11.923599243164062, 47.706527200903395 ], [ 11.881027221679688, 47.700520033704954 ], ] } }
];
将具有以下代码的GeoJSON添加到传单地图中。使用函数设置文件样式。该"color"
元素调用函数get color
,并传递对elevation
您的功能作为参数的值。
L.geoJson(yourGeoJSON, {
style: function (feature) {
return {
"color": getColor(feature.properties.elevation),
"opacity": 1,
}}
}).addTo(map);
该函数getColor
根据高程值返回颜色。
function getColor(x) {
return x < 500 ? '#bd0026':
x < 1000 ? '#f03b20':
x < 1500 ? '#fd8d3c':
x < 2000 ? '#fecc5c':
'#ffffb2' ;
};
我使用示例GeoJSON和上述功能制作了JSFiddle:http : //jsfiddle.net/2VY5z/1/