@Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); getWidget().disableOnClick = getState().disableOnClick; focusHandlerRegistration = EventHelper.updateFocusHandler(this, focusHandlerRegistration); blurHandlerRegistration = EventHelper.updateBlurHandler(this, blurHandlerRegistration); // Set text VCaption.setCaptionText(getWidget(), getState()); // handle error if (null != getState().errorMessage) { if (getWidget().errorIndicatorElement == null) { getWidget().errorIndicatorElement = DOM.createSpan(); getWidget().errorIndicatorElement.setClassName("v-errorindicator"); } getWidget() .getElement() .insertBefore(getWidget().errorIndicatorElement, getWidget().captionElement); } else if (getWidget().errorIndicatorElement != null) { getWidget().getElement().removeChild(getWidget().errorIndicatorElement); getWidget().errorIndicatorElement = null; } if (getWidget().icon != null) { getWidget().getElement().removeChild(getWidget().icon.getElement()); getWidget().icon = null; } Icon icon = getIcon(); if (icon != null) { getWidget().icon = icon; getWidget().getElement().insertBefore(icon.getElement(), getWidget().captionElement); icon.setAlternateText(getState().iconAltText); } }
@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://")) { // 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=\"#44AEEA\" stroke=\"#005FA8\" 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\"/><text fill=\"#fff\" 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"); 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())) { StringBuilder builder = new StringBuilder(); for (String style : getState().styles) { builder.append(style).append(" "); } divIconOptions.setClassName(builder.toString()); } 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().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())); } Icon icon = Icon.create(iconOptions); options.setIcon(icon); } String title = getState().title; if (title != null) { options.setTitle(title); } if (hasEventListener("dragend")) { options.setDraggable(true); } 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 popup = getState().popup; if (popup != null) { PopupOptions popupOptions = LeafletPopupConnector.popupOptionsFor(getState().popupState); marker.bindPopup(popup, popupOptions); } addToParent(marker); marker.addClickListener(handler); }