Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wmts / struct / WMTSTileMatrixSetLink.java @ 40278

History | View | Annotate | Download (4.42 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.remoteclient.wmts.struct;
23

    
24
import java.io.IOException;
25
import java.util.ArrayList;
26

    
27
import org.kxml2.io.KXmlParser;
28
import org.xmlpull.v1.XmlPullParserException;
29

    
30
/**
31
 * Set of tiles
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public abstract class WMTSTileMatrixSetLink {
35
        private String            tileMatrixSetId              = null;
36
        private WMTSTileMatrixSet tileMatrixSet                = null;
37
        private ArrayList         tileMatrixLimits             = null;
38
        protected boolean         forceLongitudeFirstAxisOrder = false;
39
        //protected WMTSBoundingBox layerBBox                    = null;
40
        /**
41
         * Sets longitude first in the axis order read from the capabilities file
42
         * @param force
43
         */
44
        public void setForceLongitudeFirstAxisOrder(boolean force) {
45
                this.forceLongitudeFirstAxisOrder = force;
46
        }
47
        
48
    /**
49
     * Parses this service
50
     * @param parser
51
     * @param content
52
     * @throws IOException
53
     * @throws XmlPullParserException
54
     */
55
    public abstract void parse(KXmlParser parser) throws IOException, XmlPullParserException; 
56
    
57
        public String getTileMatrixSetId() {
58
                return tileMatrixSetId;
59
        }
60
        
61
        public void setTileMatrixSetId(String tileMatrixSetId) {
62
                this.tileMatrixSetId = tileMatrixSetId;
63
        }
64
        
65
        public WMTSTileMatrixSet getTileMatrixSet() {
66
                return tileMatrixSet;
67
        }
68
        
69
        public void setTileMatrixSet(WMTSTileMatrixSet tileMatrixSet) {
70
                this.tileMatrixSet = tileMatrixSet;
71
        }
72
        
73
        public ArrayList getTileMatrixLimits() {
74
                if(tileMatrixLimits == null)
75
                        tileMatrixLimits = new ArrayList();
76
                return tileMatrixLimits;
77
        }
78
        
79
        /**
80
         * Links the TileMatrixLimits with the TileMatrix
81
         * @param tileMatrixSet
82
         */
83
        public void linkTileMatrix(WMTSTileMatrixSet tileMatrixSet) {
84
                //Recorre la lista de TileMatrixLimits y asigna a cada uno el TileMatrix asociado 
85
                //definido en la etiqueta
86
                if(tileMatrixLimits == null)
87
                        return;
88
                java.util.List<String> idListToRemove = new ArrayList<String>();
89
                for (int i = 0; i < tileMatrixLimits.size(); i++) {
90
                        WMTSTileMatrixLimits limits = (WMTSTileMatrixLimits)tileMatrixLimits.get(i);
91
                        String id = limits.getRefToTileMatrix();
92
                        boolean isWithoutReference = true;
93
                        for (int j = 0; j < tileMatrixSet.getTileMatrix().size(); j++) {
94
                                WMTSTileMatrix tileMatrix = (WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(j);
95
                                if(tileMatrix.getIdentifier().compareTo(id) == 0) {
96
                                        limits.setTileMatrix(tileMatrix);
97
                                        isWithoutReference = false;
98
                                        break;
99
                                }
100
                        }
101
                        if(isWithoutReference) {
102
                                idListToRemove.add(id);
103
                        }
104
                }
105
                removeLevelsFromTileMatrix(idListToRemove);
106
        }
107
        
108
        /**
109
         * Removes form the <code>WMTSTileMatrixLimits</code> the elements in the
110
         * ID list. These elements are <code>WMTSTileMatrix</code> without reference
111
         * @param idList 
112
         *        List of identifiers
113
         */
114
        private void removeLevelsFromTileMatrix(java.util.List<String> idList) {
115
                if(tileMatrixLimits == null || idList == null || idList.size() == 0)
116
                        return;
117
                for (int i = 0; i < idList.size(); i++) {
118
                        String id = idList.get(i);
119
                        for (int j = 0; j < tileMatrixLimits.size(); j++) {
120
                                WMTSTileMatrixLimits limits = (WMTSTileMatrixLimits)tileMatrixLimits.get(j);
121
                                if(id.equals(limits.getRefToTileMatrix())) {
122
                                        tileMatrixLimits.remove(j);
123
                                        break;
124
                                }
125
                        }
126
                }
127
        }
128
        
129
        
130
        public void print() {
131
                System.out.println(" *****WMTSTileMatrixSetLink******");
132
                System.out.println("TileMatrixSet ID:" + getTileMatrixSetId());
133
                for (int i = 0; i < getTileMatrixLimits().size(); i++) {
134
                        WMTSTileMatrixLimits limits = ((WMTSTileMatrixLimits)getTileMatrixLimits().get(i));
135
                        limits.print();
136
                }
137
        }
138
}