我正在使用我的html手动绘制路线的绘制交互
// manual route creation event
$('#createRoute').click(function() {
// remove previous interactions
map.removeInteraction(draw);
// create linestring interaction
draw = new ol.interaction.Draw({
source: routeSource,
type: ('LineString'),
})
// add interaction to map
map.addInteraction(draw);
draw.on('drawstart', function(event) {
console.log("Map Interaction(Route): activated");
});
draw.on('drawend', function(event) {
saveRoute(event);
map.removeInteraction(draw);
console.log("Map Interaction(Route): deactivated");
});
});
并要求在此功能中使用名称
// saving a route as defined route-object
function saveRoute(event) {
// saving ol.objects
var feature = event.feature;
var lineString = feature.getGeometry();
var newWaypoints = lineString.getCoordinates();
// setting tempid in case of abortion
feature.setId("tempID");
// prompt popup for routeName
var routeName = prompt("Name der Route eingeben", "");
var newName;
// save route object
if (routeName != null && routeName.length > 0) {
newName = routeName;
console.log(routeName);
console.log(newWaypoints);
}else
{
console.log("Route creation aborted");
}
}
如果用户中止提示或没有输入名称,我该如何停止交互/删除已创建的线串? 我通过定义一个唯一的tempID并从源代码中删除它来尝试它,但这似乎不起作用..
答案 0 :(得分:0)
等到您的功能为added至ol.source.Vector
:
your_source.on('addfeature', function(event) {
saveRoute(event);
map.removeInteraction(draw);
console.log("Map Interaction(Route): deactivated");
});