当前,单击部分路线时的默认操作是放大地图上的该坐标。
我目前正在尝试在语音中添加一个文本,以说明该特定部分的说明。
但是如何修改已经内置 L.Routing.control 的点击监听器?
下面的代码属于我:
var routeControl = L.Routing.control({
waypoints: [
L.latLng(1.2734916210174561, 103.80210876464844),
L.latLng(1.314766, 103.765229)
],
routeWhileDragging: true,
geocoder: L.Control.Geocoder.nominatim({ geocodingQueryParams: { "countrycodes": 'SG' } })
}).addTo(map);
routeControl.on('routeselected', function (e) {
var coord = e.route.instructions;
if ('speechSynthesis' in window) {
for (let i = 0; i < coord.length; i++)
{
//speak(coord[i].text);
}
}
else {
alert("your broswer does not support text to speech");
}
});
而下面的这段代码属于原作者,当找到路由时会自动加载: https ://github.com/perliedman/leaflet-routing-machine/blob/master/src/itinerary.js
_createItineraryContainer: function(r) {
var container = this._itineraryBuilder.createContainer(),
steps = this._itineraryBuilder.createStepsContainer(),
i,
instr,
step,
distance,
text,
icon;
container.appendChild(steps);
for (i = 0; i < r.instructions.length; i++) {
instr = r.instructions[i];
text = this._formatter.formatInstruction(instr, i);
distance = this._formatter.formatDistance(instr.distance);
icon = this._formatter.getIconName(instr, i);
step = this._itineraryBuilder.createStep(text, distance, icon, steps);
if(instr.index) {
this._addRowListeners(step, r.coordinates[instr.index]);
}
}
return container;
},
_addRowListeners: function(row, coordinate) {
L.DomEvent.addListener(row, 'mouseover', function() {
this._marker = L.circleMarker(coordinate,
this.options.pointMarkerStyle).addTo(this._map);
}, this);
L.DomEvent.addListener(row, 'mouseout', function() {
if (this._marker) {
this._map.removeLayer(this._marker);
delete this._marker;
}
}, this);
L.DomEvent.addListener(row, 'click', function(e) {
this._map.panTo(coordinate);
L.DomEvent.stopPropagation(e);
}, this);
},
所以我想知道如何访问它来添加我的语音功能
L.DomEvent.addListener(row, 'click', function(e) {
this._map.panTo(coordinate);
L.DomEvent.stopPropagation(e);
}, this);
当它已经被初始化时