All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wicketstuff.openlayers3.component.MarkerPopover Maven / Gradle / Ivy

The newest version!
package org.wicketstuff.openlayers3.component;

import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.wicketstuff.openlayers3.api.coordinate.LongLat;
import org.wicketstuff.openlayers3.api.overlay.Overlay;
import org.wicketstuff.openlayers3.api.util.Color;

/**
 * Provides a marker linked to a popover. When the marker is clicked, the popover will have it's content updated and
 * then be displayed.
 */
public class MarkerPopover extends Marker {

    /**
     * Default placement for the popover.
     */
    public final static String DEFAULT_PLACEMENT = "right";

    /**
     * Default positioning of the marker.
     */
    public final static Overlay.Positioning DEFAULT_POSITIONING = Overlay.Positioning.TopCenter;

    /**
     * Popover to use for this marker.
     */
    private PopoverPanel popoverPanel;

    /**
     * Title for the marker's popover.
     */
    private IModel titleModel;

    /**
     * Content for the marker's popover.
     */
    private IModel contentModel;

    /**
     * Location of the popover on the map.
     */
    private IModel positionModel;

    /**
     * Placement of the popover relative to the marker.
     */
    private IModel placementModel;

    /**
     * Creates a new marker that is linked to the provided popover panel.
     *
     * @param id
     *         Wicket element ID
     * @param colorModel
     *         Color model for the marker
     * @param popoverPanel
     *         Popover panel for display detail when marker is clicked
     * @param titleModel
     *         Title model for the popover panel
     * @param contentModel
     *         Content model for the popover panel
     * @param positionModel
     *         Location of the marker on the map
     */
    public MarkerPopover(final String id, IModel colorModel, final PopoverPanel popoverPanel,
			 final IModel titleModel, final IModel contentModel,
			 final IModel positionModel) {
        this(id, colorModel, popoverPanel, titleModel, contentModel, positionModel, Model.of(DEFAULT_PLACEMENT));
    }

    /**
     * Creates a new marker that is linked to the provided popover panel.
     *
     * @param id
     *         Wicket element ID
     * @param colorModel
     *         Color model for the marker
     * @param popoverPanel
     *         Popover panel for display detail when marker is clicked
     * @param titleModel
     *         Title model for the popover panel
     * @param contentModel
     *         Content model for the popover panel
     * @param positionModel
     *         Location of the marker on the map
     * @param placementModel
     *         Position of the popover relative to the marker
     */
    public MarkerPopover(final String id, IModel colorModel, final PopoverPanel popoverPanel,
			 final IModel titleModel,  final IModel contentModel,
			 final IModel positionModel, final IModel placementModel) {
        super(id, colorModel);
        this.popoverPanel = popoverPanel;
        this.titleModel = titleModel;
        this.contentModel = contentModel;
        this.positionModel = positionModel;
        this.placementModel = placementModel;
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();

        add(new AjaxEventBehavior("click") {
            @Override
            protected void onEvent(AjaxRequestTarget target) {
                popoverPanel.getContentModel().setObject(getContentModel().getObject());
                popoverPanel.getTitleModel().setObject(getTitleModel().getObject());
                popoverPanel.setPosition(positionModel.getObject());
                popoverPanel.setPlacement(getPlacementModel().getObject());
                popoverPanel.setPositioning(DEFAULT_POSITIONING);
                popoverPanel.show(target);
            }
        });
    }

    /**
     * Returns the popover panel for this marker.
     *
     * @return Popover panel instance
     */
    public PopoverPanel getPopoverPanel() {
        return popoverPanel;
    }

    /**
     * Returns the title model used to populate the popover panel.
     *
     * @return Model with title
     */
    public IModel getTitleModel() {
        return titleModel;
    }

    /**
     * Returns the content model used to populate the popover panel.
     *
     * @return Model with content
     */
    public IModel getContentModel() {
        return contentModel;
    }

    /**
     * Returns the model used to position the marker.
     *
     * @return Model with position for the marker
     */
    public IModel getPositionModel() {
        return positionModel;
    }

    /**
     * Returns the model used to position the popover panel relative to the marker.
     *
     * @return Model with the placement of the popover panel relative to the marker
     */
    public IModel getPlacementModel() {
        return placementModel;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy