当地图第一次初始化时,一切都会顺利进行。我已经实现了更改要显示的图层的选项。这是通过初始化时创建的每个图层来完成的,但是只有默认映射具有visible: true
,其余的具有visible: false
。另外,我遵循了有关如何设置PopoverPanel单击处理程序here的示例代码。单击功能时,将触发此单击处理程序,执行以下代码后将显示一个弹出面板:
public void handleClick(AjaxRequestTarget target, String featureId, LongLat longLat, JsonObject properties)
{
JsonArray coordinates = properties.get("geometry").getAsJsonArray();
String name =properties.get("name").getAsString();
Double longitude = coordinates.get(0).getAsDouble();
Double latitude = coordinates.get(1).getAsDouble();
LongLat newCoordinates = new LongLat(longitude, latitude, "EPSG:32633");
StringBuffer description = new StringBuffer();
description = fillPopup(individual);
Page.this.popoverPanel.getTitleModel().setObject(name);
Page.this.popoverPanel.getContentModel().setObject(description.toString());
Page.this.popoverPanel.setPosition(coordinate);
Page.this.popoverPanel.show(target);
}
在我更改显示的图层之前,此方法工作正常。这是我如何更改图层的代码。它将整个地图发送回客户端:
/* Inside radioChoice AjaxFormChoiceComponentUpdatingBehavior */
protected void onUpdate(AjaxRequestTarget target)
{
changeBaseLayerJS(Page.this.currentMap, Page.this.selectedRadio);
Page.this.currentMap = Page.this.selectedRadio;
target.add(Page.this.map);
}
void changeBaseLayerJS(String currentLayer, String newMap)
{
List<Layer> mapLayers = this.map.getModel().getObject().getLayers();
for (Layer layer : mapLayers)
{
if(layer instanceof Vector)
{
continue;
}
Tile tile = (Tile)layer;
if (tile.getTitle().equals(newMap))
{
tile.setIsVisible(true);
}
else if (tile.getTitle().equals(currentLayer))
{
tile.setIsVisible(false);
}
}
}