go-spatial / tegola

Tegola is a Mapbox Vector Tile server written in Go
http://tegola.io/
MIT License
1.26k stars 193 forks source link

Tegola viewer not showing tiles for WebMercator #784

Closed geraldo closed 3 years ago

geraldo commented 3 years ago

I'm using a _mvtpostgis provider with default srid 3857. Everything works fine I my custom OpenLayers viewer shows the vector tiles as expected.

But the internal Tegola viewer doesn't. Is there any way to change the viewer srid or does it only work with 4326 projections? Or could it be a problem with the style automatically generated by the built in viewer?

ARolek commented 3 years ago

Can you provide a few more details? your tegola config and the tegola version would be helpful.

geraldo commented 3 years ago

I'm using Tegola v0.13.0. The config file looks something like that:

[webserver]
port = ":8080"

# register data providers
[[providers]]
name = "map"            # provider name is referenced from map layers
type = "mvt_postgis"    # the type of data provider. currently only supports postgis
host = "127.0.0.1"      # postgis database host
port = 5432             # postgis database port
database = "***"        # postgis database name
user = "***"            # postgis database user
password = "***"        # postgis database password

  [[providers.layers]]
  name = "bus"
  geometry_fieldname = "geom"
  id_fieldname = "id"
  geometry_type = "LineString"
  sql = "SELECT ST_AsMVTGeom(geom,!BBOX!) AS geom, name, id FROM mobility.bus WHERE geom && !BBOX!"

[[maps]]
name = "ctbb"
center = [1.9, 41.5, 12.0] # set the center of the map

  [[maps.layers]]
  provider_layer = "map.bus"
  min_zoom = 10
  max_zoom = 20

[cache]
type = "file"
basepath = "/tmp/tegola"
ARolek commented 3 years ago

@geraldo thanks for the response, and sorry for the slow responses on my end. I have been on paternity leave, hanging with my new son!

the ST_AsMVTGeom function is expecting the geom data to be in 3857. If the data is not in 3857 then it will need to be reprojected. As far as the internal viewer not showing this data, but OpenLayers is, that's kind of odd. Are you sure the map is in the correct position? Is there anyway I can access the dataset to test?

geraldo commented 3 years ago

@ARolek Congratulations on your son!

I couldn't make ST_AsMVTGeom() work using a reprojection, but I'll hace another look on that shortly. The geometry is saved as EPSG:25831 in Postgis.

Right now it works fine using this layer definition in Openlayers:


new ol.layer.VectorTile({
  source: new ol.source.VectorTile({
    format: new ol.format.MVT(),
    tileGrid: ol.tilegrid.createXYZ({maxZoom: 20}),
    tilePixelRatio: 16,
    url:'http://localhost:8080/map.bus/{z}/{x}/{y}.vector.pbf',
    projection: new ol.proj.Projection({
      code: 'EPSG:25831',
      units: 'm',
    });
  }),
}),
ARolek commented 3 years ago

@geraldo Thank you!

Ok, so this makes sense. ST_AsMVTGeom does expect the geometries to be in 3857. I documented how you can perform this transformation at query time here. When you apply this change, your Open Layers config will not need the projection config.

Let me know if this works for you

geraldo commented 3 years ago

I changed these parameters in Tegola config file:

srid = 25831 sql = "SELECT ST_AsMVTGeom(ST_Transform(geom, 3857),ST_Transform(!BBOX!,3857)) AS geom, name, id FROM mobility.bus WHERE geom && !BBOX!"

I get this error:

[ERROR] handle_map_layer_zxy.go:165: error marshalling tile: Error trying to convert tile point: don't know how to convert from 25831 to 3857

A had a look on the projection issues, but can't figure out how to include EPSG:28831 projection (through proj4?).

ARolek commented 3 years ago

@geraldo I'm not familiar with that projection. If you know the proj details, it looks like you can add a custom projection to PostGIS. Note, you're going to need to reproject the !BBOX! tokens as well.

ARolek commented 3 years ago

@geraldo I'm going to close this issue for now. Please feel free to reopen it if you have more details. It would be great to know if the custom projection suggestion I provided helps.