Revision 102 org.gvsig.gazetteer/trunk/org.gvsig.gazetteer/org.gvsig.gazetteer.extension/src/main/java/org/gvsig/gazetteer/loaders/FeatureLoader.java

View differences:

FeatureLoader.java
77 77

  
78 78
/**
79 79
 * This class is used to load a new feature like a layer in gvSIG
80
 * 
80
 *
81 81
 * @author Jorge Piera Llodra (piera_jor@gva.es)
82 82
 */
83
public class FeatureLoader {     
83
public class FeatureLoader {
84 84
	private static final Logger LOG =
85 85
        LoggerFactory.getLogger(FeatureLoader.class);
86
	
86

  
87 87
    private static GeometryManager geometryManager = GeometryLocator.getGeometryManager();
88 88
	private static MapContextManager mapContextManager = MapContextLocator.getMapContextManager();
89
	
89

  
90 90
	/**
91 91
	 * Coordinates Transformer
92 92
	 */
93
	private ICoordTrans coordTrans;	
94
	
93
	private ICoordTrans coordTrans;
94

  
95 95
	/**
96 96
	 * @param projection
97 97
	 * Server projection
98 98
	 */
99 99
	public FeatureLoader(String sProjection){
100
		AbstractViewPanel activeView = 
100
		AbstractViewPanel activeView =
101 101
			(AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
102
		
103
		
102

  
103

  
104 104
		IProjection projection = CRSFactory.getCRS(sProjection);
105 105
		if (projection == null){
106 106
			projection = activeView.getMapControl().getViewPort().getProjection();
107 107
		}
108
		
108

  
109 109
		coordTrans=  projection.getCT(activeView.getMapControl().getViewPort().getProjection());
110 110
	}
111 111
	/**
......
126 126

  
127 127
		if (query.getOptions().getAspect().isGoTo()){
128 128
			focusCenter(feature);
129
		}        
129
		}
130 130

  
131 131
		return true;
132
	}    
132
	}
133 133

  
134 134
	/**
135
	 * This method focus the toponim in the center of the view 
135
	 * This method focus the toponim in the center of the view
136 136
	 * @param feature
137 137
	 * Feature that contains the coordinates
138 138
	 */
139 139
	private void focusCenter(Feature feature){
140
		AbstractViewPanel activeView = 
140
		AbstractViewPanel activeView =
141 141
			(AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
142 142

  
143 143
		IProjection projection = activeView.getProjection();
144 144
		ViewPort viewPort = activeView.getMapControl().getViewPort();
145 145
		MapContext mapContext = activeView.getMapControl().getMapContext();
146 146
		Point2D point = getReprojectedPoint(feature.getCoordinates());
147
				
147

  
148 148
		if (viewPort.getAdjustedEnvelope() != null){
149 149
			Toolkit kit = Toolkit.getDefaultToolkit();
150 150
			double dpi = kit.getScreenResolution();
151
			
151

  
152 152
			Envelope envelope = viewPort.getAdjustedEnvelope();
153 153
			Rectangle2D rectangle = new Rectangle2D.Double(envelope.getLowerCorner().getX(),
154 154
					envelope.getLowerCorner().getY(),
155 155
					envelope.getUpperCorner().getX() - envelope.getLowerCorner().getX(),
156 156
					envelope.getUpperCorner().getY() - envelope.getLowerCorner().getY());
157
			
157

  
158 158
			Rectangle2D extent = projection.getExtent(rectangle,
159 159
			        new Double(25000).doubleValue(),
160 160
					new Double(viewPort.getImageWidth()).doubleValue(),
161 161
					new Double(viewPort.getImageHeight()).doubleValue(),
162 162
					viewPort.getMapUnits(),
163 163
					viewPort.getDistanceUnits(),
164
					dpi);				
164
					dpi);
165 165
			if (extent != null){
166 166
				try {
167 167
					envelope = geometryManager.createEnvelope(SUBTYPES.GEOM2D);
......
172 172
							point.getY() + extent.getHeight()/2,
173 173
							SUBTYPES.GEOM2D);
174 174
					envelope.setLowerCorner(loweCorner);
175
					envelope.setUpperCorner(upperCorner);				
175
					envelope.setUpperCorner(upperCorner);
176 176
					mapContext.zoomToEnvelope(envelope);
177 177
				} catch (CreateEnvelopeException e) {
178 178
				    LOG.error("Error creating the envelope", e);
179 179
				} catch (CreateGeometryException e) {
180 180
				    LOG.error("Error creating the envelope", e);
181
				}			
181
				}
182 182
			}
183
		}		
184
	} 
183
		}
184
	}
185 185

  
186 186
	/**
187 187
	 * It adds a new Label to the current view
......
191 191
	 * To remove or keep the old searches
192 192
	 */
193 193
	private void addAndDrawLabel(Feature feature,boolean isRemoveOldClicked,boolean isMarkedPlaceClicked){
194
		AbstractViewPanel activeView = 
194
		AbstractViewPanel activeView =
195 195
			(AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
196 196
		MapContext mc = activeView.getMapControl().getMapContext();
197 197
		GraphicLayer lyr = mc.getGraphicsLayer();
198
		
198

  
199 199
		if (isRemoveOldClicked){
200 200
			lyr.clearAllGraphics();
201
		}	
202
		
201
		}
202

  
203 203
		if (isMarkedPlaceClicked){
204 204
			int pointSymbol = lyr.addSymbol(getSymbol());
205 205
			int textSymbol = lyr.addSymbol(getTextSymbol(feature.getName()));
206
			
207
				
206

  
207

  
208 208
			Point2D point2d = getReprojectedPoint(feature.getCoordinates());
209 209
			feature.setCoordinates(point2d);
210 210
			Point point;
......
217 217
				PluginServices.getMainFrame().enableControls();
218 218
			} catch (CreateGeometryException e) {
219 219
			    LOG.error("Error creating the point", e);
220
			}			
221
		}			
222
		
220
			}
221
		}
222

  
223 223
		mc.invalidate();
224 224
	}
225
	
225

  
226 226
	/**
227 227
	 * Creates a FSymbol
228 228
	 * @return
......
239 239
		theSymbol.setText(text);
240 240
		return theSymbol;
241 241
	}
242
	
242

  
243 243
	/**
244 244
	 * Creates a FSymbol
245 245
	 * @return
......
253 253
		theSymbol.setSize(4);
254 254
		return theSymbol;
255 255
	}
256
	
256

  
257 257
	/**
258 258
	 * Reprojects the new point
259 259
	 * @param ptOrig
......
263 263
	 */
264 264
	private Point2D getReprojectedPoint(Point2D ptOrigin){
265 265
		Point2D ptDest = null;
266
		return getCoordTrans().convert(ptOrigin, ptDest);
266
		ICoordTrans ct = getCoordTrans();
267
		if(ct != null) {
268
		    return ct.convert(ptOrigin, ptDest);
269
		}
270
		return ptOrigin;
267 271
	}
268 272
	/**
269 273
	 * @return the coordTrans

Also available in: Unified diff