-->

Display Polyline length in feet using Leaflet.Draw

2019-07-03 17:00发布

问题:

I am creating a map that the user will be able to draw lines on using the Leaflet.Draw toolbar. I would like the running distance of the line to be displayed in feet/miles instead of the default yards/miles. Looking at the project in GitHub, it seems to me the following code should do this:

 var drawControl = new L.Control.Draw({
            draw: {
                polyline: {
                    shapeOptions: {
                        color: 'red',
                    },
                    metric: false,
                    feet: true,
                }
            }            
        });

But the length is still displayed in yards. Any insight into why this is would be helpful.

回答1:

Which version of Leaflet.draw plugin are you using?

Note that:

  • Leaflet.draw version v0.2.4 / 0.2.4-dev (as used in the plugin GitHub demo) does not have the feet option yet.
  • Leaflet.draw version v0.3.0 / 0.3.0-dev (latest release for Leaflet 0.7) has the feet option.
  • Leaflet.draw from leaflet-master branch, for compatibility with Leaflet 1.0, is based on version 0.2.4 and does not have the feet option.