javascript - 如何使用 DirectionsJS 更改 Mapbox 的标记?它显示 A 和 B 标记

标签 javascript mapbox markers

如何更改 Mapbox 标记(使用 Directionjs 时)?

它显示 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/

最佳答案

尝试查看他们的示例,了解如何使用不同的标记样式。对于图像,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.properties 下的 icon 值来确定其样式。

关于javascript - 如何使用 DirectionsJS 更改 Mapbox 的标记?它显示 A 和 B 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37680593/

相关文章:

java - Eclipse 中的多个标记错误

javascript - 传单标记工具提示居中

javascript - 如何根据其属性值过滤充满数组的对象

javascript - 我需要 "Pro"Paypal 帐户才能使用 Payments API

javascript - 使用 mapbox js,如何更改 map 的样式?

javascript - Mapbox 标记符号颜色变化

javascript - 通过 JavaScript 打印网页的子集

javascript - 从 1 到 4096 的 csv 数字的正则表达式

javascript - 在 Mapbox 中,如何从 iOS 上的样式切换图层?

matlab - Matlab 绘图的自定义标记