Hi,

You can try my solution, it works fine :


import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Style;
import com.google.gwt.maps.client.HasMap;
import com.google.gwt.maps.client.base.LatLng;
import com.google.gwt.maps.client.base.Point;
import com.google.gwt.maps.client.overlay.OverlayView;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;

/**
 * Created with IntelliJ IDEA.
 * User: Hamza
 * Date: 2/21/13
 * Time: 3:41 PM
 * To change this template use File | Settings | File Templates.
 */


public class MapLabel
{
    private Element     div;
    private LatLng      latLng;
    private SimplePanel textPanel;
    private String      text;


    private OverlayView overlay = new OverlayView ()
    {
        @Override
        public void draw ()
        {
            Point sw = (Point) overlay.getProjection 
().fromLatLngToDivPixel (overlay.getMap ().getBounds ().getSouthWest ());
            Point ne = (Point) overlay.getProjection 
().fromLatLngToDivPixel (overlay.getMap ().getBounds ().getNorthEast ());

            Point p = (Point) overlay.getProjection ().fromLatLngToDivPixel 
(latLng);

        //    System.out.println (p.getX () + " " + p.getY ());
        //      div.getStyle ().setTop (ne.getY (), Style.Unit.PX);
        //     div.getStyle ().setLeft (sw.getX (), Style.Unit.PX);

            div.getStyle ().setTop (p.getY (), Style.Unit.PX);
            div.getStyle ().setLeft (p.getX (), Style.Unit.PX);


            div.getStyle ().setWidth (ne.getX ()-sw.getX (), Style.Unit.PX);
            div.getStyle ().setHeight (sw.getY ()-sw.getY (), 
Style.Unit.PX);

            div.getStyle ().setDisplay (Style.Display.BLOCK);
            div.getStyle ().setZIndex (99);

        }

        @Override
        public void onAdd ()
        {
            div = DOM.createElement ("div");
            div.getStyle ().setBorderStyle (Style.BorderStyle.NONE);

            div.getStyle ().setBorderWidth (0, Style.Unit.PX);
            div.getStyle ().setPosition (Style.Position.ABSOLUTE);

            div.appendChild (textPanel.getElement ());
            overlay.getPanes ().getFloatPane ().appendChild (div);
        }

        @Override
        public void onRemove ()
        {
            div.getParentNode ().removeChild (div);
            // div.removeFromParent ();
            textPanel.removeFromParent ();

            div = null;
            textPanel = null;
        }
    };

    public MapLabel (LatLng latLng, String text, HasMap map)
    {

        this.latLng = latLng;

        // System.out.println (latLng.getLatitude () + " - " + 
latLng.getLongitude ());
        this.text = text;

        HTML textWidget = new HTML (text);

        textPanel = new SimplePanel ();
        textPanel.setStyleName ("textOverlayPanel");
        textPanel.add (textWidget);

        //    initOverlay (overlay.getJso ());

        overlay.setMap (map);
    }

}


On Thursday, November 15, 2012 11:27:30 AM UTC, Giorgos Kritsotakis wrote:
>
> Hello,
>
> I have implemented a gwt map widget for the company that i'm working for. 
> Everything works great with markers, rectangles et cetera. 
>
> The problem is that we need labels (like the white labels used for country 
> names on the
> map for instance) on the map and there seems to be a problem with the 
> OverlayView class. 
>
> I am supposed to extend OverlayView and implement onAdd, onRemove and draw,
> but those methods are now declared final.
>
> From what I have seen, it is a matter of Overlays introduced to GWT, the 
> JavascriptObject class 
> being changed, and the api not following up. Even the javadoc is outdated. 
> The documentation isn't helping
> and all of the articles and tutorials I have found on the net are about 
> previous editions of 
> the maps library.
>
> Can anybody who has done something similar point me to the right direction?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to