root / trunk / extensions / extScripting / scripts / jython / centerViewToPoint.xml @ 5892
History | View | Annotate | Download (2.89 KB)
1 | 5782 | jmvivo | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|---|---|---|
2 | <!-- generated by ThinG, the Thinlet GUI editor -->
|
||
3 | <panel columns="3" gap="3"> |
||
4 | <script language="jython"> |
||
5 | <![CDATA[
|
||
6 | True = 1 == 1
|
||
7 | False = 0 == 1
|
||
8 | |||
9 | |||
10 | import java.awt.geom.Point2D as Point2D
|
||
11 | import java.awt.geom.Rectangle2D as Rectangle2D
|
||
12 | 5892 | jmvivo | import java.awt.Color as Color
|
13 | 5782 | jmvivo | |
14 | #import com.iver.andami.PluginServices as PluginServices
|
||
15 | |||
16 | #import com.iver.cit.gvsig.gui.View as View
|
||
17 | |||
18 | 5892 | jmvivo | FSymbol = gvSIG.classForName("com.iver.cit.gvsig.fmap.core.v02.FSymbol")
|
19 | FConstant = gvSIG.classForName("com.iver.cit.gvsig.fmap.core.v02.FConstant")
|
||
20 | FGraphic = gvSIG.classForName("com.iver.cit.gvsig.fmap.rendering.FGraphic")
|
||
21 | ShapeFactory = gvSIG.classForName("com.iver.cit.gvsig.fmap.core.ShapeFactory")
|
||
22 | 5782 | jmvivo | |
23 | 5892 | jmvivo | |
24 | |||
25 | |||
26 | def getFMap():
|
||
27 | 5782 | jmvivo | #vista = PluginServices.getMDIManager().getActiveView()
|
28 | vista = gvSIG.getActiveDocument()
|
||
29 | if vista == None:
|
||
30 | return None
|
||
31 | |||
32 | |||
33 | #
|
||
34 | #if not isintance(vista,View):
|
||
35 | # return None
|
||
36 | |||
37 | try:
|
||
38 | 5892 | jmvivo | fmap = vista.getModel().getMapContext()
|
39 | 5782 | jmvivo | except:
|
40 | return None
|
||
41 | |||
42 | 5892 | jmvivo | if fmap.getLayers().getLayersCount() < 1:
|
43 | 5782 | jmvivo | return None
|
44 | |||
45 | 5892 | jmvivo | return fmap
|
46 | 5782 | jmvivo | |
47 | def zoomToCoordinates():
|
||
48 | 5892 | jmvivo | if fMap == None:
|
49 | 5782 | jmvivo | return
|
50 | try:
|
||
51 | 5892 | jmvivo | oldExtent = fMap.getViewPort().getAdjustedExtent()
|
52 | 5782 | jmvivo | oldCenterX = oldExtent.getCenterX()
|
53 | oldCenterY = oldExtent.getCenterY()
|
||
54 | centerX = float(thinlet.getString(txtX, "text"))
|
||
55 | centerY = float(thinlet.getString(txtY, "text"))
|
||
56 | center=Point2D.Double(centerX,centerY)
|
||
57 | movX = centerX-oldCenterX
|
||
58 | movY = centerY-oldCenterY
|
||
59 | upperLeftCornerX = oldExtent.getMinX()+movX
|
||
60 | upperLeftCornerY = oldExtent.getMinY()+movY
|
||
61 | width = oldExtent.getWidth()
|
||
62 | height = oldExtent.getHeight()
|
||
63 | extent = Rectangle2D.Double(upperLeftCornerX, upperLeftCornerY, width, height)
|
||
64 | 5892 | jmvivo | fMap.getViewPort().setExtent(extent)
|
65 | return center
|
||
66 | 5782 | jmvivo | except ValueError:
|
67 | print "Error en los parametros: %s, %s" % (e.__class__, e)
|
||
68 | 5892 | jmvivo | |
69 | def drawPoint(center, color=None):
|
||
70 | if color == None:
|
||
71 | color = Color.blue
|
||
72 | lyr.clearAllGraphics()
|
||
73 | theSymbol = FSymbol(FConstant.SYMBOL_TYPE_POINT,color)
|
||
74 | idSymbol = lyr.addSymbol(theSymbol)
|
||
75 | geom = ShapeFactory.createPoint2D(center.getX(),center.getY())
|
||
76 | theGraphic = FGraphic(geom, idSymbol)
|
||
77 | lyr.addGraphic(theGraphic)
|
||
78 | |||
79 | 5782 | jmvivo | |
80 | 5892 | jmvivo | fMap = getFMap()
|
81 | 5782 | jmvivo | |
82 | 5892 | jmvivo | if fMap==None:
|
83 | 5782 | jmvivo | thinlet.setBoolean(botAplicar,"enabled",False)
|
84 | else:
|
||
85 | thinlet.setBoolean(botAplicar,"enabled",True)
|
||
86 | 5892 | jmvivo | lyr=fMap.getGraphicsLayer()
|
87 | 5782 | jmvivo | |
88 | 5892 | jmvivo | def doAction():
|
89 | center = zoomToCoordinates()
|
||
90 | drawPoint(center)
|
||
91 | 5782 | jmvivo | |
92 | ]]>
|
||
93 | </script>
|
||
94 | <label colspan="3" text="Coordenadas a centrar en la vista"/> |
||
95 | <label colspan="2" halign="right" text="x:"/> |
||
96 | <textfield name="txtX"/> |
||
97 | <label colspan="2" halign="right" text="y:"/> |
||
98 | <textfield name="txtY"/> |
||
99 | <panel colspan="3" gap="2" halign="right"> |
||
100 | 5892 | jmvivo | <button halign="right" name="botAplicar" text="Aplicar" action="doAction()"/> |
101 | 5782 | jmvivo | <button halign="right" name="botCerrar" text="Cerrar" action="thinlet.closeWindow()"/> |
102 | </panel>
|
||
103 | </panel> |