I'm working on a project that needs to do some simple turf.js work on the client. I am using Mapbox to host my GeoJSON data. Mapbox serves the client this data as a vector tile set, which saves a lot on bandwidth and load times on the client for large datasets. Unfortunately turf.js only works with GeoJSON, not Mapbox Vector Tiles. As far as I know, there are two libraries that can convert vector tiles into GeoJSON: vt-geojson, and vector-tile-js. The problem with these libraries is that they are Node.js libraries, not browser javascript.

At this point it seems I have four options:

  • Convert one of these libraries to normal javascript (and spend time doing it)
  • Add Browserify to my project to convert it for me (and messy up my project)
  • Find some other javascript library that can do it for me (and maybe not find one)
  • Write my own library (and spend lots of time and effort)

I'm hoping that someone on here can help me with the third option, finding a JS library.

  • Why do you want to avoid Browserify? – ThomasG77 Jan 7 '16 at 2:09
  • I'd have to convert my MVC 4 project to resemble something newer like so: stackoverflow.com/questions/31872622/… and then integrate Browserify and I'd like to avoid changing the whole structure of my project if I don't have to. If there was an easier way to use Browserify, I would use it, but I haven't found one. – LavaHot Jan 7 '16 at 2:58
  • 1
    You can build vt-geojson as a standalone lib with Browerify. With this, you will only reference a new js file (with the vt-geojson functions bundled with Browserify) and you will be able to keep the other parts of your project like they are today. – ThomasG77 Jan 7 '16 at 3:49
  • Really? How can I do this? Do I have to manually compile it with Browserify every time a new release comes out, or can I add it to my build process? Got some links for me? – LavaHot Jan 7 '16 at 3:53
  • This pointer should be enough paulsalaets.com/posts/expose-node-module-as-global-variable – ThomasG77 Jan 7 '16 at 4:00

I think you're out of luck, there is no third option. I cannot claim this with 100% certainty, but I'm at the moment doing an extensive research about vector tiling, and in short MapBox vector tiles are optimized for presentation for their own rendering engine. So while open, it is more or less proprietary - and from this perspective it is probably best to stick closely to MapBox libraries (stability and quality when dealing with these vector tiles).

So I'd say it's best to stick with vt-geojson. But I think you could also open a feature request on Github. This sounds like a useful feature.

| improve this answer | |
  • any update since 2016 ? I'm looking to convert Vector Grid layer to Geojson ! – Zak Aug 17 '18 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.