Google map addon

Hi Henri! This is a great add-on indeed. Are the directions going to be supported?

Sorry, I can’t find that method! It seems that org.vaadin.hezamu.googlemapwidget.GoogleMap class hasn’t it.
Please, check also the source code at
this link

Regards

That method is in MapWidget class which is referenced by GoogleMap.

Can anyone suggest how to simulate a marker click, in a way that, as soon as the marker is added to the map, its content window is automatically opened?

Thanks a lot!
Iacopo

Hi Henry,
I added a MapType using method

public void addMapType(String name, int minZoom, int maxZoom, String copyright, String tileUrl, boolean isPng, double opacity) {

but when I change page and then I return back on my map, the additional map type are no longer added to the map?
Do you have the same behaviour?

Hi everyone…

I struggled to make map addon to work with Vaadin 6.7.5 in Maven project. When compiling the widgetset the gwt-library depencies are a mess… I got following message when compiling the widgetset :


java.lang.IncompatibleClassChangeError: Found interface 
com.google.gwt.core.ext.typeinfo.JClassType, but class was expected 

But I managed to solve this issue. Vaadin 6.7.5 uses Gwt 2.3.0 and you need to declare these as your depencies.



 
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <!-- Version 2.0.0 works with Vaadin 6.2.7 -->
            <!--<version>2.0.0</version>-->
            <version>2.3.0</version>
            <!--<scope>provided</scope>-->
        </dependency>
        
       <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-dev</artifactId>
            <!-- Version 2.0.0 works with Vaadin 6.2.7 -->
            <!--<version>2.0.0</version>-->
            <version>2.3.0</version>
            <!--<scope>provided</scope>-->
        </dependency>
        

The only gwt-maps library that I was able to find was 1.0.4 and that does not work with Gwt 2.3.0. Luckily I managed to find repository which contains new version of the map-library which is compiled to be compatible with 2.3.0 Gwt. Here is the repository:



 <repository> 
            <id>bedatadriven-public</id> 
            <name>Bedatadriven Public Repo</name> 
            <url>http://nexus.bedatadriven.com/content/groups/public</url> 
            <snapshots> 
                <enabled>true</enabled> 
            </snapshots> 
        </repository> 

And the depency :



<dependency> 
            <groupId>com.google.gwt.google-apis</groupId> 
            <artifactId>gwt-maps</artifactId> 
            <version>1.1.0</version> 
            <classifier>gwt23</classifier> 
            <scope>provided</scope> 
        </dependency> 

You also need to use matching version of the gwt-compiler plugin :



<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.3.0</version> 
                <!-- Working version with Vaadin 6.2.7 -->
                <!--<version>1.3-SNAPSHOT</version>-->
                <executions>
                    <execution>
                        <configuration>
                            <webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets</webappDirectory>
                            <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                            <runTarget>GoogleMapComponent</runTarget>
                            <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
                            <noServer>true</noServer>
                            <port>8080</port>
                            <soyc>false</soyc>
                        </configuration>
                        <goals>
                            <goal>resources</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin> 

The google map addon was :



<dependency>
            <groupId>org.vaadin.addons</groupId>
            <artifactId>googlemapwidget</artifactId>
            <version>0.9.13</version>
        </dependency>

With all of these I was able to compile Vaadin google map addon as maven project with Vaadin 6.7.5. I hope it helps someone.

Best Regards Tuomas

Hi,
I downloaded the google map addon and I looked inside googlemapwidget-0.9.13.jar but I cannot find any API html documentation.
Can you tell me if I can find the documentation somewhere else, or do I need to generate the javadoc?
Many thanks,
-George Soler

Awesome add-on, but there is a way that I can get a Screenshot of the current map view?, I mean exporting the map to png or something like that… thanks

I have been working through the pieces,

For others who are following this thread…
- Netbeans 7.1.2 the netbeans plugin for vaadin is old but you can update it manually …os = windows xp

googlemapwidget-0.9.13 i.e. replace the gwt-map.jar file with
gwt-map-1.1.1.zip

vaadin-6.8.1
gwt-dev-2.3.0
java 1.6
tomcat 7.0

[b]

Windows version Netbeans 7.1.2[

/b]
- add
vaadin plugin
,
- edit %user%/.netbeans/7.1.2/build.properties
- search for[quote]
libs.Vaadin.classpath
[/quote]
- change = \vaadin-6.8.1.jar ---- or copy the
jar
to the windows path i.e. %user%\.netbeans\7.1.2\libs\vaadin6.8.1.jar

  1. modify -
    build-widgetset.xml

  2. ant -f build-widgetset.xml

  3. trouble shooting

a) You may need to edit = ( this may be handled by the project editor but if after adding you Jars you should check this file if you have failures)
C:\Users\ww.netbeans\7.1
- build.properties
- libs/vaadin-6.2.3.jar - renamed to vaadin-6.2.3.jar.save and added vaadin-6.8.1.jar

