⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getmapresponse.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						definitionQuery = new DefaultQuery(source.getSchema()
								.getTypeName(), optionalFilter);
						definitionQuery.setVersion(featureVersion);

						layer.setQuery(definitionQuery);
					} else if (featureVersion != null) {
						definitionQuery = new DefaultQuery(source.getSchema()
								.getTypeName());
						definitionQuery.setVersion(featureVersion);

						layer.setQuery(definitionQuery);
					}

					map.addLayer(layer);
				} else if (layers[i].getType() == MapLayerInfo.TYPE_RASTER) {
					// /////////////////////////////////////////////////////////
					//
					// Adding a coverage layer
					//
					// /////////////////////////////////////////////////////////
					AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) layers[i]
							.getCoverage().getReader();
					if (reader != null) {
						// /////////////////////////////////////////////////////////
						//
						// Setting coverage reading params.
						//
						// /////////////////////////////////////////////////////////

                       /*
                         * Test if the parameter "TIME" is present in the WMS
                         * request, and by the way in the reading parameters. If
                         * it is the case, one can adds it to the request. If an
                         * exception is thrown, we have nothing to do.
                         */
                        try {
                            ParameterValue time = reader.getFormat().getReadParameters().parameter(
                                    "TIME");
                            if (time != null && request.getTime() != null) {
                                time.setValue(request.getTime());
                            }
                        } catch (ParameterNotFoundException p) {
                        }

//                      uncomment when the DIM_RANGE vendor parameter will be enabled                        
//                        try {
//                            ParameterValue dimRange = reader.getFormat().getReadParameters()
//                                    .parameter("DIM_RANGE");
//                            if (dimRange != null && request.getDimRange() != null) {
//                                dimRange.setValue(request.getDimRange());
//                            }
//                        } catch (ParameterNotFoundException p) {
//                        }

                        try {
                            ParameterValue elevation = reader.getFormat().getReadParameters()
                                    .parameter("ELEVATION");
                            if (elevation != null && request.getElevation() != null) {
                                elevation.setValue(request.getElevation().intValue());
                            }
                        } catch (ParameterNotFoundException p) {
                        }

						try {
							final ParameterValueGroup params = reader.getFormat().getReadParameters();

							layer = new DefaultMapLayer(FeatureUtilities
									.wrapGridCoverageReader(reader, CoverageUtils
											.getParameters(params, layers[i]
													.getCoverage()
													.getParameters())), style);
							
							layer.setTitle(layers[i].getName());
							layer.setQuery(Query.ALL);
							map.addLayer(layer);
						} catch (IllegalArgumentException e) {
							if (LOGGER.isLoggable(Level.SEVERE)) {
								LOGGER.log(Level.SEVERE, new StringBuffer(
										"Wrapping GC in feature source: ")
										.append(e.getLocalizedMessage())
										.toString(), e);
							}

							throw new WmsException(
									null,
									new StringBuffer(
											"Internal error : unable to get reader for this coverage layer ")
											.append(layers[i].toString())
											.toString());
						}
					} else {
						throw new WmsException(
								null,
								new StringBuffer(
										"Internal error : unable to get reader for this coverage layer ")
										.append(layers[i].toString())
										.toString());
					}
				}
			}

			// /////////////////////////////////////////////////////////
			//
			// Producing the map in the requested format.
			//
			// /////////////////////////////////////////////////////////
			this.delegate.produceMap();

			if (cachingPossible) {
				responseHeaders.put("Cache-Control", "max-age=" + maxAge
						+ ", must-revalidate");
			}

			final String contentDisposition = this.delegate
					.getContentDisposition();
			if (contentDisposition != null) {
				this.headerContentDisposition = contentDisposition;
			}
		} catch (ClassCastException e) {
			if (LOGGER.isLoggable(Level.WARNING)) {
				LOGGER.log(Level.SEVERE, new StringBuffer(
						"Getting feature source: ").append(e.getMessage())
						.toString(), e);
			}

			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (TransformException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (FactoryConfigurationError e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (SchemaException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} catch (IllegalAttributeException e) {
			throw new WmsException(e, new StringBuffer("Internal error : ")
					.append(e.getMessage()).toString(), "");
		} finally {
			// clean
			try {
				// map.clearLayerList();
			} catch (Exception e) // we dont want to propogate a new error
			{
				if (LOGGER.isLoggable(Level.SEVERE)) {
					LOGGER.log(Level.SEVERE, new StringBuffer(
							"Getting feature source: ").append(e.getMessage())
							.toString(), e);
				}
			}
		}
	}

	/**
	 * asks the internal GetMapDelegate for the MIME type of the map that it
	 * will generate or is ready to, and returns it
	 * 
	 * @param gs
	 *            DOCUMENT ME!
	 * 
	 * @return the MIME type of the map generated or ready to generate
	 * 
	 * @throws IllegalStateException
	 *             if a GetMapDelegate is not setted yet
	 */
	public String getContentType(GeoServer gs) throws IllegalStateException {
		if (this.delegate == null) {
			throw new IllegalStateException("No request has been processed");
		}

		return this.delegate.getContentType();
	}

	/**
	 * DOCUMENT ME!
	 * 
	 * @return DOCUMENT ME!
	 */
	public String getContentEncoding() {
		if (LOGGER.isLoggable(Level.FINER)) {
			LOGGER.finer("returning content encoding null");
		}

		return null;
	}

	/**
	 * if a GetMapDelegate is set, calls it's abort method. Elsewere do nothing.
	 * 
	 * @param gs
	 *            DOCUMENT ME!
	 */
	public void abort(Service gs) {
		if (this.delegate != null) {
			if (LOGGER.isLoggable(Level.FINE)) {
				LOGGER.fine("asking delegate for aborting the process");
			}

			this.delegate.abort();
		}
	}

	/**
	 * delegates the writing and encoding of the results of the request to the
	 * <code>GetMapDelegate</code> wich is actually processing it, and has
	 * been obtained when <code>execute(Request)</code> was called
	 * 
	 * @param out
	 *            the output to where the map must be written
	 * 
	 * @throws ServiceException
	 *             if the delegate throws a ServiceException inside its
	 *             <code>writeTo(OuptutStream)</code>, mostly due to
	 * @throws IOException
	 *             if the delegate throws an IOException inside its
	 *             <code>writeTo(OuptutStream)</code>, mostly due to
	 * @throws IllegalStateException
	 *             if this method is called before <code>execute(Request)</code>
	 *             has succeed
	 */
	public void writeTo(OutputStream out) throws ServiceException, IOException {
		try { // mapcontext can leak memory -- we make sure we done (see
			// finally block)

			if (this.delegate == null) {
				throw new IllegalStateException(
						"No GetMapDelegate is setted, make sure you have called execute and it has succeed");
			}

			if (LOGGER.isLoggable(Level.FINER)) {
				LOGGER.finer(new StringBuffer("asking delegate for write to ")
						.append(out).toString());
			}

			this.delegate.writeTo(out);
		} finally {
			try {
				map.clearLayerList();
			} catch (Exception e) // we dont want to propogate a new error
			{
				if (LOGGER.isLoggable(Level.SEVERE)) {
					LOGGER.log(Level.SEVERE, new StringBuffer(
							"Getting feature source: ").append(e.getMessage())
							.toString(), e);
				}
			}
		}
	}

	/**
	 * Creates a GetMapDelegate specialized in generating the requested map
	 * format
	 * 
	 * @param outputFormat
	 *            a request parameter object wich holds the processed request
	 *            objects, such as layers, bbox, outpu format, etc.
	 * 
	 * @return A specialization of <code>GetMapDelegate</code> wich can
	 *         produce the requested output map format
	 * 
	 * @throws WmsException
	 *             if no specialization is configured for the output format
	 *             specified in <code>request</code> or if it can't be
	 *             instantiated
	 */
	private GetMapProducer getDelegate(String outputFormat, WMS wms)
			throws WmsException {
		final Collection producers = GeoServerExtensions.extensions(GetMapProducerFactorySpi.class);	

		for (Iterator iter = producers.iterator(); iter.hasNext();) {
			final GetMapProducerFactorySpi factory = (GetMapProducerFactorySpi) iter.next();

			if (factory.canProduce(outputFormat)) {
				return factory.createMapProducer(outputFormat, wms);
			}
		}

		WmsException e = new WmsException(
				"There is no support for creating maps in " + outputFormat
						+ " format");
		e.setCode("InvalidFormat");
		throw e;
	}

	/**
	 * Convenient mehtod to inspect the available
	 * <code>GetMapProducerFactorySpi</code> and return the set of all the map
	 * formats' MIME types that the producers can handle
	 * 
	 * @return a Set&lt;String&gt; with the supported mime types.
	 */
	public Set getMapFormats() {
		Set wmsGetMapFormats = loadImageFormats(applicationContext);

		return wmsGetMapFormats;
	}

	/**
	 * Convenience method for processing the GetMapProducerFactorySpi extension
	 * point and returning the set of available image formats.
	 * 
	 * @param applicationContext
	 *            The application context.
	 * 
	 */
	public static Set loadImageFormats(ApplicationContext applicationContext) {
		final Collection producers = GeoServerExtensions.extensions(GetMapProducerFactorySpi.class);
		final Set formats = new HashSet();

		for (Iterator iter = producers.iterator(); iter.hasNext();) {
			final GetMapProducerFactorySpi producer = (GetMapProducerFactorySpi) iter
					.next();
			formats.addAll(producer.getSupportedFormats());
		}

		return Collections.unmodifiableSet(formats);
	}

	public String getContentDisposition() {
		return headerContentDisposition;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -