Search in sources :

Example 1 with URLReference

use of com.vaadin.shared.communication.URLReference in project v-leaflet by mstahv.

the class LeafletImageOverlayConnector method update.

@Override
protected void update() {
    if (imageOverlay != null) {
        removeLayerFromParent();
    }
    LatLngBounds bounds = LatLngBounds.create(LatLng.create(getState().bounds.getSouthWestLat(), getState().bounds.getSouthWestLon()), LatLng.create(getState().bounds.getNorthEastLat(), getState().bounds.getNorthEastLon()));
    URLReference urlReference = getState().resources.get("url");
    ImageOverlayOptions options = createOptions();
    if (getState().attribution != null) {
        options.setAttribution(getState().attribution);
    }
    if (getState().opacity != null) {
        options.setOpacity(getState().opacity);
    }
    String url = getConnection().translateVaadinUri(urlReference.getURL());
    imageOverlay = ImageOverlay.create(url, bounds, options);
    addToParent(imageOverlay);
}
Also used : URLReference(com.vaadin.shared.communication.URLReference) ImageOverlayOptions(org.peimari.gleaflet.client.ImageOverlayOptions) LatLngBounds(org.peimari.gleaflet.client.LatLngBounds)

Example 2 with URLReference

use of com.vaadin.shared.communication.URLReference in project cuba by cuba-platform.

the class CubaOrderedActionsLayoutConnector method updateCaptionInternal.

@Override
protected void updateCaptionInternal(ComponentConnector child) {
    // CAUTION copied from superclass
    CubaOrderedLayoutSlot slot = (CubaOrderedLayoutSlot) getWidget().getSlot(child.getWidget());
    String caption = child.getState().caption;
    URLReference iconUrl = child.getState().resources.get(ComponentConstants.ICON_RESOURCE);
    String iconUrlString = iconUrl != null ? iconUrl.getURL() : null;
    Icon icon = child.getConnection().getIcon(iconUrlString);
    List<String> styles = child.getState().styles;
    String error = child.getState().errorMessage;
    boolean showError = error != null;
    if (child.getState() instanceof AbstractFieldState) {
        AbstractFieldState abstractFieldState = (AbstractFieldState) child.getState();
        showError = showError && !abstractFieldState.hideErrors;
    }
    boolean required = false;
    if (child instanceof AbstractFieldConnector) {
        required = ((AbstractFieldConnector) child).isRequired();
    }
    boolean enabled = child.isEnabled();
    if (slot.hasCaption() && null == caption) {
        slot.setCaptionResizeListener(null);
    }
    // Haulmont API
    boolean contextHelpIconEnabled = isContextHelpIconEnabled(child.getState());
    // Haulmont API
    slot.setCaption(caption, contextHelpIconEnabled, icon, styles, error, showError, required, enabled, child.getState().captionAsHtml);
    AriaHelper.handleInputRequired(child.getWidget(), required);
    AriaHelper.handleInputInvalid(child.getWidget(), showError);
    AriaHelper.bindCaption(child.getWidget(), slot.getCaptionElement());
    if (slot.hasCaption()) {
        CaptionPosition pos = slot.getCaptionPosition();
        slot.setCaptionResizeListener(slotCaptionResizeListener);
        if (child.isRelativeHeight() && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        } else if (child.isRelativeWidth() && (pos == CaptionPosition.LEFT || pos == CaptionPosition.RIGHT)) {
            getWidget().updateCaptionOffset(slot.getCaptionElement());
        }
    }
}
Also used : URLReference(com.vaadin.shared.communication.URLReference) AbstractFieldState(com.vaadin.shared.AbstractFieldState) AbstractFieldConnector(com.vaadin.client.ui.AbstractFieldConnector) Icon(com.vaadin.client.ui.Icon) CaptionPosition(com.vaadin.client.ui.orderedlayout.CaptionPosition)

Example 3 with URLReference

use of com.vaadin.shared.communication.URLReference 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

URLReference (com.vaadin.shared.communication.URLReference)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 AbstractFieldConnector (com.vaadin.client.ui.AbstractFieldConnector)1 Icon (com.vaadin.client.ui.Icon)1 CaptionPosition (com.vaadin.client.ui.orderedlayout.CaptionPosition)1 AbstractFieldState (com.vaadin.shared.AbstractFieldState)1 ClickListener (org.peimari.gleaflet.client.ClickListener)1 ContextMenuListener (org.peimari.gleaflet.client.ContextMenuListener)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 ImageOverlayOptions (org.peimari.gleaflet.client.ImageOverlayOptions)1 LatLng (org.peimari.gleaflet.client.LatLng)1 LatLngBounds (org.peimari.gleaflet.client.LatLngBounds)1 MarkerOptions (org.peimari.gleaflet.client.MarkerOptions)1 MouseEvent (org.peimari.gleaflet.client.MouseEvent)1 MouseOutListener (org.peimari.gleaflet.client.MouseOutListener)1 MouseOverListener (org.peimari.gleaflet.client.MouseOverListener)1 PopupOptions (org.peimari.gleaflet.client.PopupOptions)1