示例#1
0
 public void addZoomLevel(ReferencedEnvelope bbox, int tileWidth, int tileHeight) {
   List<Grid> list = grids.getModelObject();
   final Grid newGrid = new Grid();
   if (list.isEmpty()) {
     BoundingBox extent =
         new BoundingBox(bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY());
     final int levels = 1;
     GridSet tmpGridset =
         GridSetFactory.createGridSet(
             "stub",
             SRS.getEPSG4326(),
             extent,
             false,
             levels,
             1D,
             GridSetFactory.DEFAULT_PIXEL_SIZE_METER,
             tileWidth,
             tileHeight,
             false);
     Grid grid = tmpGridset.getGridLevels()[0];
     newGrid.setResolution(grid.getResolution());
     newGrid.setScaleDenominator(grid.getScaleDenominator());
   } else {
     Grid prev = list.get(list.size() - 1);
     newGrid.setResolution(prev.getResolution() / 2);
     newGrid.setScaleDenominator(prev.getScaleDenominator() / 2);
   }
   list.add(newGrid);
   grids.setModelObject(list);
   // TileMatrixSetEditor.this.convertInput();
 }
示例#2
0
    @Override
    public void validate(IValidatable<List<Grid>> validatable) {
      ValidationError error = new ValidationError();

      List<Grid> grids = validatable.getValue();
      if (grids == null || grids.size() == 0) {
        error.setMessage(new ResourceModel("TileMatrixSetEditor.validation.empty").getObject());
        validatable.error(error);
        return;
      }

      for (int i = 1; i < grids.size(); i++) {
        Grid prev = grids.get(i - 1);
        Grid curr = grids.get(i);

        if (curr.getResolution() >= prev.getResolution()) {
          String message =
              "Each resolution should be lower than it's prior one. Res["
                  + i
                  + "] == "
                  + curr.getResolution()
                  + ", Res["
                  + (i - 1)
                  + "] == "
                  + prev.getResolution()
                  + ".";
          error.setMessage(message);
          validatable.error(error);
          return;
        }

        if (curr.getScaleDenominator() >= prev.getScaleDenominator()) {
          String message =
              "Each scale denominator should be lower "
                  + "than it's prior one. Scale["
                  + i
                  + "] == "
                  + curr.getScaleDenominator()
                  + ", Scale["
                  + (i - 1)
                  + "] == "
                  + prev.getScaleDenominator()
                  + ".";
          error.setMessage(message);
          validatable.error(error);
          return;
        }
      }
    }
  Integer findClosestZoom(GridSet gridSet, WMSMapContent map) {
    double reqScale =
        RendererUtilities.calculateOGCScale(bounds(map), gridSet.getTileWidth(), null);

    int i = 0;
    double error = Math.abs(gridSet.getGrid(i).getScaleDenominator() - reqScale);
    while (i < gridSet.getNumLevels() - 1) {
      Grid g = gridSet.getGrid(i + 1);
      double e = Math.abs(g.getScaleDenominator() - reqScale);

      if (e > error) {
        break;
      } else {
        error = e;
      }
      i++;
    }

    return Math.max(i, 0);
  }
 private void tileMatrix(
     StringBuilder str,
     Grid grid,
     double[] tlCoordinates,
     int tileWidth,
     int tileHeight,
     boolean scaleWarning) {
   str.append("    <TileMatrix>\n");
   if (scaleWarning) {
     str.append(
         "      <ows:Abstract>The grid was not well-defined, the scale therefore assumes 1m per map unit.</ows:Abstract>");
   }
   str.append("      <ows:Identifier>" + grid.getName() + "</ows:Identifier>\n");
   str.append("      <ScaleDenominator>" + grid.getScaleDenominator() + "</ScaleDenominator>\n");
   str.append(
       "      <TopLeftCorner>" + tlCoordinates[0] + " " + tlCoordinates[1] + "</TopLeftCorner>\n");
   str.append("      <TileWidth>" + tileWidth + "</TileWidth>\n");
   str.append("      <TileHeight>" + tileHeight + "</TileHeight>\n");
   str.append("      <MatrixWidth>" + grid.getNumTilesWide() + "</MatrixWidth>\n");
   str.append("      <MatrixHeight>" + grid.getNumTilesHigh() + "</MatrixHeight>\n");
   str.append("    </TileMatrix>\n");
 }