Search in sources :

Example 1 with MouseEvent

use of org.peimari.gleaflet.client.MouseEvent 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)

Example 2 with MouseEvent

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

the class LeafletCircleMarkerConnector 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());
    CircleMarkerOptions options = createOptions();
    marker = CircleMarker.create(latlng, options);
    final double radius = getState().radius;
    // TODO workaround to Leaflet bug, report
    marker.setRadius(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) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) MouseOverListener(org.peimari.gleaflet.client.MouseOverListener) CircleMarkerOptions(org.peimari.gleaflet.client.CircleMarkerOptions) ContextMenuListener(org.peimari.gleaflet.client.ContextMenuListener) LatLng(org.peimari.gleaflet.client.LatLng) ClickListener(org.peimari.gleaflet.client.ClickListener)

Example 3 with MouseEvent

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

the class LeafletMarkerConnector 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());
    MarkerOptions options = createOptions();
    URLReference urlReference = getState().resources.get("icon");
    String divIcon = getState().divIcon;
    if (urlReference != null && urlReference.getURL().startsWith("fonticon://")) {
        String pathFill = getState().iconPathFill != null ? getState().iconPathFill : "#44AEEA";
        String pathStroke = getState().iconPathStroke != null ? getState().iconPathStroke : "#005FA8";
        String textFill = getState().iconTextFill != null ? getState().iconTextFill : "#fff";
        // fonticons have special handling
        com.vaadin.client.ui.Icon vIcon = getIcon();
        String fontAwesomeChar = vIcon.getElement().getInnerText();
        StringBuilder svgSb = new StringBuilder();
        // TODO make this configurable, consider making also possible to
        // use configurable SVG marker without fontawesome icon in marker
        svgSb.append("<svg width=\"25px\" height=\"40px\"><path fill=\"");
        svgSb.append(pathFill);
        svgSb.append("\" stroke=\"");
        svgSb.append(pathStroke);
        svgSb.append("\" d=\"M12.544,0.5C5.971,0.5,0.5,6.24,0.5,12.416c0,2.777,1.564,6.308,2.694,8.745\n" + "L12.5,38.922l9.262-17.761c1.13-2.438,2.738-5.791,2.738-8.745C24.5,6.24,19.117,0.5,12.544,0.5L12.544,0.5z\"/>");
        svgSb.append("<text fill=\"");
        svgSb.append(textFill);
        svgSb.append("\" x=\"12.5\" y=\"20\" text-anchor=\"middle\" font-size=\"16\" class=\"");
        svgSb.append(vIcon.getStyleName());
        svgSb.append("\">");
        svgSb.append(fontAwesomeChar);
        svgSb.append("</text></svg>");
        DivIconOptions divIconOptions = DivIconOptions.create();
        divIconOptions.setClassName("v-leaflet-custom-svg ");
        if (ComponentStateUtil.hasStyles(getState())) {
            divIconOptions.setClassName(divIconOptions.getClassName() + String.join(" ", getState().styles));
        }
        divIconOptions.setHtml(svgSb.toString());
        divIconOptions.setIconSize(Point.create(25, 40));
        divIconOptions.setIconAnchor(Point.create(12.5, 40));
        configureIconSize(divIconOptions);
        DivIcon icon = DivIcon.create(divIconOptions);
        options.setIcon(icon);
    } else if (divIcon != null) {
        DivIconOptions divIconOptions = DivIconOptions.create();
        configureIconSize(divIconOptions);
        if (ComponentStateUtil.hasStyles(getState())) {
            divIconOptions.setClassName(String.join(" ", getState().styles));
        }
        divIconOptions.setHtml(divIcon);
        DivIcon icon = DivIcon.create(divIconOptions);
        options.setIcon(icon);
    } else if (urlReference != null) {
        IconOptions iconOptions = IconOptions.create();
        iconOptions.setIconUrl(urlReference.getURL());
        if (getState().popupAnchor != null) {
            iconOptions.setPopupAnchor(Point.create(getState().popupAnchor.getLat(), getState().popupAnchor.getLon()));
        }
        if (getState().iconAnchor != null) {
            iconOptions.setIconAnchor(Point.create(getState().iconAnchor.getLat(), getState().iconAnchor.getLon()));
        }
        if (getState().iconSize != null) {
            iconOptions.setIconSize(Point.create(getState().iconSize.getLat(), getState().iconSize.getLon()));
        }
        if (ComponentStateUtil.hasStyles(getState())) {
            iconOptions.setClassName(String.join(" ", getState().styles));
        }
        Icon icon = Icon.create(iconOptions);
        options.setIcon(icon);
    }
    String title = getState().title;
    if (title != null) {
        options.setTitle(title);
    }
    if (hasEventListener("dragend")) {
        options.setDraggable(true);
    }
    Integer zIndexOffset = getState().zIndexOffset;
    if (zIndexOffset != null) {
        options.setZIndexOffset(zIndexOffset);
    }
    marker = Marker.create(latlng, options);
    if (hasEventListener("dragend")) {
        marker.addDragEndListener(new ClickListener() {

            @Override
            public void onClick(MouseEvent event) {
                dragServerRcp.dragEnd(U.toPoint(marker.getLatLng()));
            }
        });
    }
    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()));
            }
        });
    }
    String tooltip = getState().tooltip;
    if (tooltip != null) {
        TooltipOptions tooltipOptions = LeafletTooltipConnector.tooltipOptionsFor(getState().tooltipState, this);
        marker.bindTooltip(tooltip, tooltipOptions);
    }
    String popup = getState().popup;
    if (popup != null) {
        PopupOptions popupOptions = LeafletPopupConnector.popupOptionsFor(getState().popupState, this);
        marker.bindPopup(popup, popupOptions);
    }
    addToParent(marker);
    marker.addClickListener(handler);
}
Also used : MarkerOptions(org.peimari.gleaflet.client.MarkerOptions) MouseEvent(org.peimari.gleaflet.client.MouseEvent) URLReference(com.vaadin.shared.communication.URLReference) DivIconOptions(org.peimari.gleaflet.client.DivIconOptions) ContextMenuListener(org.peimari.gleaflet.client.ContextMenuListener) TooltipOptions(org.peimari.gleaflet.client.TooltipOptions) PopupOptions(org.peimari.gleaflet.client.PopupOptions) DivIconOptions(org.peimari.gleaflet.client.DivIconOptions) IconOptions(org.peimari.gleaflet.client.IconOptions) MouseOutListener(org.peimari.gleaflet.client.MouseOutListener) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) MouseOverListener(org.peimari.gleaflet.client.MouseOverListener) LatLng(org.peimari.gleaflet.client.LatLng) DivIcon(org.peimari.gleaflet.client.DivIcon) Icon(org.peimari.gleaflet.client.Icon) DivIcon(org.peimari.gleaflet.client.DivIcon) ClickListener(org.peimari.gleaflet.client.ClickListener)

Aggregations

ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)3 ClickListener (org.peimari.gleaflet.client.ClickListener)3 ContextMenuListener (org.peimari.gleaflet.client.ContextMenuListener)3 LatLng (org.peimari.gleaflet.client.LatLng)3 MouseEvent (org.peimari.gleaflet.client.MouseEvent)3 MouseOutListener (org.peimari.gleaflet.client.MouseOutListener)3 MouseOverListener (org.peimari.gleaflet.client.MouseOverListener)3 URLReference (com.vaadin.shared.communication.URLReference)1 CircleMarkerOptions (org.peimari.gleaflet.client.CircleMarkerOptions)1 CircleOptions (org.peimari.gleaflet.client.CircleOptions)1 DivIcon (org.peimari.gleaflet.client.DivIcon)1 DivIconOptions (org.peimari.gleaflet.client.DivIconOptions)1 Icon (org.peimari.gleaflet.client.Icon)1 IconOptions (org.peimari.gleaflet.client.IconOptions)1 MarkerOptions (org.peimari.gleaflet.client.MarkerOptions)1 PopupOptions (org.peimari.gleaflet.client.PopupOptions)1 TooltipOptions (org.peimari.gleaflet.client.TooltipOptions)1