<commit_before>var EMPWorldWind = window.EMPWorldWind || {};
emp.engineDefs = emp.engineDefs || {};

/**
 * @classdesc EMP3 WorldWind Map Engine Interface
 *
 * @class Instantiates a WorldWind map for EMP
 * @param args
 * @returns {engineInterface}
 */
emp.engineDefs.worldWindMapEngine = function(args) {

  var empMapInstance = args.mapInstance,
    empWorldWind;

  var engineInterface = emp.map.createEngineTemplate(),
    mapEngineExposed = engineInterface;

  engineInterface.implementation.displayName = "WorldWind Map Engine";
  engineInterface.implementation.version = "1.0.0";
  engineInterface.capabilities.mapType.type3D = true;
  engineInterface.capabilities.mapType.type2_5D = true;
  engineInterface.capabilities.mapType.type3D = true;
  engineInterface.capabilities.formats.GEOJSON_BASIC.plot = true;
  engineInterface.capabilities.formats.GEOJSON_BASIC.draw = true;
  engineInterface.capabilities.formats.GEOJSON_BASIC.edit = true;
  engineInterface.capabilities.formats.GEOJSON_FULL.plot = true;
  engineInterface.capabilities.formats.GEOJSON_FULL.edit = true;
  engineInterface.capabilities.formats.WMS.version_1_1 = true;
  engineInterface.capabilities.formats.WMS.version_1_3 = true;
  engineInterface.capabilities.formats.WMS.elevationData = true;
  engineInterface.capabilities.formats.KML_BASIC.plot = true;
  engineInterface.capabilities.formats.KML_BASIC.draw = true;
  engineInterface.capabilities.formats.KML_BASIC.edit = true;
  engineInterface.capabilities.formats.KML_COMPLEX.plot = true;
  engineInterface.capabilities.formats.IMAGE.plot = true;
  engineInterface.capabilities.formats.MILSTD.version2525B.plot = true;
  engineInterface.capabilities.formats.MILSTD.version2525B.draw = true;
  engineInterface.capabilities.formats.MILSTD.version2525B.edit = true;
  engineInterface.capabilities.formats.MILSTD.version2525C.plot = true;
  engineInterface.capabilities.formats.MILSTD.version2525C.draw = true;
  engineInterface.capabilities.formats.MILSTD.version2525C.edit = true;
  engineInterface.capabilities.formats.AIRSPACE.plot = true;
  engineInterface.capabilities.formats.AIRSPACE.draw = true;
  engineInterface.capabilities.formats.AIRSPACE.edit = true;
  engineInterface.capabilities.formats.AOI.plot = true;
  engineInterface.capabilities.formats.AOI.draw = true;
  engineInterface.capabilities.formats.AOI.edit = true;
  engineInterface.capabilities.settings.milstd.iconSize = true;
  engineInterface.capabilities.settings.milstd.labelOption = true;
  engineInterface.requirements.wmsCapabilities = true;
  engineInterface.capabilities.projection.flat = false;

  /**
   * Initialization
   * @param {EMPWorldWind.map} empWorldWindInstance
   */
  engineInterface.initialize.succeed = function(empWorldWindInstance) {
    // Add initialization code here
    try {
      empWorldWind = empWorldWindInstance;
      //empWorldWind.empMapInstance = empMapInstance;
      empWorldWind.mapEngineExposed = mapEngineExposed;
      emp.map.engineDirect = {name: "worldwind", ref: empWorldWind};

      // Notify application that the map is ready to receive data
      empMapInstance.eventing.StatusChange({
        status: emp.map.states.READY
      });
    }
    catch (err) {
      console.error("Error initializing World Wind ", err);
    }
  };

  /**
   * Indicates a failed loading
   */
  engineInterface.initialize.fail = function() {
    empMapInstance.eventing.StatusChange({
      status: emp.map.states.MAP_INSTANCE_INIT_FAILED
    });
  };

  /**
   * @param {emp.typeLibrary.Transaction} transaction
   */
  engineInterface.view.set = function(transaction) {
    var args, altitude, bottomLeft, topRight, feature, bufferScale,
      t1, t2,
      toRad = Math.PI / 180.0; // save a few divisions later

    switch (transaction.items[0].globalType) {
      case "view":
        // Set camera
        if (transaction.items[0].location) {
          args = {
            latitude: transaction.items[0].location.lat,
            longitude: transaction.items[0].location.lon,
            altitude: transaction.items[0].altitude,
            tilt: transaction.items[0].tilt,
            roll: transaction.items[0].roll,
            heading: transaction.items[0].heading
          };
        } else if (transaction.items[0].bounds) {
          // Zoom to overlay

          // Express lat/lon as radians
          bottomLeft = {
            lat: transaction.items[0].bounds.west * toRad,
            lon: transaction.items[0].bounds.south * toRad
          };

          topRight = {
            lat: transaction.items[0].bounds.east * toRad,
            lon: transaction.items[0].bounds.north * toRad
          };

          t1 = Math.pow(Math.sin((topRight.lat - bottomLeft.lat) / 2), 2);
          t2 = Math.pow(Math.sin((topRight.lon - bottomLeft.lon) / 2), 2);

          // Haversine formula
          altitude = 2 * WorldWind.EARTH_RADIUS * Math.asin(Math.sqrt(t1 + Math.cos(topRight.lat) * Math.cos(bottomLeft.lat) * t2));

          args = {
            latitude: (transaction.items[0].bounds.north + transaction.items[0].bounds.south) / 2,
            longitude: (transaction.items[0].bounds.east + transaction.items[0].bounds.west) / 2,
            altitude: altitude,
            tilt: 0,
            roll: 0,
            heading: 0
          };
        }
        break;
      case "feature":

        bufferScale = 2.25; // Assume conic view from the camera
        feature = transaction.items[0];
        switch (feature.format) {
          case emp3.api.enums.FeatureTypeEnum.GEO_ACM:
            // TODO compute bounding box diagonal distance
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_CIRCLE:
            altitude = feature.properties.radius * bufferScale;
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_ELLIPSE:
            altitude = Math.max(feature.properties.semiMajor, feature.properties.semiMinor) * bufferScale;
            break;

          case emp3.api.enums.FeatureTypeEnum.GEO_RECTANGLE:
            altitude = Math.max(feature.properties.width, feature.properties.height) * bufferScale;
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_SQUARE:
            altitude = feature.properties.width * bufferScale;
            break;
          default:
            altitude = undefined; // Remain at the current altitude
        }

        args = {
          latitude: transaction.items[0].coordinates[1],
          longitude: transaction.items[0].coordinates[0],
          altitude: altitude,
          tilt: 0,
          roll: 0,
          heading: 0
        };
        break;
      default:
        transaction.failures.push(transaction.items[0]);
    }

    if (transaction.items[0].animate === true) {
      transaction.pause();

      args.animate = true;
      args.animateCB = function() {
        transaction.run();
        // Notify movement ended
        EMPWorldWind.eventHandlers.notifyViewChange.call(empWorldWind, emp3.api.enums.CameraEventEnum.CAMERA_MOTION_STOPPED);
      };
    }
    // Notify start of movement
    EMPWorldWind.eventHandlers.notifyViewChange.call(empWorldWind, emp3.api.enums.CameraEventEnum.CAMERA_IN_MOTION);
    empWorldWind.centerOnLocation(args);
  };<commit_msg>fixes the error of centerOnFeature not having any values<commit_after>var EMPWorldWind = window.EMPWorldWind || {};
emp.engineDefs = emp.engineDefs || {};

/**
 * @classdesc EMP3 WorldWind Map Engine Interface
 *
 * @class Instantiates a WorldWind map for EMP
 * @param args
 * @returns {engineInterface}
 */
emp.engineDefs.worldWindMapEngine = function(args) {

  var empMapInstance = args.mapInstance;
  /** @type EMPWorldWind.map */
  var empWorldWind;

  var engineInterface = emp.map.createEngineTemplate(),
    mapEngineExposed = engineInterface;

  engineInterface.implementation.displayName = "WorldWind Map Engine";
  engineInterface.implementation.version = "1.0.0";
  engineInterface.capabilities.mapType.type3D = true;
  engineInterface.capabilities.mapType.type2_5D = true;
  engineInterface.capabilities.mapType.type3D = true;
  engineInterface.capabilities.formats.GEOJSON_BASIC.plot = true;
  engineInterface.capabilities.formats.GEOJSON_BASIC.draw = true;
  engineInterface.capabilities.formats.GEOJSON_BASIC.edit = true;
  engineInterface.capabilities.formats.GEOJSON_FULL.plot = true;
  engineInterface.capabilities.formats.GEOJSON_FULL.edit = true;
  engineInterface.capabilities.formats.WMS.version_1_1 = true;
  engineInterface.capabilities.formats.WMS.version_1_3 = true;
  engineInterface.capabilities.formats.WMS.elevationData = true;
  engineInterface.capabilities.formats.KML_BASIC.plot = true;
  engineInterface.capabilities.formats.KML_BASIC.draw = true;
  engineInterface.capabilities.formats.KML_BASIC.edit = true;
  engineInterface.capabilities.formats.KML_COMPLEX.plot = true;
  engineInterface.capabilities.formats.IMAGE.plot = true;
  engineInterface.capabilities.formats.MILSTD.version2525B.plot = true;
  engineInterface.capabilities.formats.MILSTD.version2525B.draw = true;
  engineInterface.capabilities.formats.MILSTD.version2525B.edit = true;
  engineInterface.capabilities.formats.MILSTD.version2525C.plot = true;
  engineInterface.capabilities.formats.MILSTD.version2525C.draw = true;
  engineInterface.capabilities.formats.MILSTD.version2525C.edit = true;
  engineInterface.capabilities.formats.AIRSPACE.plot = true;
  engineInterface.capabilities.formats.AIRSPACE.draw = true;
  engineInterface.capabilities.formats.AIRSPACE.edit = true;
  engineInterface.capabilities.formats.AOI.plot = true;
  engineInterface.capabilities.formats.AOI.draw = true;
  engineInterface.capabilities.formats.AOI.edit = true;
  engineInterface.capabilities.settings.milstd.iconSize = true;
  engineInterface.capabilities.settings.milstd.labelOption = true;
  engineInterface.requirements.wmsCapabilities = true;
  engineInterface.capabilities.projection.flat = false;

  /**
   * Initialization
   * @param {EMPWorldWind.map} empWorldWindInstance
   */
  engineInterface.initialize.succeed = function(empWorldWindInstance) {
    // Add initialization code here
    try {
      empWorldWind = empWorldWindInstance;
      //empWorldWind.empMapInstance = empMapInstance;
      empWorldWind.mapEngineExposed = mapEngineExposed;
      emp.map.engineDirect = {name: "worldwind", ref: empWorldWind};

      // Notify application that the map is ready to receive data
      empMapInstance.eventing.StatusChange({
        status: emp.map.states.READY
      });
    }
    catch (err) {
      console.error("Error initializing World Wind ", err);
    }
  };

  /**
   * Indicates a failed loading
   */
  engineInterface.initialize.fail = function() {
    empMapInstance.eventing.StatusChange({
      status: emp.map.states.MAP_INSTANCE_INIT_FAILED
    });
  };

  /**
   * @param {emp.typeLibrary.Transaction} transaction
   */
  engineInterface.view.set = function(transaction) {
    var args, altitude, bottomLeft, topRight, feature, bufferScale,
      t1, t2,
      toRad = Math.PI / 180.0; // save a few divisions later

    switch (transaction.items[0].globalType) {
      case "view":
        // Set camera
        if (transaction.items[0].location) {
          args = {
            latitude: transaction.items[0].location.lat,
            longitude: transaction.items[0].location.lon,
            altitude: transaction.items[0].altitude,
            tilt: transaction.items[0].tilt,
            roll: transaction.items[0].roll,
            heading: transaction.items[0].heading
          };
        } else if (transaction.items[0].bounds) {
          // Zoom to overlay

          // Express lat/lon as radians
          bottomLeft = {
            lat: transaction.items[0].bounds.west * toRad,
            lon: transaction.items[0].bounds.south * toRad
          };

          topRight = {
            lat: transaction.items[0].bounds.east * toRad,
            lon: transaction.items[0].bounds.north * toRad
          };

          t1 = Math.pow(Math.sin((topRight.lat - bottomLeft.lat) / 2), 2);
          t2 = Math.pow(Math.sin((topRight.lon - bottomLeft.lon) / 2), 2);

          // Haversine formula
          altitude = 2 * WorldWind.EARTH_RADIUS * Math.asin(Math.sqrt(t1 + Math.cos(topRight.lat) * Math.cos(bottomLeft.lat) * t2));

          args = {
            latitude: (transaction.items[0].bounds.north + transaction.items[0].bounds.south) / 2,
            longitude: (transaction.items[0].bounds.east + transaction.items[0].bounds.west) / 2,
            altitude: altitude,
            tilt: 0,
            roll: 0,
            heading: 0
          };
        }
        break;
      case "feature":
        bufferScale = 2.25; // Assume conic view from the camera
        feature = transaction.items[0];
        switch (feature.format) {
          case emp3.api.enums.FeatureTypeEnum.GEO_ACM:
            // TODO compute bounding box diagonal distance
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_CIRCLE:
            altitude = feature.properties.radius * bufferScale;
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_ELLIPSE:
            altitude = Math.max(feature.properties.semiMajor, feature.properties.semiMinor) * bufferScale;
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_RECTANGLE:
            altitude = Math.max(feature.properties.width, feature.properties.height) * bufferScale;
            break;
          case emp3.api.enums.FeatureTypeEnum.GEO_SQUARE:
            altitude = feature.properties.width * bufferScale;
            break;
          default:
            altitude = undefined; // Remain at the current altitude
        }

        args = {
          latitude: transaction.items[0].coordinates[1],
          longitude: transaction.items[0].coordinates[0],
          altitude: altitude,
          tilt: 0,
          roll: 0,
          heading: 0
        };
        break;
      default:
        transaction.failures.push(transaction.items[0]);
    }

    // Check if we are animating
    if (transaction.items[0].animate === true) {
      transaction.pause();

      args.animate = true;
      args.animateCB = function() {

        // If we animated update the returned values
        transaction.items[0].location = {
          lat: empWorldWind.getCenter().latitude,
          lon: empWorldWind.getCenter().longitude
        };
        transaction.items[0].bounds = empWorldWind.getBounds();

        transaction.run();
        // Notify movement ended
        EMPWorldWind.eventHandlers.notifyViewChange.call(empWorldWind, emp3.api.enums.CameraEventEnum.CAMERA_MOTION_STOPPED);
      };
    }

    // Notify start of movement
    EMPWorldWind.eventHandlers.notifyViewChange.call(empWorldWind, emp3.api.enums.CameraEventEnum.CAMERA_IN_MOTION);
    empWorldWind.centerOnLocation(args);

    // Set initial transaction return values, to be overwritten if the moved is animated
    transaction.items[0].location = {
      lat: empWorldWind.getCenter().latitude,
      lon: empWorldWind.getCenter().longitude
    };
    transaction.items[0].bounds = empWorldWind.getBounds();
  };
{'fraction_non_alphanumeric': 0.10752972258916776, 'fraction_numerical': 0.012549537648612946, 'mean_word_length': 2.857579617834395, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7245063', 'n_tokens_mistral': 4693, 'n_tokens_neox': 4495, 'n_words': 754}