Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.43k stars 3.41k forks source link

Tile: Encode Forward / Backward Property for Geometries #2980

Open soupman99 opened 8 years ago

soupman99 commented 8 years ago

Trying to get tile service to return the vector tiles with all of the meta data but can't seem to figure it out. I keep getting

400 Bad Request - source.error

Can someone help me with setting up my style correctly to display the data?

{
    "version": 8,
    "name": "osrmtiles",
    "metadata": {
        "mapbox:autocomposite": true,
        "mapbox:type": "default"
    },
"sources": {
    "osm": {
        "url": "http://localhost:5000/tile/v1/driving/tile({x},{y},{z}).mvt",
        "type": "vector"
    }
},
    "sprite": "sprites/basic-v9",
    "glyphs": "glyphs/{fontstack}/{range}.pbf",
    "layers": [
      {
          "id": "place-town",
          "type": "symbol",
          "source": "osm",
          "source-layer": "speed",
          "minzoom": 12,
          "maxzoom": 20,
          "interactive": true,
          "filter": [
              "==",
              "type",
              "town"
          ],
          "layout": {
              "text-size": {
                  "base": 1,
                  "stops": [
                      [
                          7,
                          11.5
                      ],
                      [
                          15,
                          20
                      ]
                  ]
              },
              "text-font": {
                  "base": 1,
                  "stops": [
                      [
                          11,
                          [
                              "DIN Offc Pro Regular",
                              "Arial Unicode MS Regular"
                          ]
                      ],
                      [
                          12,
                          [
                              "DIN Offc Pro Medium",
                              "Arial Unicode MS Regular"
                          ]
                      ]
                  ]
              },
              "text-padding": 2,
              "text-offset": [
                  0,
                  0
              ],
              "text-field": "{name_en}",
              "text-max-width": 7
          },
          "paint": {
              "text-color": {
                  "base": 1,
                  "stops": [
                      [
                          10,
                          "hsl(0, 0%, 75%)"
                      ],
                      [
                          11,
                          "hsl(0, 0%, 85%)"
                      ]
                  ]
              }

          }
      }
      ]
}
daniel-j-h commented 8 years ago

Here's an example of a vector tile viewer we're using on http://map.project-osrm.org/debug/#12.21/52.5233/13.3987: https://github.com/danpat/osrm-tile-viewer

soupman99 commented 8 years ago

@daniel-j-h that was a HUGE help. Thanks for the link. Which brings up another question. Is there a way to filter streets based on the direction of traffic flow? I see that this is being used to filter the street color based on the speed property.

      "filter": ["all",
                ["==", "$type", "LineString"],
                [ ">", "speed",90 ]
            ]

Is there property in OSRM tiles that indicates whether a street is one way or two way? Or is there some documentation I can read up on? I'd like to sort & change colors based on one way/two way streets.

daniel-j-h commented 8 years ago

@soupman99 in theory it should be possible. Here's the code for the Tile endpoint: https://github.com/Project-OSRM/osrm-backend/blob/master/src/engine/plugins/tile.cpp

and here's where we create the Protobuf Tile response object: https://github.com/Project-OSRM/osrm-backend/blob/d1f1358e481698a8b2401333e14d27b15582a47f/src/engine/plugins/tile.cpp#L663-L665

I think it should be possible to add forward / backward properties in the Tile endpoint's response. Looping @danpat in here who wrote the style / tile plugin.

danpat commented 8 years ago

We would need to change the way we encode the geometry if you want to highlight one-way streets. What the code does right now is encode everything as one-way geometry, and for a two-way street you get overlapping geometries with reversed coordinate order.

It's not very efficient, we could probably encode geometries once and have forward and backward properties and save quite a bit of space in the encoded tiles. Having forward & backward properties would enable you to highlight one-way roads.

This would be a breaking change to how the tiles are encoded, so it'd need to wait for OSRM 6.x.

I think we should do it, the debug tiles are unnecessarily large.