Closed gegeweb closed 4 years ago
Hi Gérald,
could you kindly:
Thanks for your cooperation, Raruto
Hope last commit is now fine!
Changes are:
(point.alt || point.meta.ele)
so we can add data from an array of L.latLng() (L.polyline) like this:
elevation.addData({_lanlng: L.polyline });
_path
property.I'm using the plugin with a feature group, so the layer have no path.
Hope i'm clear. ;)
Here you can check the code where i use this:
.on('routeselected', function(e) {
let coordinates = e.route.coordinates;
elevationControl.clear();
elevationControl.show();
elevationControl.addData({ '_latlngs': coordinates }, controlRouting.getLine());
})
coordinates is an array of
L.latLng object: { lat: lat, lon: lon, alt: z }
and the layers returned by the function a
L.FeatureGroup object
Here you can see a simple example on how to effectively use an L.polyline as elevation object.
In your particular case, it could also be solved in this way:
let _latlngs = e.route.coordinates; // same as polyline.getLatLngs()
let coords = L.GeoJSON.latLngsToCoords(e.route.coordinates);
elevationControl.addData({type: "Feature", geometry: { coordinates: coords, type: "LineString" }}, controlRouting.getLine());
Your solution is also quite correct, but I think it would be better if we adopt a slightly cleaner / general one.
Yes you're right, this solution works fine, thanks ! So there is no need to modify addGPXData.
But we always need to check if layer have _path propertie in _clearPath or where adding class.
I'll update the PR by removing what's useless.
shorter, single line:
elevationControl.addData(L.polyline(e.route.coordinates).toGeoJSON(), controlRouting.getLine());
Thanks again, it looks better. ;)
Add L.polyline data (array of L.latLng) as gpx data to the chart.