Revision 8700 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.wmts/org.gvsig.wmts.provider/src/main/java/org/gvsig/wmts/provider/WMTSRasterProvider.java

View differences:

WMTSRasterProvider.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2018 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
1 23
package org.gvsig.wmts.provider;
2 24

  
3

  
4 25
import java.awt.Image;
5 26
import java.awt.geom.Rectangle2D;
6 27
import java.awt.image.BufferedImage;
......
8 29
import java.io.IOException;
9 30
import java.net.URL;
10 31
import java.util.ArrayList;
32
import java.util.Collections;
11 33
import java.util.HashMap;
12 34
import java.util.Iterator;
13 35
import java.util.List;
14 36
import java.util.Map;
37
import java.util.SortedSet;
38
import java.util.TreeSet;
15 39
import java.util.Map.Entry;
16 40

  
17 41
import javax.imageio.ImageIO;
......
49 73
import org.gvsig.metadata.MetadataLocator;
50 74
import org.gvsig.metadata.MetadataManager;
51 75
import org.gvsig.metadata.exceptions.MetadataException;
52
import org.gvsig.raster.lib.buffer.api.BandInfo;
53 76
import org.gvsig.raster.lib.buffer.api.Buffer;
54 77
import org.gvsig.raster.lib.buffer.api.BufferDimensions;
55 78
import org.gvsig.raster.lib.buffer.api.BufferLocator;
......
80 103

  
81 104
    private static final Logger logger = LoggerFactory.getLogger(WMTSRasterProvider.class);
82 105

  
83
    public static String NAME = "WMTSRaster";
106
    public static String NAME = "WMTS";
84 107
    public static String DESCRIPTION = "WMTS Raster Provider";
85
    public static final String METADATA_DEFINITION_NAME = "WMTSRaster";
108
    public static final String METADATA_DEFINITION_NAME = "WMTS";
86 109

  
87 110
    public static final int DEFAULT_BUFFER_SIZE = 256;
88
    public static final int MAX_ZOOM_LEVEL = 22;
111
    public static final int DEFAULT_MAX_ZOOM_LEVEL = 22;
89 112

  
90 113
    // WMTS Parameters
91 114
    private WMTSClient wmtsClient;
......
103 126
    private int columnsPerTile;
104 127
    private int rowsPerTile;
105 128

  
129
    private int maxZoomLevel;
130

  
106 131
    protected WMTSRasterProvider(DataStoreParameters params, DataStoreProviderServices storeServices) throws InitializeException {
107 132
        super(params, storeServices, FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME));
108 133
        initParams();
......
115 140
//        wmtsClient = getWMTSClient();
116 141
//        wmtsStatus = getWMTSStatus();
117 142
        envelope = getEnvelope();
143
        maxZoomLevel = DEFAULT_MAX_ZOOM_LEVEL;
118 144

  
119 145
        //PRUEBA
120 146
//        tileStruct = getTileStruct();
......
588 614
                        } else {
589 615
                            tileHeightsCounter.put(tileHeight, tileHeightsCounter.get(tileHeight)+1);
590 616
                        }
617
                        maxZoomLevel = zoomLevel;
591 618
                        zoomLevel++;
592 619
                    }
593 620
                }
......
692 719
     * @return The appropriate zoom level for the pizelSize
693 720
     */
694 721
    private int getZoomLvlForPixelSize(double pixelSize) {
722
        //FIXME: Elegir el c?digo id?neo
723
        // Este trozo de c?digo selecciona un zoom superior con lo que,
724
        // al hacer la interpolaci?n se generar?n p?xeles m?s gordos
695 725
        int zoom = 0;
726
        Map<Integer, Double> pixelSizePerZoomLevel = tileStruct.getPixelSizePerZoomLevel();
727

  
728
        SortedSet<Integer> keySet = new TreeSet<>(Collections.reverseOrder());
729
        keySet.addAll(pixelSizePerZoomLevel.keySet());
730
        Iterator<Integer> iterator = keySet.iterator();
731
        while(iterator.hasNext()){
732
            zoom = iterator.next();
733
            double levelPixelSize = pixelSizePerZoomLevel.get(zoom);
734
            if (pixelSize <= levelPixelSize) {
735
                return zoom;
736
            }
737
        }
738

  
739
        return zoom;
740

  
741
        // Este trozo de c?digo selecciona un zoom inferior con lo que,
742
        // al hacer la interpolaci?n se perder?n p?xeles
743
        // repercutiendo en la legibilidad de las leyendas
744
        /*
745
        int zoom = 0;
696 746
        Map<Integer, Double> pixelSizePerZoomLevel = getTileStruct().getPixelSizePerZoomLevel();
697 747
        for (int i : pixelSizePerZoomLevel.keySet()) {
698 748
            zoom = i;
......
702 752
            }
703 753
        }
704 754
        return zoom;
755
        */
705 756
    }
706 757

  
707 758
    private WMTSImage getWMTSImage() {
......
732 783
                }
733 784
                wmtsClient.connect(true, null);
734 785
            } catch (IOException e) {
735
                throw new InitializeException("Can't create WMSClient with from service '" + service.toString() + "'",
786
                throw new InitializeException("Can't create WMTSClient with from service '" + service.toString() + "'",
736 787
                    e);
737 788
            }
738 789
        }
......
774 825
    @Override
775 826
    public BufferDimensions getDimensions() throws InitializeException {
776 827
        if(this.dimensions==null){;
777
            Double pixelSize = getTileStruct().getPixelSizePerZoomLevel().get(MAX_ZOOM_LEVEL);
828
            Double pixelSize = getTileStruct().getPixelSizePerZoomLevel().get(getMaxZoomLevel());
778 829
            Envelope envelope = this.getEnvelope();
779 830
            int rows = (int)Math.round(envelope.getLength(DIMENSIONS.Y)/pixelSize);
780 831
            int columns = (int)Math.round(envelope.getLength(DIMENSIONS.X)/pixelSize);
......
783 834
        return this.dimensions;
784 835
    }
785 836

  
837
    /**
838
     * @return the maxZoomLevel
839
     */
840
    public int getMaxZoomLevel() {
841
        return maxZoomLevel;
842
    }
843

  
844
//    /**
845
//     * @param maxZoomLevel the maxZoomLevel to set
846
//     */
847
//    public void setMaxZoomLevel(int maxZoomLevel) {
848
//        this.maxZoomLevel = maxZoomLevel;
849
//    }
850

  
786 851
}

Also available in: Unified diff