Statistics
| Revision:

root / trunk / extensions / extScripting / scripts / jython / centerViewToPoint.xml @ 5892

History | View | Annotate | Download (2.89 KB)

1
<?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
import java.awt.Color as Color
13

14
#import com.iver.andami.PluginServices as PluginServices
15

16
#import com.iver.cit.gvsig.gui.View as View
17

18
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

23

24

25

26
def getFMap():
27
  #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
          fmap = vista.getModel().getMapContext()
39
  except:
40
          return None
41

42
  if fmap.getLayers().getLayersCount() < 1:
43
    return None
44

45
  return fmap
46

47
def zoomToCoordinates():
48
  if fMap == None:
49
          return
50
  try:
51
    oldExtent = fMap.getViewPort().getAdjustedExtent()
52
    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
    fMap.getViewPort().setExtent(extent)
65
    return center
66
  except ValueError:
67
    print "Error en los parametros: %s, %s" % (e.__class__, e)
68

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
        
80
fMap = getFMap()
81

82
if fMap==None:
83
        thinlet.setBoolean(botAplicar,"enabled",False)
84
else:
85
        thinlet.setBoolean(botAplicar,"enabled",True)
86
        lyr=fMap.getGraphicsLayer()
87

88
def doAction():
89
    center = zoomToCoordinates()
90
    drawPoint(center)
91

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
        <button halign="right" name="botAplicar" text="Aplicar" action="doAction()"/>
101
        <button halign="right" name="botCerrar" text="Cerrar" action="thinlet.closeWindow()"/>
102
    </panel>
103
</panel>