Revision 43618 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContext.java

View differences:

MapContext.java
41 41

  
42 42
import org.gvsig.compat.CompatLocator;
43 43
import org.gvsig.compat.print.PrintAttributes;
44
import org.gvsig.fmap.dal.DataStore;
44 45
import org.gvsig.fmap.dal.exception.ReadException;
45 46
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
46 47
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
......
69 70
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer;
70 71
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
71 72
import org.gvsig.fmap.mapcontext.rendering.strategies.SelectedEnvelopeVisitor;
73
import org.gvsig.timesupport.AbsoluteInstant;
74
import org.gvsig.timesupport.AbsoluteIntervalTypeNotRegisteredException;
75
import org.gvsig.timesupport.Instant;
76
import org.gvsig.timesupport.Interval;
77
import org.gvsig.timesupport.RelativeInstant;
78
import org.gvsig.timesupport.Time;
79
import org.gvsig.timesupport.TimeSupportLocator;
80
import org.gvsig.timesupport.TimeSupportManager;
72 81
import org.gvsig.tools.ToolsLocator;
73 82
import org.gvsig.tools.dispose.impl.AbstractDisposable;
74 83
import org.gvsig.tools.dynobject.DynStruct;
......
102 111
 * <li>some {@link ErrorListener ErrorListener}s
103 112
 * </ul>
104 113
 * </p>
105
 *
106
 * @author Fernando Gonz?lez Cort?s
107 114
 */
108 115
public class MapContext extends AbstractDisposable implements Projected,
109 116
        Persistent, Observer, Iterable<FLayer> {
110 117

  
118
    public interface MapTimeContext {
119
        public Interval getInterval();
120
        public List<Instant> getTimes();
121
    }    
122

  
111 123
    /**
112
     * <p>
113
     * Defines the value which a unit of a distance measurement must be divided
114
     * to obtain its equivalent <b>in meters</b>.</p>
115
     *
116
     * <p>
117
     * <b><i>Conversion values of distance measurements:</i></b>
118
     * <ul>
119
     * <li><code>MapContext.CHANGEM[0]</code>: kilometer
120
     * <li><code>MapContext.CHANGEM[1]</code>: meter
121
     * <li><code>MapContext.CHANGEM[2]</code>: centimeter
122
     * <li><code>MapContext.CHANGEM[3]</code>: millimeter
123
     * <li><code>MapContext.CHANGEM[4]</code>: international statute mile
124
     * <li><code>MapContext.CHANGEM[5]</code>: yard
125
     * <li><code>MapContext.CHANGEM[6]</code>: foot
126
     * <li><code>MapContext.CHANGEM[7]</code>: inch
127
     * <li><code>MapContext.CHANGEM[8]</code>: grade
128
     * </ul>
129
     *
130
     * <p>
131
     * <h3>Examples:</h3>
132
     * <pre>1 international statute mile / MapContext.CHANGEM[4] = X meters</pre>
133
     * <pre>1 kilometer / MapContext.CHANGEM[0] = X meters</pre>
134
     * <pre>1 grade / MapContext.CHANGEM[8] = X meters</pre>
135
     * </p>
136
     *
137
     * <p>
138
     * <h3>Grade conversion value: <code>MapContext.CHANGEM[8]</code></h3>
139
     * The value of <code>MapContext.CHANGEM[8]</code> represents the meters of
140
     * a straight line between two points on the Earth surface that are 1 grade
141
     * far each other of the center of the Earth. This value has been calculated
142
     * using a radius approximated of R<sub>Earth</sub>=6.37846082678100774672e6
143
     * meters, according these equations:
144
     * <pre>D = 2 * (sin (1)) * R<sub>Earth</sub></pre>
145
     * <pre>MapContext.CHANGEM[8] = 1 / D</pre>
146
     * <h4>Explanation:</h4>
147
     * We get an isosceles triangle with the center of the Earth and the 2
148
     * points on the surface. This triangle can be divided into two rectangle
149
     * triangles. We know two values, the angle of 1 grade, that will be 0.50
150
     * grades in each triangle, and the Earth radius that is the hypotenuse.
151
     * Then we apply trigonometry and get the distance <i>D</i> between both
152
     * points on the Earth surface.</p>
153
     * <p>
154
     * Now we only must invert that value to obtain
155
     * <code>MapContext.CHANGEM[8]</code>.</p>
156
     *
157 124
     * @deprecated use getDistanceTrans2Meter()
158 125
     */
159 126
    public static final double[] CHANGEM = {1000, 1, 0.01, 0.001, 1609.344,
......
1871 1838
    public Iterator deepiterator() {
1872 1839
        return this.layers.deepiterator();
1873 1840
    }
1874
 
1841

  
1842
    public MapTimeContext getTimeContext() {
1843
        TimeSupportManager timeSupportManager = TimeSupportLocator.getManager();
1844
        Interval interval = null;
1845
        final List<Instant> times = new ArrayList<>();
1846
        Instant minInstant = null;
1847
        Instant maxInstant = null;
1848

  
1849
        //TODO Separate absolute and relative time
1850
        FLayers layers = this.getLayers();
1851
        for( Iterator<FLayer> iterator = layers.deepiterator(); iterator.hasNext(); ) {
1852
            FLayer layer = iterator.next();
1853
            if( layer instanceof SingleLayer ) {
1854
                DataStore dataStore = ((SingleLayer) layer).getDataStore();
1855
                if( dataStore.getInterval() != null ) {
1856
                    Instant startInstant = dataStore.getInterval().getStart();
1857
                    Instant endInstant = dataStore.getInterval().getEnd();
1858
                    times.addAll(dataStore.getTimes());
1859
                    if( minInstant == null ) {
1860
                        minInstant = startInstant;
1861
                        maxInstant = endInstant;
1862
                    } else {
1863
                        if( minInstant.isAfter(startInstant) ) {
1864
                            minInstant = startInstant;
1865
                        }
1866
                        if( maxInstant.isBefore(endInstant) ) {
1867
                            maxInstant = endInstant;
1868
                        }
1869
                    }
1870
                }
1871
            }
1872
        }
1873

  
1874
        if( minInstant != null ) {
1875
            if( minInstant.isAbsolute() ) {
1876
                try {
1877
                    interval = timeSupportManager.createAbsoluteInterval((AbsoluteInstant) minInstant, (AbsoluteInstant) maxInstant);
1878
                } catch (AbsoluteIntervalTypeNotRegisteredException e) {
1879
                    logger.warn("Error creating the time interval", e);
1880
                }
1881
            } else {
1882
                interval = timeSupportManager.createRelativeInterval(((RelativeInstant) minInstant).toMillis(), ((RelativeInstant) maxInstant).toMillis());
1883
            }
1884
        }
1885
        final Interval tmp_interval = interval;
1886
        return new MapTimeContext() {
1887
            @Override
1888
            public Interval getInterval() {
1889
                return tmp_interval;
1890
            }
1891

  
1892
            @Override
1893
            public List<Instant> getTimes() {
1894
                return times;
1895
            }
1896
        };
1897
    }
1898
    
1875 1899
}

Also available in: Unified diff