b) Check netbeans > Files > nbproject >
- project.properties
- project.xml
generally you should not need to edit these but if you change any names from the Gui files you may need to edit these.


build-widgetset.xml example :

  • This is the Netbeans widgetset.xml builder NOT the Eclipse version which may handle this automagically:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Compile Vaadin Widgetset" default="compile-widgetset" basedir=".">
    <description>Compiles a combined widgetset of all Vaadin widgetsets found on the classpath.</description>

    <!--
        Important notice!!
        This Ant script depends on the NetBeans project specific build-impl.xml
        file. If you want to use this script in some other environment, you need
        to manually create init and compile targets and define required properties.

        See also http://demo.vaadin.com/docs/example-source/build-widgetset.xml
        for another example script.
    -->
    <import file="nbproject/build-impl.xml"/>

    <target name="widgetset-init">
        <!-- Name of the widget set -->
        <property name="widgetset" value="com.mycompany.vaadin.widgetset.GoogleMapWidgetSet"/>

        <!-- Path to the widgetset directory. Required only for -->
    	<!-- generated widget sets. Must be relative to         -->
    	<!-- $src.dir, that is, under the first entry in        -->
    	<!-- classpath.                                         -->
       	<property name="widgetset-path" value="com/mycompany/vaadin/widgetset"/>

        <!-- Target where to compile the widget set -->
        <property name="client-side-destination" value="web/VAADIN/widgetsets" />

        <!-- Define if the widget set be generated automatically -->
        <!-- from all widget sets included in the class path.    -->
        <property name="generate.widgetset" value="1"/>
    </target>


    <!-- Generates a combined widget set from all widget    -->
    <!-- sets in the class path, including project sources. -->
    <!-- Updates the configuration if it already exists.    -->
    <target name="generate-widgetset" depends="widgetset-init, compile" if="generate.widgetset">
        <echo>Updating ${widgetset}...</echo>
        <echo>Remember to define the widgetset in web.xml as follows.</echo>
        <echo>
            &lt;init-param&gt;
                &lt;param-name&gt;widgetset&lt;/param-name&gt;
                &lt;param-value&gt;${widgetset}&lt;/param-value&gt;
            &lt;/init-param&gt;
        </echo>

        <!-- Create the directory if it does not already exist. -->
        <mkdir dir="${src.dir}/${widgetset-path}"/>

        <java classname="com.vaadin.terminal.gwt.widgetsetutils.WidgetSetBuilder" failonerror="yes" fork="yes" maxmemory="256m">
            <arg value="${widgetset}"/>
            <jvmarg value="-Xss1024k"/>
            <jvmarg value="-Djava.awt.headless=true"/>
            <classpath>
                <pathelement path="${src.dir}" />
                <pathelement path="${javac.classpath}" />
                <pathelement path="${build.web.dir}/WEB-INF/classes" />
            </classpath>
        </java>
    </target>

    <!-- Compiles the widget set using the GWT compiler. -->
    <target name="compile-widgetset" depends="init, widgetset-init, generate-widgetset">
        <echo>Compiling ${widgetset} into ${client-side-destination} directory...</echo>
        
        <java classname="com.google.gwt.dev.Compiler" failonerror="yes" fork="yes" maxmemory="256m">
            <arg value="-war" />
            <arg value="${client-side-destination}" />
            <arg value="${widgetset}" />
            <jvmarg value="-Xss1024k"/>
            <jvmarg value="-Djava.awt.headless=true"/>
            <classpath>
                <pathelement path="${src.dir}" />
                <pathelement path="${javac.classpath}" />
                <pathelement path="${build.web.dir}/WEB-INF/classes" />
            </classpath>
        </java>
    </target>

</project>

Netbeans> project view > Configuration Files > web.xml

Copied from the build-widgetset.xml build screen into this file

widgetset
com.mycompany.vaadin.widgetset.GoogleMapWidgetSet

See Below:


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>VaadinApplication</servlet-name>
        <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
        <init-param>
            <param-name>application</param-name>
            <param-value>com.mycompany.vaadin.Firstapp</param-value>
        </init-param>
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.mycompany.vaadin.widgetset.GoogleMapWidgetSet</param-value>
        </init-param>        
    </servlet>
    <servlet-mapping>
        <servlet-name>VaadinApplication</servlet-name>
        <url-pattern>/firstapp/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>VaadinApplication</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file/>
    </welcome-file-list>
</web-app>

