go-spatial / tegola

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

selected properties data coming not coming through as json array #917

Closed jjw00d closed 1 year ago

jjw00d commented 1 year ago

Tegola is cool! Good work, really enjoyed using it so far

I'm using an MVT layer and selecting properties of the data - which I then show in a popover when inspecting items on the map. I'm having some issues with the data types of things returned

I'm selecting my layer like this:

# Power lines
  [[providers.layers]]
  name = "power_line"
  sql = """
    SELECT ogc_fid,
      ST_AsMVTGeom(ST_SimplifyPreserveTopology(wkb_geometry, !PIXEL_WIDTH! / 4), !BBOX!) as geom,
      name,
      "name:en",
      operator,
      power,
      array_to_json(voltage) as voltage,
      array_to_json(cables) as cables
    FROM osm_power
    WHERE (
    power = 'line'
    OR power = 'minor_line'
    OR power = 'cable'
    OR power = 'minor_cable'
      )
      AND ST_IsValid(wkb_geometry)
      AND wkb_geometry && !BBOX!
      AND ST_Length(wkb_geometry) > !PIXEL_WIDTH! / 4
  """

But both the cables and voltage properties are returned as string array properties when the pbf is decoded image

For numeric properties of the data - they are correctly decoded as numbers... So i'm not sure what's going on here - or why the data wouldn't be coming through as an array. Is this expected?

(To produce the screen shot above I'm using a Deck.gl MVT layer and reading the data before rendering a geojson layer)

ARolek commented 1 year ago

@jjw00d hey there! Glad you're enjoying tegola. Looking at your issue here, the problem is that the MVT spec does not support JSON like you're trying to use it here.

Can you help me understand a bit more what you're trying to achieve? For example, do you need the cables and voltage attributes for cartographic purposes, or will these attributes be displayed in a data view when the user interacts with the feature? If the latter, you might be able to encode the JSON as a string in the MVT and then decode the JSON client side.

jjw00d commented 1 year ago

Aha - that's interesting - I'll go peruse it - would be good to read up.

Yep, all I'm trying to achieve is to display the attributes in a data view when the user interacts. I can definitely decode them client side - my thought was I shouldn't need to but it looks like I was wrong. Thank you

ARolek commented 1 year ago

@jjw00d We have a link to the spec in the README. Here's a link for reference: https://github.com/mapbox/vector-tile-spec