Leaflet / Leaflet/Leaflet.VectorGrid

Can not slice a GeoJSON file containing just points

Open
#104 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
676
Forks
202
PR merge metrics
No merged PRs in 30d

Description

Prompted by https://stackoverflow.com/questions/44707862/how-to-add-geojson-points-as-a-vector-tile-in-leaflet

I tried to load a GeoJSON file containing only points (the one referenced in the SO question) like so:

    fetch('https://raw.githubusercontent.com/evantdailey/map_testing/master/site1.geo.json').then(function(response){
      return response.json();
    }).then(function(json){
      var points = L.geoJson(json);
      map.fitBounds(points.getBounds());

      var vectorGrid = L.vectorGrid.slicer( json, {
        maxZoom: 20,
        rendererFactory: L.svg.tile,
        vectorTileLayerStyles: {
          sliced: {
            weight: 2,
            color: 'red',
            opacity: 1,
            fillColor: 'yellow',
            fill: true,
            radius: 6,
            fillOpacity: 0.7
          }
        }
      });
      
      vectorGrid.addTo(map);
    })

Playground here. The GeoJSON is valid as per geojsonlint, and it loads if the code is changed to read var points = L.geoJson(json).addTo(map);

After a few minutes looking at the problem, I've discovered at least two problems when slicing geojson points:

  • The L.VectorGrid.Slicer does not have a minZoom nor maxZoom. This affects the behaviour of L.GridLayer.update(), as this._tileZoom becomes undefined. The end result is that no tiles are displayed, so no tiles are requested to geojson-vt. Setting a default minZoom and maxZoom should alleviate this. I do not know if the default maxZoom of 14 is being overwritten, or if there is some other race condition elsewhere.

  • If this._tileZoom is hacked during debug to allow some tiles to be requested, then _mkFeatureParts throws an exception. It is reminiscent of the cases where a point geometry is used but a linestring geometry is expected.

Unfortunately I don't have the time to debug this problem thoroughly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the linked point-only GeoJSON and the Leaflet.VectorGrid.Slicer example. Start by tracing L.GridLayer.update(), L.VectorGrid.Slicer, and the geojson-vt call, then inspect _mkFeatureParts for the point geometry failure. Done means point-only GeoJSON is sliced and rendered without missing tiles or exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.