Open PopupWindow programmatically

Hi,
is there a way to open programmatically a PopupWindow relative to a GeoObject on a map, without having user to click on the element?
I’ve found the method openPopup(PopupWindow) only for the GeoMap interface.
For example, I’d like to open a PopupWindow over a CanvasLayer.Point when a user selects an Entity in a DataGrid or in a Table.
Thanks,
Paolo

Hi, Paolo!

The current version of the add-on does not provide a way to open a PopupWindow programmatically for a geo-object.
We are planning to release the new version soon (in the coming weeks), so we will consider adding this option in the release.

We will inform you as soon as the new version is published.

Regards,
Gleb

Thanks Gleb!
I therefore await the upcoming release of the new add-on version.
Regards,
Paolo

Hello Gleb,
I’ve updated maps addon to the new version (1.2.0): now I can open a PopupWindow on geo-object programmatically.
Thank you very much.

Regards,
Paolo

Hi Gleb,
I’m trying to do the same in a VectorLayer: when a user clicks or selects an Entity in a grid, the app centers the map on the Entity and open a PopupWindow over it.
I’m able to center the map, but I can’t open the PopupWindow over the marker to emphasize user choice (while I’m able to do this in a CanvasLayer as I’ve a reference to the Point).

@Subscribe("dataGrid")
public void onDataGridSelection(DataGrid.SelectionEvent<MyEntity> event) {
    MyEntity entitySelected = null;
    for (MyEntity sel : event.getSelected()) {
        entitySelected = sel;
    }
    if (entitySelected!=null && entitySelected.getLocation()!=null) {
        vectorLayer.setSelectedGeoObject(entitySelected);
        map.setCenter(entitySelected.getLocation().getX(),entitySelected.getLocation().getY());
    }
}

How should I do this?

Thank you.
Regards,
Paolo

Hi Paolo!

You need to obtain the references to the underlying Vaadin components corresponding to your vector layer’s geo-objects. This functionality was added in the release 1.2.0 and we haven’t published updated docs for this release yet.
I have complemented your code with the needed logic:

import com.haulmont.addon.maps.web.gui.components.leaflet.translators.GeoObjectWrapper;

...

@Subscribe("dataGrid")
public void onDataGridSelection(DataGrid.SelectionEvent<MyEntity> event) {
    MyEntity entitySelected = null;
    for (MyEntity sel : event.getSelected()) {
        entitySelected = sel;
    }
    if (entitySelected!=null && entitySelected.getLocation()!=null) {
        vectorLayer.setSelectedGeoObject(entitySelected);
        map.setCenter(entitySelected.getLocation().getX(),entitySelected.getLocation().getY());
        //open pop-up over the geo-object
        VectorLayer<MyEntity> myVectorLayer = map.getLayer("myVectorLayer"); // vector layer with id = "myVectorLayer"
        Map<?, GeoObjectWrapper<MyEntity>> geoObjectWrappersMap =
                ((WebGeoMap) map).getGeoObjectWrappersMap(myVectorLayer);
        GeoObjectWrapper<MyEntity> geoObjectWrapper = geoObjectWrappersMap.get(entitySelected.getId());
        if (geoObjectWrapper != null) {
            geoObjectWrapper.openPopup();
        }
    }
}

Regards,
Gleb

Great!
Thank you very much Gleb!
Regards,
Paolo

We have updated the add-on’s documentation. This section describes how to work with the geo-objects on a map directly (for example, open pop-ups programmatically).

1 Like