Search in sources :

Example 1 with CircleOptions

use of org.peimari.gleaflet.client.CircleOptions in project v-leaflet by mstahv.

the class LeafletCircleConnector method update.

@Override
protected void update() {
    if (marker != null) {
        removeLayerFromParent();
        marker.removeClickListener();
        marker.removeMouseOverListener();
        marker.removeMouseOutListener();
        marker.removeContextMenuListener();
    }
    LatLng latlng = LatLng.create(getState().point.getLat(), getState().point.getLon());
    CircleOptions options = createOptions();
    marker = Circle.create(latlng, getState().radius, options);
    // for some reasone bugs currently without this...
    marker.setRadius(getState().radius);
    addToParent(marker);
    marker.addClickListener(new ClickListener() {

        @Override
        public void onClick(MouseEvent event) {
            rpc.onClick(U.toPoint(event.getLatLng()), MouseEventDetailsBuilder.buildMouseEventDetails(event.getNativeEvent(), getLeafletMapConnector().getWidget().getElement()));
        }
    });
    if (hasEventListener(EventId.MOUSEOVER)) {
        /*
             * Add listener lazily to avoid extra event if layer is modified in
             * server side listener. This can be removed if "clear and rebuild"
             * style component updates are changed into something more
             * intelligent at some point.
             */
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                marker.addMouseOverListener(new MouseOverListener() {

                    @Override
                    public void onMouseOver(MouseEvent event) {
                        mouseOverRpc.onMouseOver(U.toPoint(event.getLatLng()));
                    }
                });
            }
        });
    }
    if (hasEventListener(EventId.MOUSEOUT)) {
        marker.addMouseOutListener(new MouseOutListener() {

            @Override
            public void onMouseOut(MouseEvent event) {
                mouseOutRpc.onMouseOut(U.toPoint(event.getLatLng()));
            }
        });
    }
    if (hasEventListener(EventId.CONTEXTMENU)) {
        marker.addContextMenuListener(new ContextMenuListener() {

            @Override
            public void onContextMenu(MouseEvent event) {
                contextMenuRpc.onContextMenu(U.toPoint(event.getLatLng()), MouseEventDetailsBuilder.buildMouseEventDetails(event.getNativeEvent(), getLeafletMapConnector().getWidget().getElement()));
            }
        });
    }
}
Also used : MouseOutListener(org.peimari.gleaflet.client.MouseOutListener) MouseEvent(org.peimari.gleaflet.client.MouseEvent) CircleOptions(org.peimari.gleaflet.client.CircleOptions) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) MouseOverListener(org.peimari.gleaflet.client.MouseOverListener) ContextMenuListener(org.peimari.gleaflet.client.ContextMenuListener) LatLng(org.peimari.gleaflet.client.LatLng) ClickListener(org.peimari.gleaflet.client.ClickListener)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 CircleOptions (org.peimari.gleaflet.client.CircleOptions)1 ClickListener (org.peimari.gleaflet.client.ClickListener)1 ContextMenuListener (org.peimari.gleaflet.client.ContextMenuListener)1 LatLng (org.peimari.gleaflet.client.LatLng)1 MouseEvent (org.peimari.gleaflet.client.MouseEvent)1 MouseOutListener (org.peimari.gleaflet.client.MouseOutListener)1 MouseOverListener (org.peimari.gleaflet.client.MouseOverListener)1