svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.geocoding.extension / src / org / gvsig / geocoding / extension / GeocodingController.java @ 32526
History | View | Annotate | Download (21.9 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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L. main developer
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.extension; |
29 |
|
30 |
import java.awt.Color; |
31 |
import java.io.BufferedReader; |
32 |
import java.io.File; |
33 |
import java.io.FileReader; |
34 |
import java.io.IOException; |
35 |
import java.util.ArrayList; |
36 |
import java.util.List; |
37 |
import java.util.Locale; |
38 |
import java.util.Set; |
39 |
|
40 |
import javax.swing.DefaultComboBoxModel; |
41 |
import javax.swing.JFileChooser; |
42 |
import javax.swing.JOptionPane; |
43 |
import javax.swing.JTable; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
47 |
import org.gvsig.app.project.Project; |
48 |
import org.gvsig.app.project.documents.Document; |
49 |
import org.gvsig.app.project.documents.gui.ProjectWindow; |
50 |
import org.gvsig.app.project.documents.table.TableDocument; |
51 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
52 |
import org.gvsig.app.project.documents.view.gui.IView; |
53 |
import org.gvsig.fmap.crs.CRSFactory; |
54 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.primitive.Envelope; |
57 |
import org.gvsig.fmap.geom.primitive.Point; |
58 |
import org.gvsig.fmap.geom.primitive.impl.Envelope2D; |
59 |
import org.gvsig.fmap.geom.primitive.impl.Point2D; |
60 |
import org.gvsig.fmap.mapcontext.MapContext; |
61 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
62 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
63 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
64 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
65 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
66 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
67 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
68 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
70 |
import org.gvsig.fmap.mapcontrol.MapControl; |
71 |
import org.gvsig.geocoding.address.Literal; |
72 |
import org.gvsig.geocoding.gui.GeocodingModel; |
73 |
import org.gvsig.geocoding.gui.GeocodingPanel; |
74 |
import org.gvsig.geocoding.gui.IGeocodingModel; |
75 |
import org.gvsig.geocoding.gui.address.AbstractAddressPanel; |
76 |
import org.gvsig.geocoding.gui.address.AddressComposedPanel; |
77 |
import org.gvsig.geocoding.gui.address.AddressRangePanel; |
78 |
import org.gvsig.geocoding.gui.address.AddressSimpleCentroidPanel; |
79 |
import org.gvsig.geocoding.gui.newpattern.NewPatternPanel; |
80 |
import org.gvsig.geocoding.gui.relation.RelatePanel; |
81 |
import org.gvsig.geocoding.gui.results.ResultsPanel; |
82 |
import org.gvsig.geocoding.pattern.GeocodingPattern; |
83 |
import org.gvsig.geocoding.pattern.GeocodingSettings; |
84 |
import org.gvsig.geocoding.result.GeocodingResult; |
85 |
import org.gvsig.geocoding.styles.AbstractGeocodingStyle; |
86 |
import org.gvsig.geocoding.styles.impl.AbstractRange; |
87 |
import org.gvsig.geocoding.styles.impl.Composed; |
88 |
import org.gvsig.geocoding.styles.impl.SimpleCentroid; |
89 |
import org.gvsig.geocoding.tasks.GeocodingTask; |
90 |
import org.gvsig.geocoding.tasks.IndexingTask; |
91 |
import org.gvsig.geocoding.utils.GeocodingExtTags; |
92 |
import org.gvsig.geocoding.utils.GeocodingUtils; |
93 |
import org.gvsig.geocoding.utils.PatternLoaderThread; |
94 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
95 |
import org.gvsig.utils.GenericFileFilter; |
96 |
import org.gvsig.utils.XMLEntity; |
97 |
import org.slf4j.Logger; |
98 |
import org.slf4j.LoggerFactory; |
99 |
|
100 |
/**
|
101 |
* Controller of the geocoding extension and all yours panels
|
102 |
*
|
103 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
104 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
|
105 |
*/
|
106 |
public class GeocodingController { |
107 |
|
108 |
private static final Logger log = LoggerFactory |
109 |
.getLogger(GeocodingController.class); |
110 |
|
111 |
private volatile static GeocodingController instance; |
112 |
|
113 |
public static final String ROW = PluginServices.getText(null, "row") |
114 |
+ " : ";
|
115 |
|
116 |
private IGeocodingModel gmodel = null; |
117 |
private GeocodingPanel gpanel = null; |
118 |
private RelatePanel relpanel = null; |
119 |
private ResultsPanel respanel = null; |
120 |
|
121 |
private int[] symbId = new int[3]; |
122 |
|
123 |
/**
|
124 |
* Controller Constructor
|
125 |
*/
|
126 |
private GeocodingController() {
|
127 |
// Build geocoding model
|
128 |
this.gmodel = new GeocodingModel(); |
129 |
// Create all extensions panel
|
130 |
this.gpanel = new GeocodingPanel(this); |
131 |
this.relpanel = new RelatePanel(this); |
132 |
this.respanel = new ResultsPanel(this); |
133 |
|
134 |
} |
135 |
|
136 |
/**
|
137 |
*
|
138 |
* @return
|
139 |
*/
|
140 |
public static GeocodingController getInstance() { |
141 |
if (instance == null) { |
142 |
synchronized (GeocodingController.class) {
|
143 |
if (instance == null) { |
144 |
instance = new GeocodingController();
|
145 |
} |
146 |
} |
147 |
} |
148 |
return instance;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* Run the geocoding process in background
|
153 |
*/
|
154 |
public void geocoding() { |
155 |
PluginServices.cancelableBackgroundExecution(new GeocodingTask(this)); |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Run the indexing process in background
|
160 |
*/
|
161 |
public void indexing() { |
162 |
PluginServices.cancelableBackgroundExecution(new IndexingTask(this)); |
163 |
} |
164 |
|
165 |
/**
|
166 |
* This method loads a Pattern from XML file
|
167 |
*
|
168 |
* @return true if the load is succesfully
|
169 |
*/
|
170 |
public boolean loadPatternFromXML() { |
171 |
boolean ok = true; |
172 |
File thefile = null; |
173 |
JFileChooser jfc = null; |
174 |
/* Show the FileChooser to select a pattern file */
|
175 |
try {
|
176 |
jfc = new JFileChooser(); |
177 |
jfc.setDialogTitle(PluginServices.getText(this,
|
178 |
"load_geoco_pattern"));
|
179 |
String[] extensions = { "xml" }; |
180 |
jfc.setCurrentDirectory(new File("")); |
181 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
182 |
PluginServices.getText(this, "pattern_geoco_file"))); |
183 |
int returnval = jfc
|
184 |
.showOpenDialog((java.awt.Component) PluginServices |
185 |
.getMainFrame()); |
186 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
187 |
thefile = jfc.getSelectedFile(); |
188 |
log.debug("geocoding pattern file opened: " + thefile);
|
189 |
} else {
|
190 |
return false; |
191 |
} |
192 |
} catch (Exception e) { |
193 |
String mes = PluginServices.getText(this, "geocoerrorloadingfile"); |
194 |
String tit = PluginServices.getText(this, "geocoding"); |
195 |
JOptionPane.showMessageDialog(null, mes, tit, |
196 |
JOptionPane.ERROR_MESSAGE);
|
197 |
log.error("Error loading pattern file", e);
|
198 |
} |
199 |
/* Parse the xml file */
|
200 |
PatternLoaderThread load = new PatternLoaderThread(thefile);
|
201 |
load.run(); |
202 |
ok = load.isOk(); |
203 |
if (ok) {
|
204 |
this.gmodel.setPatternFile(load.getFile());
|
205 |
this.gmodel.setPattern(load.getPattern());
|
206 |
} |
207 |
return ok;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* This method gets the list with the address components that the user has
|
212 |
* defined in the Geocoding Preferences
|
213 |
*
|
214 |
* @return
|
215 |
*/
|
216 |
public List<String> getListAddressComponents() { |
217 |
|
218 |
List<String> components = new ArrayList<String>(); |
219 |
PluginServices ps = PluginServices.getPluginServices(this);
|
220 |
XMLEntity xml = ps.getPersistentXML(); |
221 |
|
222 |
String tag = GeocodingExtTags.GEOCODINGELEMENTS + "_" + getLanguage(); |
223 |
if (xml.contains(tag)) {
|
224 |
|
225 |
String nam = String.valueOf(xml.getStringProperty(tag)); |
226 |
File persistenceFile = new File(nam); |
227 |
String str = ""; |
228 |
|
229 |
try {
|
230 |
BufferedReader br = new BufferedReader(new FileReader( |
231 |
persistenceFile)); |
232 |
while ((str = br.readLine()) != null) { |
233 |
components.add(str); |
234 |
} |
235 |
} catch (IOException e) { |
236 |
log.error("Reading the geocoding elements file", e);
|
237 |
} |
238 |
} |
239 |
return components;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* This method gets the application language
|
244 |
*
|
245 |
* @return
|
246 |
*/
|
247 |
private String getLanguage() { |
248 |
|
249 |
ArrayList<Locale> myLocs = org.gvsig.i18n.Messages |
250 |
.getPreferredLocales(); |
251 |
Locale myLoc = myLocs.size() == 0 ? Locale.ENGLISH : myLocs.get(0); |
252 |
|
253 |
/*
|
254 |
* TODO review and test with differente language codes, included Spanish
|
255 |
* languages
|
256 |
*/
|
257 |
String lang = myLoc.getLanguage().toLowerCase();
|
258 |
|
259 |
return lang;
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* This method saves the Geocoding Pattern
|
264 |
*
|
265 |
* @return
|
266 |
*/
|
267 |
public boolean savePattern(GeocodingPattern pat, boolean editing) { |
268 |
|
269 |
boolean savedOK = false; |
270 |
|
271 |
if (!editing) {
|
272 |
|
273 |
JFileChooser jfc = new JFileChooser(); |
274 |
jfc.setDialogTitle(PluginServices.getText(this,
|
275 |
"save_geoco_pattern"));
|
276 |
String[] extensions = { "xml" }; |
277 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
278 |
PluginServices.getText(this, "pattern_geoco_file"))); |
279 |
int returnval = jfc
|
280 |
.showSaveDialog((java.awt.Component) PluginServices |
281 |
.getMainFrame()); |
282 |
|
283 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
284 |
File file = jfc.getSelectedFile();
|
285 |
log.debug("file created: " + file);
|
286 |
if (file != null) { |
287 |
file = GeocodingUtils.addXMLSuffix(file); |
288 |
try {
|
289 |
pat.setPatternName(file.getName()); |
290 |
pat.saveToXML(file); |
291 |
savedOK = true;
|
292 |
log.debug("pattern saved: " + file);
|
293 |
this.gmodel.setPatternFile(file);
|
294 |
/* save the new pattern in the model */
|
295 |
this.getGmodel().setPattern(pat);
|
296 |
} catch (Exception e) { |
297 |
log.error("Serializing the pattern", e);
|
298 |
String mes = PluginServices.getText(this, |
299 |
"geocorrorsavingfile");
|
300 |
String tit = PluginServices.getText(this, "geocoding"); |
301 |
JOptionPane.showMessageDialog(null, mes, tit, |
302 |
JOptionPane.ERROR_MESSAGE);
|
303 |
} |
304 |
} |
305 |
} |
306 |
} |
307 |
// editing pattern (override)
|
308 |
else {
|
309 |
String mes = PluginServices.getText(this, "overridepatternfile"); |
310 |
String tit = PluginServices.getText(this, "geocoding"); |
311 |
int n = JOptionPane.showConfirmDialog(null, mes, tit, |
312 |
JOptionPane.YES_NO_OPTION);
|
313 |
if (n == JOptionPane.OK_OPTION) { |
314 |
try {
|
315 |
File file = this.gmodel.getPatternFile(); |
316 |
pat.saveToXML(file); |
317 |
/* save the new pattern in the model */
|
318 |
this.getGmodel().setPattern(pat);
|
319 |
savedOK = true;
|
320 |
} catch (Exception e) { |
321 |
log.error("Serializing the pattern", e);
|
322 |
String mess = PluginServices.getText(this, |
323 |
"geocorrorsavingfile");
|
324 |
String titt = PluginServices.getText(this, "geocoding"); |
325 |
JOptionPane.showMessageDialog(null, mess, titt, |
326 |
JOptionPane.ERROR_MESSAGE);
|
327 |
} |
328 |
} |
329 |
|
330 |
} |
331 |
|
332 |
return savedOK;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
* This method launches the New Pattern Panel
|
337 |
*
|
338 |
* @param pat
|
339 |
*/
|
340 |
public void launchNewPatternPanel(GeocodingPattern pat) { |
341 |
|
342 |
List<FLyrVect> lyrs = this.getListgvSIGVectLayers(); |
343 |
if (lyrs.size() > 0) { |
344 |
/* Launch the new pattern panel */
|
345 |
NewPatternPanel ppanel = new NewPatternPanel(this, pat); |
346 |
PluginServices.getMDIManager().addWindow(ppanel); |
347 |
ppanel.setVisible(true);
|
348 |
} else {
|
349 |
// show warning message
|
350 |
String title = PluginServices.getText(null, "geocoding"); |
351 |
|
352 |
String message = PluginServices.getText(null, "nolayers"); |
353 |
JOptionPane.showMessageDialog(null, message, title, |
354 |
JOptionPane.WARNING_MESSAGE);
|
355 |
} |
356 |
} |
357 |
|
358 |
/**
|
359 |
* This method updates the GeocodingPanel after save
|
360 |
*/
|
361 |
public void updateGeocoGUI() { |
362 |
// pattern path
|
363 |
gpanel.setJTextPatternPath(this.getGmodel().getPatternFile()
|
364 |
.getAbsolutePath()); |
365 |
// settings. Maximum results availables
|
366 |
gpanel.setParamMaxresults(this.getPattern().getSettings()
|
367 |
.getMaxResultsNumber()); |
368 |
// settings. Minimum score
|
369 |
gpanel.setParamScore(this.getPattern().getSettings().getMinScore());
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* Get the pattern from the geocoding model
|
374 |
*
|
375 |
* @return pattern
|
376 |
*/
|
377 |
public GeocodingPattern getPattern() {
|
378 |
return this.getGmodel().getPattern(); |
379 |
} |
380 |
|
381 |
/**
|
382 |
* Get geocoding model
|
383 |
*
|
384 |
* @return the gmodel
|
385 |
*/
|
386 |
public IGeocodingModel getGmodel() {
|
387 |
return gmodel;
|
388 |
} |
389 |
|
390 |
/**
|
391 |
* Get main geocoding panel
|
392 |
*
|
393 |
* @return the gpanel
|
394 |
*/
|
395 |
public GeocodingPanel getGPanel() {
|
396 |
return gpanel;
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* Get relate geocoding panel
|
401 |
*
|
402 |
* @return the gpanel
|
403 |
*/
|
404 |
public RelatePanel getGRelPanel() {
|
405 |
return relpanel;
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* Get results geocoding panel
|
410 |
*
|
411 |
* @return the gpanel
|
412 |
*/
|
413 |
public ResultsPanel getGResPanel() {
|
414 |
return respanel;
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* Get a list gvSIG Project tables
|
419 |
*
|
420 |
* @return
|
421 |
*/
|
422 |
public DefaultComboBoxModel getModelgvSIGTables() { |
423 |
// get tables loaded in gvSIG project
|
424 |
List<TableDocument> tables = this.getListgvSIGTables(); |
425 |
// Build combo model with list of tables availables
|
426 |
if (tables.size() > 0) { |
427 |
DefaultComboBoxModel comboModel = new DefaultComboBoxModel(); |
428 |
for (int i = 0; i < tables.size(); i++) { |
429 |
TableDocument table = tables.get(i); |
430 |
comboModel.addElement(table); |
431 |
} |
432 |
return comboModel;
|
433 |
} |
434 |
return null; |
435 |
} |
436 |
|
437 |
/**
|
438 |
* Get the address panel from pattern style
|
439 |
*
|
440 |
* @return panel
|
441 |
*/
|
442 |
public AbstractAddressPanel getAddressPanelFromPatternStyle() {
|
443 |
GeocodingPattern pat = this.getPattern();
|
444 |
if (pat != null) { |
445 |
AbstractGeocodingStyle style = pat.getDataSource().getStyle(); |
446 |
Literal lit = style.getRelationsLiteral(); |
447 |
AbstractAddressPanel aPanel = null;
|
448 |
if (style instanceof SimpleCentroid) { |
449 |
aPanel = new AddressSimpleCentroidPanel(this, lit); |
450 |
} |
451 |
if (style instanceof AbstractRange) { |
452 |
aPanel = new AddressRangePanel(this, lit); |
453 |
} |
454 |
if (style instanceof Composed) { |
455 |
aPanel = new AddressComposedPanel(this, lit); |
456 |
} |
457 |
return aPanel;
|
458 |
} |
459 |
return null; |
460 |
} |
461 |
|
462 |
/**
|
463 |
* get loops number of geocoding process
|
464 |
*
|
465 |
* @return
|
466 |
*/
|
467 |
public long getGeocodingProcessCount() { |
468 |
if (this.getGmodel().isSimple()) { |
469 |
return 1; |
470 |
} else {
|
471 |
long n = 0; |
472 |
try {
|
473 |
n = this.getGmodel().getSelectedTableStore().getFeatureSet()
|
474 |
.getSize(); |
475 |
return n;
|
476 |
} catch (Exception e) { |
477 |
return 0; |
478 |
} |
479 |
} |
480 |
} |
481 |
|
482 |
/**
|
483 |
* get JTable Results
|
484 |
*
|
485 |
* @return
|
486 |
*/
|
487 |
public JTable getJTableResults() { |
488 |
return this.gpanel.getJTableResults(); |
489 |
} |
490 |
|
491 |
/**
|
492 |
* Create initial array with list of selected results elements to export
|
493 |
*
|
494 |
* @param results
|
495 |
* @return
|
496 |
*/
|
497 |
public Integer[] createInitialResultsExportElements( |
498 |
List<Set<GeocodingResult>> results) { |
499 |
int cant = results.size();
|
500 |
Integer[] expElems = new Integer[cant]; |
501 |
int i = 0; |
502 |
for (Set<GeocodingResult> res : results) { |
503 |
if (res.size() > 0) { |
504 |
expElems[i] = 0;
|
505 |
} else {
|
506 |
expElems[i] = -1;
|
507 |
} |
508 |
i++; |
509 |
} |
510 |
return expElems;
|
511 |
} |
512 |
|
513 |
/**
|
514 |
* Get current view in gvSIG
|
515 |
*
|
516 |
* @return view
|
517 |
*/
|
518 |
public IView getCurrentView() {
|
519 |
IWindow[] ws = PluginServices.getMDIManager().getOrderedWindows();
|
520 |
for (int k = 0; k < ws.length; k++) { |
521 |
if (ws[k] instanceof IView) { |
522 |
return (DefaultViewPanel) ws[k];
|
523 |
} |
524 |
} |
525 |
return null; |
526 |
} |
527 |
|
528 |
/**
|
529 |
* Get current mapcontrol
|
530 |
*
|
531 |
* @return mapcontrol
|
532 |
*/
|
533 |
public MapControl getMapControl() {
|
534 |
DefaultViewPanel vista = (DefaultViewPanel) this.getCurrentView();
|
535 |
MapContext mapContext = vista.getModel().getMapContext(); |
536 |
MapControl mapControl = new MapControl();
|
537 |
mapControl.setMapContext(mapContext); |
538 |
return mapControl;
|
539 |
} |
540 |
|
541 |
/**
|
542 |
* Get graphics layer
|
543 |
*
|
544 |
* @return graphicslayer
|
545 |
*/
|
546 |
private GraphicLayer getGraphicsLayer() {
|
547 |
|
548 |
// DefaultViewPanel view = (DefaultViewPanel) this.getCurrentView();
|
549 |
//
|
550 |
// MapContextManager graphManager = MapContextLocator.getMapContextManager();
|
551 |
// GraphicLayer graphLayer = graphManager.createGraphicsLayer(view.getProjection());
|
552 |
//
|
553 |
// graphLayer.
|
554 |
MapControl mapControl = this.getMapControl();
|
555 |
GraphicLayer glyr = null;
|
556 |
try {
|
557 |
glyr = mapControl.getMapContext().getGraphicsLayer(); |
558 |
} catch (Exception e) { |
559 |
|
560 |
log.debug("Error getting graphic layer", e);
|
561 |
} |
562 |
return glyr;
|
563 |
} |
564 |
|
565 |
/**
|
566 |
* Centers the view in a point (x,y)
|
567 |
*
|
568 |
* @param x
|
569 |
* @param y
|
570 |
*
|
571 |
* @throws Exception
|
572 |
*/
|
573 |
public void zoomToPoint(double x, double y) throws Exception { |
574 |
|
575 |
MapControl mapControl = this.getMapControl();
|
576 |
|
577 |
Envelope oldExtent = mapControl.getViewPort().getAdjustedEnvelope(); |
578 |
double oldCenterX = oldExtent.getCenter(0); |
579 |
double oldCenterY = oldExtent.getCenter(1); |
580 |
double movX = x - oldCenterX;
|
581 |
double movY = y - oldCenterY;
|
582 |
double minX = oldExtent.getMinimum(0) + movX; |
583 |
double minY = oldExtent.getMinimum(1) + movY; |
584 |
double width = oldExtent.getLength(0); |
585 |
double height = oldExtent.getLength(1); |
586 |
Point pto1 = new Point2D(minX, minY); |
587 |
Point pto2 = new Point2D(minX + width, minY + height); |
588 |
Envelope enve = new Envelope2D(pto1, pto2);
|
589 |
if (enve != null) { |
590 |
mapControl.getViewPort().setEnvelope(enve); |
591 |
} |
592 |
|
593 |
} |
594 |
|
595 |
/**
|
596 |
* Clear all graphics in view
|
597 |
*/
|
598 |
public void clearGeocodingPoint() { |
599 |
DefaultViewPanel view = (DefaultViewPanel) this.getCurrentView();
|
600 |
try {
|
601 |
GraphicLayer grphclyr = this.getGraphicsLayer();
|
602 |
//
|
603 |
if (grphclyr != null) { |
604 |
FeatureSet set = (FeatureSet) grphclyr.getDataStore().getDataSet(); |
605 |
if (set != null && !set.isEmpty()) { |
606 |
grphclyr.clearAllGraphics(); |
607 |
} |
608 |
} |
609 |
// create graphics layer
|
610 |
else{
|
611 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
612 |
manager.createGraphicsLayer(view.getProjection()); |
613 |
} |
614 |
} catch (Exception e) { |
615 |
log.warn("Error with GraphicLayer", e);
|
616 |
} |
617 |
|
618 |
this.getMapControl().drawGraphics();
|
619 |
view.repaint(); |
620 |
view.repaintMap(); |
621 |
|
622 |
} |
623 |
|
624 |
/**
|
625 |
* This method gets the FLyrVect list of the View
|
626 |
*
|
627 |
* @return
|
628 |
*/
|
629 |
public List<FLyrVect> getListgvSIGVectLayers() { |
630 |
|
631 |
List<FLyrVect> layers = new ArrayList<FLyrVect>(); |
632 |
|
633 |
IView view = this.getCurrentView();
|
634 |
|
635 |
if (view != null) { |
636 |
/* Get the layers of the view */
|
637 |
MapControl mapControl = view.getMapControl(); |
638 |
FLayers lyrs = mapControl.getMapContext().getLayers(); |
639 |
if (lyrs.getLayersCount() > 0) { |
640 |
/* Get the layers (FLyrVect) of the view */
|
641 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
642 |
FLayer lyr = lyrs.getLayer(i); |
643 |
if (lyr instanceof FLyrVect) { |
644 |
layers.add((FLyrVect) lyr); |
645 |
} |
646 |
} |
647 |
} |
648 |
} |
649 |
return layers;
|
650 |
} |
651 |
|
652 |
/**
|
653 |
* Get a tables list of gvSIG project
|
654 |
*
|
655 |
* @return
|
656 |
*/
|
657 |
public List<TableDocument> getListgvSIGTables() { |
658 |
|
659 |
List<TableDocument> tables = new ArrayList<TableDocument>(); |
660 |
|
661 |
IWindow[] wins = PluginServices.getMDIManager().getAllWindows();
|
662 |
ProjectWindow projWindow = null;
|
663 |
for (int i = 0; i < wins.length; i++) { |
664 |
if (wins[i] instanceof ProjectWindow) { |
665 |
projWindow = (ProjectWindow) wins[i]; |
666 |
break;
|
667 |
} |
668 |
} |
669 |
if (projWindow != null) { |
670 |
Project p = (Project) projWindow.getWindowModel(); |
671 |
List<Document> documents = p.getDocuments(); |
672 |
for (Document docu : documents) { |
673 |
if (docu instanceof TableDocument) { |
674 |
tables.add((TableDocument) docu); |
675 |
} |
676 |
} |
677 |
} |
678 |
return tables;
|
679 |
} |
680 |
|
681 |
/**
|
682 |
*
|
683 |
* @param result
|
684 |
* @throws LegendLayerException
|
685 |
*/
|
686 |
public void showResultsPositionsOnView(Set<GeocodingResult> result) |
687 |
throws LegendLayerException {
|
688 |
|
689 |
// Add symbology graphicLayer
|
690 |
// FIXME
|
691 |
symbId = addSymbolsGraphicsLayers(); |
692 |
|
693 |
GeocodingSettings sett = this.getPattern().getSettings();
|
694 |
int max = sett.getMaxResultsNumber();
|
695 |
double score = sett.getMinScore();
|
696 |
// get graphic layer
|
697 |
GraphicLayer grphclyr = this.getGraphicsLayer();
|
698 |
long siz = 0; |
699 |
try {
|
700 |
siz = ((FeatureSet) grphclyr.getDataStore().getDataSet()).getSize(); |
701 |
} catch (Exception e) { |
702 |
e.printStackTrace(); |
703 |
} |
704 |
if (siz > 0) { |
705 |
grphclyr.clearAllGraphics(); |
706 |
} |
707 |
|
708 |
int i = 1; |
709 |
for (GeocodingResult res : result) {
|
710 |
if (res.getScore() >= score && i <= max) {
|
711 |
Geometry geom = res.getGeometry(); |
712 |
grphclyr.addGraphic(geom, this.symbId[0]); |
713 |
} |
714 |
i++; |
715 |
} |
716 |
this.getMapControl().drawGraphics();
|
717 |
} |
718 |
|
719 |
/**
|
720 |
*
|
721 |
* @param pto
|
722 |
*/
|
723 |
public void showSingleResultsPositionsOnView(Point pto) { |
724 |
|
725 |
GraphicLayer grphclyr = this.getGraphicsLayer();
|
726 |
grphclyr.clearAllGraphics(); |
727 |
|
728 |
grphclyr.addGraphic(pto, this.symbId[0]); |
729 |
this.getMapControl().drawGraphics();
|
730 |
} |
731 |
|
732 |
/**
|
733 |
* Get selected FLyrVect in view
|
734 |
*
|
735 |
* @return
|
736 |
*/
|
737 |
public FLyrVect getSelectedFLyrVect() {
|
738 |
IView view = this.getCurrentView();
|
739 |
|
740 |
if (view != null) { |
741 |
/* Get the layers of the view */
|
742 |
MapControl mapControl = view.getMapControl(); |
743 |
FLayers lyrs = mapControl.getMapContext().getLayers(); |
744 |
if (lyrs.getActives().length > 0) { |
745 |
return (FLyrVect) lyrs.getLayer(0); |
746 |
} else {
|
747 |
return null; |
748 |
} |
749 |
} |
750 |
return null; |
751 |
} |
752 |
|
753 |
/**
|
754 |
*
|
755 |
*/
|
756 |
private int[] addSymbolsGraphicsLayers() { |
757 |
|
758 |
MapContextManager mapContextManager = MapContextLocator |
759 |
.getMapContextManager(); |
760 |
SymbolManager symManager = mapContextManager.getSymbolManager(); |
761 |
|
762 |
// symManager.registerSymbol(symbolName, symbolClass)
|
763 |
|
764 |
int[] symId = new int[3]; |
765 |
|
766 |
// build symbol RED POINT
|
767 |
if (symManager != null) { |
768 |
|
769 |
ISymbol ptoRed = symManager.createSymbol(Geometry.TYPES.POINT, |
770 |
Color.RED);
|
771 |
if (ptoRed != null) { |
772 |
((SimpleMarkerSymbol) ptoRed) |
773 |
.setStyle(SimpleMarkerSymbol.CIRCLE_STYLE); |
774 |
((SimpleMarkerSymbol) ptoRed).setSize(6);
|
775 |
|
776 |
// build symbol
|
777 |
// SimpleTextSymbol symbolText = new SimpleTextSymbol();
|
778 |
// symbolText.setFont(new Font("Verdana", Font.BOLD, 12));
|
779 |
// symbolText.setTextColor(Color.BLACK);
|
780 |
// symbolText.setText(Integer.toString(i));
|
781 |
|
782 |
// add symbols
|
783 |
GraphicLayer glyrs = this.getGraphicsLayer();
|
784 |
int ptoRedId = glyrs.addSymbol(ptoRed);
|
785 |
|
786 |
// id
|
787 |
symId[0] = ptoRedId;
|
788 |
} |
789 |
} |
790 |
|
791 |
return symId;
|
792 |
} |
793 |
|
794 |
// public void initializeGaphicsLayer(){
|
795 |
// MapContextManager manager = MapContextLocator.getMapContextManager();
|
796 |
// manager.createGraphicsLayer(view.getProjection());
|
797 |
// }
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
} |