private static boolean matchEPSG(List<Layer> layers, String epsgCode) { boolean match = true; for (Layer layer : layers) { Set<String> srs = layer.getSrs(); if (!srs.contains(epsgCode)) { match = false; break; } } return match; }
/** * We have made this visible so that WMSDescribeLayer (used by InfoView2) can figure out how to * make the *exact* same request in order to a getInfo operation. We should really store the last * request on the layer blackboard for this intra module communication. * * @return SRS code */ public static String findRequestCRS( List<Layer> layers, CoordinateReferenceSystem viewportCRS, IMap map) { String requestCRS = null; if (layers == null || layers.isEmpty()) { return null; } Collection<String> viewportEPSG = extractEPSG(map, viewportCRS); if (viewportEPSG != null) { String match = matchEPSG(layers, viewportEPSG); if (match != null) return match; } if (matchEPSG(layers, EPSG_4326)) return EPSG_4326; if (matchEPSG(layers, EPSG_4269)) { return EPSG_4269; } Layer firstLayer = layers.get(0); for (Object object : firstLayer.getSrs()) { String epsgCode = (String) object; try { // Check to see if *we* can actually use this code first. CRS.decode(epsgCode); } catch (NoSuchAuthorityCodeException e) { continue; } catch (FactoryException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (matchEPSG(layers, epsgCode)) { requestCRS = epsgCode; return requestCRS; } } if (requestCRS == null) { // Hmm. Our layers have no SRS in common - we are in an illegal state WMSPlugin.log( "ERROR: Illegal State: Basic WMS Renderer contains layers with no common CRS. Unable to perform request."); //$NON-NLS-1$ return null; } return requestCRS; }
private static void writeLayer(ILayer layer, BufferedWriter out) throws IOException { Layer wmsLayer = layer.getResource(Layer.class, null); WebMapServer wms = layer.getResource(WebMapServer.class, null); WMSCapabilities caps = wms.getCapabilities(); String version = caps.getVersion(); String title = wms.getCapabilities().getService().getTitle(); int hidden = layer.isVisible() ? 1 : 0; int info = layer.isApplicable("info") ? 1 : 0; // $NON-NLS-1$ String get = caps.getRequest().getGetCapabilities().getGet().toExternalForm(); System.out.println(get); if (get.endsWith("&")) get = get.substring(0, get.length() - 1); // $NON-NLS-1$ append( 4, out, "<Layer hidden=\"" + hidden + "\" queryable=\"" + info + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ append( 6, out, "<Server service=\"OGC:WMS\" title=\"" + title + "\" version=\"" + version + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ append( 8, out, "<OnlineResource method=\"GET\" xlink:href=\"" + get + "\" xlink:type=\"simple\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ append(6, out, "</Server>"); // $NON-NLS-1$ append(6, out, "<Name>" + wmsLayer.getName() + "</Name>"); // $NON-NLS-1$ //$NON-NLS-2$ append(6, out, "<Title>" + wmsLayer.getTitle() + "</Title>"); // $NON-NLS-1$ //$NON-NLS-2$ if (!Double.isNaN(wmsLayer.getScaleHintMin())) append( 6, out, "<sld:MinScaleDenominator>" + wmsLayer.getScaleHintMin() + "</sld:MinScaleDenominator>"); //$NON-NLS-1$ //$NON-NLS-2$ if (!Double.isNaN(wmsLayer.getScaleHintMax())) append( 6, out, "<sld:MaxScaleDenominator>" + wmsLayer.getScaleHintMax() + "</sld:MaxScaleDenominator>"); //$NON-NLS-1$ //$NON-NLS-2$ for (String srs : (Set<String>) wmsLayer.getSrs()) { append(6, out, "<SRS>" + srs + "</SRS>"); // $NON-NLS-1$ //$NON-NLS-2$ } append(6, out, "<FormatList>"); // $NON-NLS-1$ boolean first = true; // TODO: look up preferences? for (String format : caps.getRequest().getGetMap().getFormats()) { if (first) { append( 8, out, "<Format current=\"1\">" + format + "</Format>"); // $NON-NLS-1$ //$NON-NLS-2$ first = false; } append(8, out, "<Format>" + format + "</Format>"); // $NON-NLS-1$ //$NON-NLS-2$ } append(6, out, "</FormatList>"); // $NON-NLS-1$ first = true; // TODO: look up on styleblackboard? append(6, out, "<StyleList>"); // $NON-NLS-1$ Object styles = wmsLayer.getStyles(); List list; if (styles instanceof String) list = Collections.singletonList(styles); else if (styles instanceof List) list = (List) styles; else list = Collections.emptyList(); for (Iterator<Object> iter = list.iterator(); iter.hasNext(); ) { Object next = iter.next(); if (next instanceof String) { String style = (String) next; first = writeStyle(style, style, first, out); } else if (next instanceof StyleImpl) { StyleImpl style = (StyleImpl) next; writeStyle(style.getName(), style.getTitle().toString(), first, out); } } append(6, out, "</StyleList>"); // $NON-NLS-1$ append(4, out, "</Layer>"); // $NON-NLS-1$ }