我的DrawEnd和On Click事件遇到了一些麻烦。我已经尝试将条件更改为单击,单击,并已删除它。
由于未处理点击,它似乎进入某种平移模式,无论我移动鼠标的地方,地图都会移动。
我的过程是这个..
- 用户单击以添加点,并显示该点的属性屏幕
- 一旦用户输入属性,屏幕就会消失,然后他们可以放弃一个点
- 当放置点时,调用服务来做东西
- 如果服务确定其不良点,则会自动从地图中删除它。
draw = new ol.interaction.Draw({
source : addrVectorSource,
type: "Point",
//condition: ol.events.condition.singleClick
});
看来我在on drawend函数中遇到错误。 ol-debug.js:99465未捕获的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');
});
};