Hi,
I have a table with legends explaining map (OpenLayers) layers.
I want to turn visibility on/off on the entire row based on the visibility of
these map layers using JS.
I can easily turn on/off the visibility of the legend image itself using
JavaScript/JQuery, but I want to toggle visibility of the entire row. I know
this can be done through ajax, but I don't want to put extra unnecessary load
on the server through Ajax calls.
The easiest way to do this (AFAIK) is adding an id to the table row, and
toggling visibility through JQuery:
$("#tableRowId").show()/hide();
Below is the entire code of my LegendPanel pasted.
Yours,
Tron Walseth
public class LegendPanel<ID extends Serializable> extends MapPanel<ID>
{
private static final long serialVersionUID = 1L;
/**
* @param id
*/
public LegendPanel(String id, List<BusinessLayer> layers,
BusinessDataAjaxMap<ID> map)
{
super(id, map);
ListDataProvider<BusinessLayer> dp = new ListDataProvider<>(layers);
DefaultDataTable<BusinessLayer, String> table = new
DefaultDataTable<>("legends", getTableColumns(), dp, 100000);
add(table);
}
private static List<IColumn<BusinessLayer, String>> getTableColumns()
{
List<IColumn<BusinessLayer, String>> cols = new ArrayList<>();
cols.add(new HeaderlessColumn<BusinessLayer, String>() {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<BusinessLayer>>
cellItem, String componentId, IModel<BusinessLayer> rowModel)
{
cellItem.add(new Label(componentId,
rowModel.getObject().getLegendDescription()));
}});
cols.add(new HeaderlessColumn<BusinessLayer, String>() {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<BusinessLayer>>
cellItem, String componentId, IModel<BusinessLayer> rowModel)
{
Url imgUrl =
Url.parse(rowModel.getObject().getLayerLegend().trim());
ResourceReference ref = new UrlResourceReference(imgUrl);
ImagePanel i = new ImagePanel(componentId, ref);
i.setMarkupId(rowModel.getObject().getLegendDescription());
cellItem.add(i);
}
});
return cols;
}
/* (non-Javadoc)
* @see
org.apache.wicket.Component#renderHead(org.apache.wicket.markup.head.IHeaderResponse)
*/
@Override
public void renderHead(IHeaderResponse response)
{
super.renderHead(response);
response.render(JavaScriptHeaderItem.forScript("function
toggleLegend(event){\n\t" +
"var visible = event.object.visibility;\n" +
"\tvar divObject = '#' +
event.object.params.BUSINESSNAME;\n" +
"\tif (visible) \n" +
"\t\t$(divObject).show();\n" +
"\telse\n" +
"\t\t$(divObject).hide();\n" +
"}", "layerlegend"));
}
/* (non-Javadoc)
* @see
no.telespor.web.page.map.openlayers.MapPanel#updateComponents(org.apache.wicket.ajax.AjaxRequestTarget)
*/
@Override
public void updateComponents(AjaxRequestTarget target)
{
//empty on purpose
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]