【问题标题】:Routing between places with mapbox or similar direction api使用 mapbox 或类似方向 api 在地点之间路由
【发布时间】:2015-04-26 15:38:53
【问题描述】:

我有一个 geoJSON 对象,我想在我的 geoJSON 文件上的航点之间进行路由。

{
    "type":"FeatureCollection",
    "generator":"JOSM",
    "bbox":[
        23.4668,
        58.9198,
        23.6412,
        58.974
    ],
    "features":[

    {
            "type":"Feature",
            "properties":{
                "wheelchair":"yes",
                "smoothness":"bad",
                "surface":"crushed stones"
            },
            "geometry":{
                "type":"Point",
                "coordinates":[
                    23.53359252,
                    58.95034587858
                ]
            }
        },
        {
            "type":"Feature",
            "properties":{
                "wheelchair":"yes",
                "addr:housename":"Saue kohvik",
                "amenity":"pub",
                "name":"Saue kohvik"
            },
            "geometry":{
                "type":"Point",
                "coordinates":[
                    23.5361382,
                    58.9473236
                ]
            }
        },
         {
            "type":"Feature",
            "properties":{
                "wheelchair":"yes",
                "smoothness":"intermediate",
                "highway":"footway"
            },
            "geometry":{
                "type":"LineString",
                "coordinates":[
                    [
                        23.5410658,
                        58.9406213
                    ],
                    [
                        23.5410936,
                        58.9408252
                    ],
                    [
                        23.541092,
                        58.9408358
                    ],
                    [
                        23.5410706,
                        58.9410896
                    ],
                    [
                        23.5410448,
                        58.9412609
                    ],
                    [
                        23.541028,
                        58.9413309
                    ],
                    [
                        23.5409993,
                        58.9414512
                    ],
                    [
                        23.5408984,
                        58.9416477
                    ],
                    [
                        23.5408677,
                        58.9416962
                    ],
                    [
                        23.5407571,
                        58.9418706
                    ],
                    [
                        23.5405886,
                        58.9421204
                    ],
                    [
                        23.5405302,
                        58.9422071
                    ],
                    [
                        23.5403894,
                        58.9423888
                    ],
                    [
                        23.5401636,
                        58.9426413
                    ],
                    [
                        23.5400953,
                        58.9426593
                    ],
                    [
                        23.5399336,
                        58.9428447
                    ],
                    [
                        23.5399287,
                        58.9428504
                    ],
                    [
                        23.5399434,
                        58.9428895
                    ],
                    [
                        23.5394702,
                        58.9434341
                    ],
                    [
                        23.5394296,
                        58.943468
                    ],
                    [
                        23.5389324,
                        58.9439879
                    ],
                    [
                        23.5384256,
                        58.9445103
                    ],
                    [
                        23.5381597,
                        58.9447992
                    ],
                    [
                        23.5377425,
                        58.9452314
                    ],
                    [
                        23.5375449,
                        58.9454551
                    ]
                ]
            }
        },
         {
            "type":"Feature",
            "properties":{
                "wheelchair":"yes",
                "highway":"footway"
            },
            "geometry":{
                "type":"LineString",
                "coordinates":[
                    [
                        23.5408677,
                        58.9416962
                    ],
                    [
                        23.541045,
                        58.9417267
                    ],
                    [
                        23.5412157,
                        58.9417564
                    ]
                ]
            }
        }

        ]
}

我的问题是:我能否在文件中的位置之间路由“仅在属性为“轮椅”:“是”和“高速公路”:“人行道”的这些 LineStrings 上路由。并且路由不能使用 LineStrings,其中属性仅“高速公路”:“人行道”。

当我使用 mapbox 方向服务时可以吗?

我用我的自定义属性制作了自己的 openstreetmap,但我知道我被卡住了,我不知道如何在该地图中路由,因为路由只能调用一个属性所在的这些方式(线串和点)轮椅=“是”。

【问题讨论】:

    标签: openstreetmap mapbox geojson


    【解决方案1】:

    您可以使用L.mapbox.FeatureLayer 结合过滤器来呈现您的特征集合:

    var featureLayer = L.mapbox.featureLayer('data.geo.json').addTo(map);
    
    var filter = function (feature) {
      // Check if feature is a linestring
      if (feature.geometry.type == 'Linestring') {
        // Check if has property wheelchair and value is yes
        if (feature.properties.hasOwnProperty('wheelchair') &&
            feature.properties.wheelchair === 'yes') {
          // Check if has property highway and value is footway
          if (!feature.properties.hasOwnProperty('highway') || 
              feature.properties.highway === 'footway') {
              // highway absent or highway is footway
              return true;
          } else {
            // highway found and value is not footway
            return false;
          }
        } else {
          // Wheelchair absent or value isn't yes
          return false;
        }
      } else {
        // Not a linestring
        return true;
      }
    }
    
    featureLayer.on('ready', function () {
      featureLayer.setFilter(filter);
    });
    

    L.mapbox.featureLayer的参考:https://www.mapbox.com/mapbox.js/api/v2.1.5/l-mapbox-featurelayer/

    【讨论】:

    • okey TNX,很有帮助,但你能告诉我,如果我已将数据添加到地图,那么如何导航我的数据?
    • 您需要编写自己的逻辑,坦率地说,这是一项艰巨的任务。目前 Mapbox 中没有开箱即用的东西(据我所知)它正在开发中,您可以在这里查看:mapbox.com/developers/api/directions 并申请测试。
    • okey ,但是您知道任何其他可能的框架或 api-s 吗?
    • 你可以看看github.com/perliedman/leaflet-routing-machine,这是开源的。但是我不知道它是否可以满足您的需求,因为我自己没有使用过。
    • iH8 tnx 获取该信息,您是正确的,他们没有办法将我的步行方向限制为轮椅 =“yes”路径,但我提出了一个问题,也许他们现在添加了该功能 :)
    猜你喜欢
    • 2013-04-24
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多