Google Maps used from a Groovy SwingBuilder





7
Date Submitted Thu. Mar. 22nd, 2007 4:30 PM
Revision 1 of 1
Helper glaforge
Tags google | groovy
Comments 1 comments
Using the SwingX JXMapViewer and using a special tile factory to retrieve Google Maps tiles, from a Groovy SwingBuilder.

import java.awt.*
import java.awt.BorderLayout as BL

import javax.swing.WindowConstants as WC

import org.jdesktop.swingx.mapviewer.*
import org.jdesktop.swingx.JXMapViewer

import groovy.swing.SwingBuilder


def mapViewer = new JXMapViewer()
def tfi = new TileFactoryInfo(0, 20, 17, 256, true, true, "http://mt.google.com/mt?w=2.43", "x", "y", "zoom")

mapViewer.tileFactory = new DefaultTileFactory(tfi)
mapViewer.zoom = 9
mapViewer.centerPosition = [43.835, 2.329]
mapViewer.preferredSize = [800, 600]

frame = new SwingBuilder().frame(title: 'Groovy Maps', defaultCloseOperation: WC.DISPOSE_ON_CLOSE) {
    panel(layout: new BL()) {
        panel(constraints: BL.CENTER) { widget(mapViewer) }
        panel(constraints: BL.SOUTH) {
            button(text: "+", actionPerformed: { mapViewer.zoom -= 1 })
            button(text: "-", actionPerformed: { mapViewer.zoom += 1 })
        }
    }
}

frame.pack()
frame.visible = true
 

Guillaume Laforge

glaforge.free.fr/blog/groovy

Comments

Comments Nice
Wed. Jun. 6th, 2007 3:43 PM    Newbie tom_zeng

Voting