/**
* Builds a select that reacts like a menu, fully javascript based, for wms outputs
*/
private Component buildJSWMSSelect(String id,
List<String> wmsOutputFormats, List<String> wfsOutputFormats, PreviewLayer layer) {
Fragment f = new Fragment(id, "menuFragment", MapPreviewPage.this);
WebMarkupContainer menu = new WebMarkupContainer("menu");
RepeatingView wmsFormats = new RepeatingView("wmsFormats");
for (int i = 0; i < wmsOutputFormats.size(); i++) {
String wmsOutputFormat = wmsOutputFormats.get(i);
String label = translateFormat("format.wms.", wmsOutputFormat);
// build option with text and value
Label format = new Label(i + "", label);
format.add(new AttributeModifier("value", true, new Model(wmsOutputFormat)));
wmsFormats.add(format);
}
menu.add(wmsFormats);
// the vector ones, it depends, we might have to hide them
boolean vector = layer.groupInfo == null && layer.layerInfo.getType() != LayerInfo.Type.RASTER;
WebMarkupContainer wfsFormatsGroup = new WebMarkupContainer("wfs");
RepeatingView wfsFormats = new RepeatingView("wfsFormats");
if(vector) {
for (int i = 0; i < wfsOutputFormats.size(); i++) {
String wfsOutputFormat = wfsOutputFormats.get(i);
String label = translateFormat("format.wfs.", wfsOutputFormat);
// build option with text and value
Label format = new Label(i + "", label);
format.add(new AttributeModifier("value", true, new Model(wfsOutputFormat)));
wfsFormats.add(format);
}
}
wfsFormatsGroup.add(wfsFormats);
menu.add(wfsFormatsGroup);
// build the wms request, redirect to it in a new window, reset the selection
String wmsUrl = "'" + layer.getWmsLink()
+ "&format=' + this.options[this.selectedIndex].value";
String wfsUrl = "'../ows?service=WFS&version=1.0.0&request=GetFeature&typeName="
+ layer.getName()
+ "&maxFeatures=50"
+ "&outputFormat=' + this.options[this.selectedIndex].value";
String choice = "(this.options[this.selectedIndex].parentNode.label == 'WMS') ? " + wmsUrl + " : " + wfsUrl;
menu.add(new AttributeAppender("onchange", new Model("window.open("
+ choice + ");this.selectedIndex=0"), ";"));
f.add(menu);
return f;
}