1

I'm having some trouble with my DrawEnd and OnClick event. I've tried changing the condition to singleClick, click, and have removed it.

  • If Condition is added to the interaction, DrawEnd is not called (I Need DrawEnd to place the point)
  • If I remove the condition, the click handler is not called, but DrawEnd is.

Since the click is not handled, it seems to go into some sort of Panning mode and the map moves wherever I move my mouse.

My process is this..

  • user clicks to add a point and an attribute screen for the point is displayed.

  • Once the user enters attributes, the screen goes away and then they can drop a point.

  • When the point is placed, a service is called to do stuff

  • if service determines its a bad point, It remove is automatically removed from the map.

    draw = new ol.interaction.Draw({ source : addrVectorSource, type: "Point", //condition: ol.events.condition.singleClick });


It appears I'm getting an error during the on drawend function:

ol-debug.js:99465 Uncaught TypeError: this.source_.addFeature is not a function

    //[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');

      });
};
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jim S
  • 11
  • 3
  • I guess you'll have to show some more code. Are you using all these tags? – Jonatas Walker Apr 11 '16 at 11:21
  • Jonatas, Yes, I'm using Angular and Openlayers . Thanks. I've done a bit more research and an error is appearing in the on Drawend function. Once my point is placed, I attempt to validate it in the DB. If the user is not allowed to place a point there, it is removed. I guess the map goes into a weird panning state and waits for me to click again before the point is placed, because of the error that arises. ol-debug.js:99465 Uncaught TypeError: this.source_.addFeature is not a function – Jim S Apr 23 '16 at 23:38

0 Answers0