On Friday, November 16, 2012 11:53:16 AM UTC, Giorgos Kritsotakis wrote:
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(instance.@gr.palmera.maps.client.MapLabel::myDraw() ());
};
jso.onAdd = function() {
$entry(instance.@gr.palmera.maps.client.MapLabel::myOnAdd( )());
};
jso.onRemove = function() {
$entry(instance.@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 unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@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.
No comments:
Post a Comment