Demo Code:
-Henri 's demo - Thanks henri.


/*
 * Firstapp.java
 *
 * Created on July 11, 2012, 6:41 PM
 */
 
package com.mycompany.vaadin;           



import com.vaadin.Application;
import com.vaadin.ui.*;
import com.vaadin.data.*;

import org.vaadin.hezamu.googlemapwidget.*;


import java.awt.geom.Point2D;
import org.vaadin.hezamu.googlemapwidget.overlay.*;


/** 
 *
 * @author w bush
 * @version 
 */

public class Firstapp extends Application {

    
    GoogleMap makeGoogleMap(Double lat, Double lon)
    {
        // Create a new map instance centered on the IT Mill offices
        GoogleMap googleMap = new GoogleMap(this,new Point2D.Double(lat,lon), 9);
        googleMap.setWidth("800px");
        googleMap.setHeight("600px");

        // Create a marker at the IT Mill offices
        googleMap.addMarker(new BasicMarker(1L, new Point2D.Double(lat,lon), "Test marker " + lat +","+lon));
        return googleMap;
    }
    
    
    @Override
    public void init() {
	Window mainWindow = new Window("Firstapp");
        Label label = new Label("Hello Vaadin user");
        
	mainWindow.addComponent(label);
	mainWindow.addComponent(makeGoogleMap(22.3, 60.4522));
	setMainWindow(mainWindow);
    }
}

Errors :frowning:

widget compile errors. How to resolve these?

Chris


Forum message 1


Forum message 2

Dear Henri , I want use Polygon create an circle on google map, but I don’t know how to make the Point2D.Double for a circle , would you give me an eg. or some advise . Thank you!

Unfortunately the old GWT Maps API used by the add-on does not support circles. You could circumvent the problem by calculating a set of points along the circle of desired radius, but this will result in a circular polygon instead of a true circle.

You can find the math and plenty of implementations for this simply by googling “points on a circle” - see e.g.
this page
.

Just a quick heads up regarding widgetset compile errors with the latest version of the add-on: please see
this post
for instructions on how to fix the problem.

If you are using Maven and do not want to mess with the JAR dependencies by hand, you can fix the problem by following
the instructions
earlier in this thread by Tuomas Katva.

Note that the prerelease Maps v3 wrapper released earlier this year will not work with this add-on, it requires the v2 version. I will look at updating the add-on to v3 after Google releases a final version of the v3 wrapper.

Thank you guys,I work out this way :
It is not a true circle ,but likely
float radius=3; /
double d2r= Math.PI/180;
double r2d=180/Math.PI;
double clat= (radius/3963.189)*r2d; // Convert statute miles into degrees latitude
double clng=clat/Math.cos(myPosMarker.getLatLng().getY()*d2r);
Point2D.Double cornerss = new Point2D.Double[330]
; // more points,more like circle
for (int i=0;i< cornerss.length;i++) {
double theta = Math.PI * ((double)i / 16);
double cy=myPosMarker.getLatLng().getX()+(clng * Math.sin(theta));
double cx=myPosMarker.getLatLng().getY()+(clat * Math.cos(theta));
Point2D.Double point = new Point2D.Double(cy, cx);
cornerss[i]
=point;

     }

Polygon poly=new Polygon(12L, cornerss, “#FF0000”, 1, 0.5, “#000000”, 0.1, true);

googleMap.addPolyOverlay(poly);

I’m getting multiple errors when compiling the widget set, using the sample project:

What’s the problem and how do I solve it?

Alternatively, does anyone have a working maven/eclipse project of the demo uploaded?

I’m not sure if the error has to do with the maps add-on. Are you sure you have everything in your classpath?

I solved the problem by switching from the add-on’s uncompiled source code (oops) to the maven dependency. Then I created an eclipse maven project, copied the gwt-maps.jar (1.1.1) to the web-inf lib and drag-n-dropped the widget jar to the web-inf/lib to trigger the autocompilation, which completed successfully. Everything worked after that.


However, this raised another question: If I created a vaadin project from the clean maven archetype, how do I trigger the widgetset autocompilation in Eclipse? Will the vaadin plugin detect drag-n-dropped addons/widgetsets?
Turns out the answer was here:
Using+Vaadin+with+Maven-UsingVaadinAddOnsWithMaven

But are there any other archetypes with widgetset compilation support out of the box?

Now I’m getting the same problem as before. Everything works if I create a new Vaadin project inside eclipse and drop the addon jars to web-inf/lib, but when I try to use the same technique for an existing maven project, I get the above errors.

What exactly do I need to have in my classpath?

I’m not big on Maven, but I understand that you shouldn’t just copy stuff to lib/. Perhaps
this post
is of help?