我的DrawEnd
和OnClick
事件有问题。我已尝试将条件更改为singleClick
,click
并已将其删除。
- 如果 Condition 添加到交互中,
DrawEnd
则不调用(我需要DrawEnd
放置点) - 如果我删除条件,则不会调用单击处理程序,而是调用
DrawEnd
。
由于未处理单击,因此它似乎进入了某种平移模式,并且无论我移动鼠标,地图都会移动。
我的流程是这样的。。
用户单击以添加一个点并显示该点的属性屏幕。
一旦用户输入属性,屏幕就会消失,然后他们可以放下一个点。
放置点后,调用一个服务来做事
如果服务确定它是一个坏点,它会自动从地图中删除。
draw = new ol.interaction.Draw({ source : addrVectorSource, type: "Point", //condition: ol.events.condition.singleClick });
看来我在 on drawend 函数期间遇到错误:
ol-debug.js:99465 Uncaught TypeError: this.source_.addFeature 不是函数
//[DRAW]
draw.on('drawend', function (e) {
console.log('drawend');
start_drawing = false;
//var id = guid();
if (typeof ($scope.addr.prefix) == 'undefined') {
$scope.addr.prefix = '';
}
if (typeof ($scope.addr.suffix) == 'undefined') {
$scope.addr.suffix = '';
}
var id = $scope.addr.prefix + $scope.addr.addrnbr + $scope.addr.suffix + '-' + $scope.selAddr.uuid;
e.feature.featureID = id;
e.feature.setId(id);
$scope.map.removeInteraction(draw);
$scope.map.removeInteraction(modify);
$scope.map.removeInteraction(select);
e.feature.setProperties({
'id': id,
'name': "Point", // Can be anything
'description': 'Some values',
'addrnum': ($scope.addr.prefix + $scope.addr.addrnbr + $scope.addr.suffix).toUpperCase()
})
$scope.nLon = e.feature.getGeometry().getCoordinates()[0];
$scope.nLat = e.feature.getGeometry().getCoordinates()[1];
$scope.addID = e.feature.getId();
var lcstat = $scope.addr.lifeCycleStatus;
var lifecycle = LCSSearch($scope.lifeStatus.lifeCycles, lcstat);
var featyp = $scope.addr.featureType;
var featuretype = FTSearch($scope.featTypes.features, featyp);
addrVectorSource.addFeature(e.feature);
//ID = addrnum + segmentUUID
$scope.nAddAddress($scope.nLat, $scope.nLon, $scope.addr.addrnbr, $scope.uuid, $scope.addr.prefix, $scope.addr.suffix, $scope.addr.lifeCycleStatus, $scope.addr.featureType, $scope.sSegment.SNSID, $scope.sSegment.StreetNameFk, id, lifecycle, featuretype);
});
//[DRAW]
// Call Service to check placement permissions
// aid = AddrNum + StreetUUID
$scope.nAddAddress = function (lat, lon, addrnum, suuid, prefix, suffix, lcstat, featyp, SNSID, SNFK, aid, lifecycle, featuretype) {
var UTObj = {
token: Lockr.get('token'),
uid: Lockr.get('user'),
};
var mapID = $scope.mapid;
var promise = MapService.AddAddress(UTObj, mapID, suuid, lat, lon, addrnum, prefix, suffix, lcstat, featyp, SNSID, SNFK, aid, lifecycle, featuretype);
promise.then(
function (payload) {
$scope.AddrRet = payload.data.PlacePointResult;
//Assign AddrRet.aid to drawn feature
$scope.assignAddressUUID(aid, $scope.AddrRet.UUID);
$scope.drawing = false;
console.log($scope.AddrRet.msg);
var msg = $scope.AddrRet.msg;
$scope.toastMessage(msg);
$scope.editState = 'NONE';
$scope.hbtnD = $scope.hbtnoff;
console.log('DrawingOff');
},
function (errorPayload) {
console.log('Error Adding Address');
$scope.removeAddressFeature(aid);
$scope.drawing = false;
var msg = errorPayload.data.msg;
$scope.toastMessage(msg);
$scope.editState = 'NONE';
$scope.hbtnD = $scope.hbtnoff;
console.log('DrawingOff');
});
};