I have been able to draw the label, still I can't get the positioning 
right. This is the code in case someone wants to do something similar:


public class MapLabel {
    private Element div;
    private LatLng latLng;
    private SimplePanel textPanel;
    private String text;
    private OverlayView overlay = OverlayView.create();

    public MapLabel(LatLng latLng, String text, GoogleMap map) { 
    
        this.latLng = latLng;
        this.text = text;

        HTML textWidget = new HTML(text);

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

        initOverlay(overlay);
    
        overlay.setMap(map);
    }

    private final native void initOverlay(JavaScriptObject jso) /*-{
        var instance = this;

        jso.draw = function() {
            $entry(instan...@gr.palmera.maps.client.MapLabel::myDraw()());
        };

        jso.onAdd = function() {
            $entry(instan...@gr.palmera.maps.client.MapLabel::myOnAdd()());
        };

        jso.onRemove = function() {
            
$entry(instan...@gr.palmera.maps.client.MapLabel::myOnRemove()());
        };
    }-*/;

    public void myDraw() {
        Point ne = 
overlay.getProjection().fromLatLngToDivPixel(overlay.getMap().getBounds().getNorthEast());
        Point sw = 
overlay.getProjection().fromLatLngToDivPixel(overlay.getMap().getBounds().getSouthWest());

        Point p = overlay.getProjection().fromLatLngToDivPixel(latLng);
        
        div.getParentElement().getStyle().setTop(p.getY(), Unit.PX);
        div.getParentElement().getStyle().setLeft(p.getX(), Unit.PX); 
        
        div.getStyle().setWidth(100, Unit.PX);
        div.getStyle().setHeight(25, Unit.PX);
    }

    public void myOnAdd() {
        div = DOM.createDiv();
        div.appendChild(textPanel.getElement());
        overlay.getPanes().getFloatPane().appendChild(div);
    }

    public void myOnRemove() {
        div.removeFromParent();
        textPanel.removeFromParent();

        div = null;
        textPanel = null;
    }
}

 

 

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/c46RD99JP5EJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to