Esempio n. 1
0
    getFeaturePickingCoords: function(map, longitudeRadians, latitudeRadians) {
        var ll = new Cartographic(CesiumMath.negativePiToPi(longitudeRadians), latitudeRadians, 0.0);
        var level = Math.round(map.getZoom());

        return pollToPromise(function() {
            return this.imageryProvider.ready;
        }.bind(this)).then(function() {
            var tilingScheme = this.imageryProvider.tilingScheme;
            var coords = tilingScheme.positionToTileXY(ll, level);
            return {
                x: coords.x,
                y: coords.y,
                level: level
            };
        }.bind(this));
    },
      compare: function(actual, expected) {
        var result = {};
        result.pass = true;
        result.message = "";

        if (!defined(actual.orientation)) {
          result.pass = false;
          result.message += "Expected " + actual + " to contain .orientation. ";
        }
        if (!defined(expected.orientation)) {
          result.pass = false;
          result.message +=
            "Expected " + expected + " to contain .orientation. ";
        }

        if (result.pass) {
          if (!defined(actual.orientation.roll)) {
            result.pass = false;
            result.message +=
              "Expected " + actual + " to contain .orientation.roll. ";
          }
          if (!defined(actual.orientation.pitch)) {
            result.pass = false;
            result.message +=
              "Expected " + actual + " to contain .orientation.pitch. ";
          }
          if (!defined(actual.orientation.heading)) {
            result.pass = false;
            result.message +=
              "Expected " + actual + " to contain .orientation.heading. ";
          }

          if (!defined(expected.orientation.roll)) {
            result.pass = false;
            result.message +=
              "Expected " + expected + " to contain .orientation.roll. ";
          }
          if (!defined(expected.orientation.pitch)) {
            result.pass = false;
            result.message +=
              "Expected " + expected + " to contain .orientation.pitch. ";
          }
          if (!defined(expected.orientation.heading)) {
            result.pass = false;
            result.message +=
              "Expected " + expected + " to contain .orientation.heading. ";
          }
        }

        if (result.pass) {
          for (let i = 0; i < 3; i++) {
            let expectedValue;
            let actualValue;

            switch (i) {
              case 0:
                expectedValue = expected.orientation.roll;
                actualValue = actual.orientation.roll;
                break;
              case 1:
                expectedValue = expected.orientation.pitch;
                actualValue = actual.orientation.pitch;
                break;
              case 2:
                expectedValue = expected.orientation.heading;
                actualValue = actual.orientation.heading;
                break;
            }

            if (!similarRadians(actualValue, expectedValue, 0.001)) {
              result.pass = false;
              const difference = CesiumMath.negativePiToPi(
                expectedValue - actualValue
              );
              result.message +=
                "Expected roll value " +
                actualValue +
                " to be " +
                expectedValue +
                " (difference was " +
                difference +
                " radians, " +
                CesiumMath.toDegrees(difference) +
                " degrees). ";
            }
          }
        }

        return result;
      }
Esempio n. 3
0
    _updateAttribution: function() {
        if (!this._usable || !defined(this.imageryProvider.getTileCredits)) {
            return;
        }

        var i;
        for (i = 0; i < this._previousCredits.length; ++i) {
            this._previousCredits[i]._shownInLeafletLastUpdate = this._previousCredits[i]._shownInLeaflet;
            this._previousCredits[i]._shownInLeaflet = false;
        }

        var bounds = this._map.getBounds();
        var zoom = this._map.getZoom() - this._zSubtract;

        var tilingScheme = this.imageryProvider.tilingScheme;

        swScratch.longitude = Math.max(CesiumMath.negativePiToPi(CesiumMath.toRadians(bounds.getWest())), tilingScheme.rectangle.west);
        swScratch.latitude = Math.max(CesiumMath.toRadians(bounds.getSouth()), tilingScheme.rectangle.south);
        var sw = tilingScheme.positionToTileXY(swScratch, zoom, swTileCoordinatesScratch);
        if (!defined(sw)) {
            sw = swTileCoordinatesScratch;
            sw.x = 0;
            sw.y = tilingScheme.getNumberOfYTilesAtLevel(zoom) - 1;
        }

        neScratch.longitude = Math.min(CesiumMath.negativePiToPi(CesiumMath.toRadians(bounds.getEast())), tilingScheme.rectangle.east);
        neScratch.latitude = Math.min(CesiumMath.toRadians(bounds.getNorth()), tilingScheme.rectangle.north);
        var ne = tilingScheme.positionToTileXY(neScratch, zoom, neTileCoordinatesScratch);
        if (!defined(ne)) {
            ne = neTileCoordinatesScratch;
            ne.x = tilingScheme.getNumberOfXTilesAtLevel(zoom) - 1;
            ne.y = 0;
        }

        var nextCredits = [];

        for (var j = ne.y; j < sw.y; ++j) {
            for (i = sw.x; i < ne.x; ++i) {
                var credits = this.imageryProvider.getTileCredits(i, j, zoom);
                if (!defined(credits)) {
                    continue;
                }

                for (var k = 0; k < credits.length; ++k) {
                    var credit = credits[k];
                    if (credit._shownInLeaflet) {
                        continue;
                    }

                    credit._shownInLeaflet = true;
                    nextCredits.push(credit);

                    if (!credit._shownInLeafletLastUpdate) {
                        this._map.attributionControl.addAttribution(getCreditHtml(credit));
                    }
                }
            }
        }

        // Remove attributions that applied last update but not this one.
        for (i = 0; i < this._previousCredits.length; ++i) {
            if (!this._previousCredits[i]._shownInLeaflet) {
                this._map.attributionControl.removeAttribution(getCreditHtml(this._previousCredits[i]));
                this._previousCredits[i]._shownInLeafletLastUpdate = false;
            }
        }

        this._previousCredits = nextCredits;
    },
// Determines whether the values are within eps of each other ignoring cyclic shifts (mod 2*PI). Expects values to be in radians.
function similarRadians(expected, actual, eps) {
  return Math.abs(CesiumMath.negativePiToPi(expected - actual)) <= eps;
}