Example usage for com.google.gwt.maps.client.overlays MapCanvasProjection fromLatLngToDivPixel

List of usage examples for com.google.gwt.maps.client.overlays MapCanvasProjection fromLatLngToDivPixel

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.overlays MapCanvasProjection fromLatLngToDivPixel.

Prototype

public final native Point fromLatLngToDivPixel(LatLng latlng) ;

Source Link

Document

Computes the pixel coordinates of the given geographical location in the DOM element that holds the draggable map.

Usage

From source file:com.google.gwt.maps.testing.client.maps.OverlayViewMapWidget.java

License:Apache License

private void drawOverlay_Generic_OverlayView() {
    OverlayViewOnDrawHandler onDrawHandler = new OverlayViewOnDrawHandler() {
        @Override//from  w w w .ja  v a  2 s . c om
        public void onDraw(OverlayViewMethods methods) {
            MapCanvasProjection projection = methods.getProjection();
            LatLng sw = LatLng.newInstance(40.710216, -74.213393);
            Point p = projection.fromLatLngToDivPixel(sw);
            htmlOverlayMessage.getElement().getStyle().setPosition(Position.ABSOLUTE);
            htmlOverlayMessage.getElement().getStyle().setLeft(p.getX(), Unit.PX);
            htmlOverlayMessage.getElement().getStyle().setTop(p.getY(), Unit.PX);

            String message = "OverlayView draw() called... the projection world width is "
                    + projection.getWorldWidth();
            htmlOverlayMessage.clear();
            htmlOverlayMessage.add(new HTML(message));
            System.out.println(message);
        }
    };

    OverlayViewOnAddHandler onAddHandler = new OverlayViewOnAddHandler() {
        @Override
        public void onAdd(OverlayViewMethods methods) {
            MapCanvasProjection projection = methods.getProjection();
            String message = "OverlayView add() called... the projection world width is "
                    + projection.getWorldWidth();
            System.out.println(message);

            methods.getPanes().getFloatPane().appendChild(htmlOverlayMessage.getElement());
        }
    };

    OverlayViewOnRemoveHandler onRemoveHandler = new OverlayViewOnRemoveHandler() {
        @Override
        public void onRemove(OverlayViewMethods methods) {
            String message = "OverlayView remove() called...";
            System.out.println(message);

            // remove existing nodes
            htmlOverlayMessage.getElement().removeFromParent();
        }
    };

    customOverlayView = OverlayView.newInstance(mapWidget, onDrawHandler, onAddHandler, onRemoveHandler);
}