Skip to content

Client side turf

Matthew McKenna edited this page Jul 1, 2014 · 1 revision

Turf functions in the client

If you're familiar with how browserfied node scripts work than you should be able to get up and running using any collection of turf modules in your client side javascript pretty quick. I will provide an example of using turf-distance using the complete collection of turf features contained in turf.min.js.

<script src="turf.min.js" charset="utf-8"></script>

You just need to include this minified file or the regular turf.js (easier to debug, but way bigger) file which is included when you download the turf module with npm install turf. Or go to the turf github repo and clone that or copy the desired file.

Whereas you'd normally create your distance method with:

var distance = require('turf-distance')

Now in your client side javascript you can just use:

turf.distance(point1,point2,unit)

That will use the code from the turf-distance module to calculate the distance between the given to points with a proper units string provided. See this example for it in use to calculate the distance between a selected point and the other points given points included in a topojson dataset.

Clone this wiki locally