Revision 5892 trunk/extensions/extScripting/scripts/jython/centerViewToPoint.xml

View differences:

centerViewToPoint.xml
9 9

  
10 10
import java.awt.geom.Point2D as Point2D
11 11
import java.awt.geom.Rectangle2D as Rectangle2D
12
import java.awt.Color as Color
12 13

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

  
15 16
#import com.iver.cit.gvsig.gui.View as View
16 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")
17 22

  
18
def getMapControl():
23

  
24

  
25

  
26
def getFMap():
19 27
  #vista = PluginServices.getMDIManager().getActiveView()
20 28
  vista = gvSIG.getActiveDocument()
21 29
  if vista == None:
......
27 35
  #  return None
28 36

  
29 37
  try:
30
  	mapa = vista.getModel().getMapContext()
38
  	fmap = vista.getModel().getMapContext()
31 39
  except:
32 40
  	return None
33 41

  
34
  if mapa.getLayers().getLayersCount() < 1:
42
  if fmap.getLayers().getLayersCount() < 1:
35 43
    return None
36 44

  
37
  return mapa
45
  return fmap
38 46

  
39 47
def zoomToCoordinates():
40
  if mapControl == None:
48
  if fMap == None:
41 49
  	return
42 50
  try:
43
    oldExtent = mapControl.getViewPort().getAdjustedExtent()
51
    oldExtent = fMap.getViewPort().getAdjustedExtent()
44 52
    oldCenterX = oldExtent.getCenterX()
45 53
    oldCenterY = oldExtent.getCenterY()
46 54
    centerX = float(thinlet.getString(txtX, "text"))
......
53 61
    width = oldExtent.getWidth()
54 62
    height = oldExtent.getHeight()
55 63
    extent = Rectangle2D.Double(upperLeftCornerX, upperLeftCornerY, width, height)
56
    mapControl.getViewPort().setExtent(extent)
64
    fMap.getViewPort().setExtent(extent)
65
    return center
57 66
  except ValueError:
58 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

  
59 79
	
60
mapControl = getMapControl()
80
fMap = getFMap()
61 81

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

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

  
68 92
]]>
69 93
	</script>
......
73 97
    <label colspan="2" halign="right" text="y:"/>
74 98
    <textfield name="txtY"/>
75 99
    <panel colspan="3" gap="2" halign="right">
76
        <button halign="right" name="botAplicar" text="Aplicar" action="zoomToCoordinates()"/>
100
        <button halign="right" name="botAplicar" text="Aplicar" action="doAction()"/>
77 101
        <button halign="right" name="botCerrar" text="Cerrar" action="thinlet.closeWindow()"/>
78 102
    </panel>
79 103
</panel>

Also available in: Unified diff