2016-06-07 58 views
0

如何更改Mapbox标记(使用directionjs时)?如何使用directionsjs更改Mapbox的标记?它显示A和B标记

它显示A和B标记。

我试着编辑标记,但失去方向。

var x= L.marker([51.508245, -0.087700], { 
    icon: L.mapbox.marker.icon({ 
     'marker-size': 'large', 
     'marker-icon': 'monument', 
     'marker-color': '#fa0' 
    }) 
}).addTo(map); 


// Set the origin and destination for the direction and call the routing service 
directions.setOrigin(L.latLng(x)); 
directions.setDestination(L.latLng(51.508112, -0.075949)); 
directions.query(); 



var directionsLayer = L.mapbox.directions.layer(directions).addTo(map); 
var directionsRoutesControl = L.mapbox.directions.routesControl('routes', directions) 
    .addTo(map); 
    var directionsLayer = L.mapbox.directions.layer(directions, {readonly: true}).addTo(map); 

以上是我试过的,但它打破了方向。我正在寻找一种方法来改变A和B.

的jsfiddle的图标:https://jsfiddle.net/x48qrca8/1/

+0

试过了 - 我可以更改标记颜色,但不能更改图标。捣鼓更新的图标URL - http://jsfiddle.net/pq2wv4j9/4/ - 图标显示为灰色。 –

+0

你在他们的网站上看过[这个例子](https://www.mapbox.com/help/markers/#marker-image)吗?这可能有帮助。 – BDD

+0

太棒了。这工作。附加问题(以便我不打开新线程):如何隐藏所有geojson定义的标记并仅显示图标?标记有时会出现在图标的顶部。 –

回答

1

尝试如何做不同的标记样式看着他们的榜样。对于一个图像,check out this example,具体地在这样的代码:

myLayer.on('layeradd', function(e) { 
    var marker = e.layer, 
     feature = marker.feature; 
    marker.setIcon(L.icon(feature.properties.icon)); 
}); 
myLayer.setGeoJSON(geojson); 

这将进GeoJSON属性和使用feature.propertiesicon值找出应该如何样式。

+0

标记仍然出现在图标顶部 - 有没有办法隐藏标记A和B,只留下图标?不幸的是,这在文档中没有提到。任何想法? –

+0

我不是100%确定。我的建议是在SO或[GIS.SE](http://gis.stackexchange.com/)上提出一个新问题。您也可以直接通过[他们的帮助论坛](https://www.mapbox.com/help/)联系Mapbox人员。 – BDD