mwassmann of Ninjas
11/30/2017 - 3:00 PM

Popup hovering over a part including its metadata like partnumbers - reading out a json coming from pvs2json :-) No model-items needed.

Popup hovering over a part including its metadata like partnumbers - reading out a json coming from pvs2json :-) No model-items needed.

var MODEL_JSON = {
  'model-1':'EDM3611_2.json'
}
$scope.modelData = new Array();
var PICK_COLOR = "rgba(0,255,0,1)";
//load MODEL_JSON files
angular.forEach(MODEL_JSON, function(value, key) {
  $http.get('app/resources/Uploaded/' + value).
  success(function(data, status, headers, config) {
    $scope.modelData[key]=data;
  })
  .error(function(data, status, headers, config) {
  });
});

$timeout(function() {
  angular.forEach($element.find('twx-dt-model'), function(value, key) {
    angular.element(value).scope().$on('userpick',function(event,target,parent,edata) {
      var data = $scope.modelData[target];
      if (data != undefined) {
      	if($scope.currentSelection!=undefined) {
    	    vuforia.setColor($scope.currentSelection, undefined);
   	   	}
   	   	var pathid = JSON.parse(edata).occurrence;
        $scope.app.params['debug'] = pathid;
	    $scope.currentSelection = target + "-" + pathid;
      	var partNumber = data.components[data.idmap[pathid].cid].properties['name'];
      	var template   = '<ion-popover-view><ion-content>&nbsp;' + partNumber +  '&nbsp;</ion-content></ion-popover-view>';
      	vuforia.setColor($scope.currentSelection, PICK_COLOR);
      	var popover = $ionicPopover.fromTemplate(template, {
        	scope: $scope
      	}
                                              );
      	var customEvent = {
        	target: {
          		getBoundingClientRect:function () {
            		return {
              			'left'  :$scope.lastClick.x,
              			'top'   :$scope.lastClick.y,
              			'width' :1,
              			'height':1
           		 	};
          		}
        	}
      	};
      	popover.show(customEvent);
      	var dismissF = function(modelItem,popover) {
        	var modelItemId = modelItem;
        	var thePopover  = popover;
        	return function() {
          		$scope.currentSelection = undefined;
          		thePopover.remove();
         	 	vuforia.setColor(modelItemId, undefined);
        	}
      	}
      	// auto-close the popover after 3 seconds
      	$timeout(dismissF(target + "-" + pathid,popover), 3000);
      	$scope.$apply();
      }
    });
  });
} ,0);

document.addEventListener('click', function(event) {
  $scope.lastClick = {
    x: event.pageX, y: event.pageY};
});