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

📄 mapmerger.java

📁 联合国农粮署牵头开发的geonetwork源代码最新版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//		}////		MapService service;//		Vector imageNames = new Vector();//		String serverURL = null;////		int i = 0;//		boolean flag = false;//		while (!flag)//		{////			prevService = (MapService)htServices.get(vRank.get(i));//			Layer layer = _layers.get(vRank.get(i));//			prevService = layer.getService();////			if (  htShow.get(vRank.get(i)).equals(new Boolean(true)) ) {//			if (  layer.isVisible() ) {//				imageNames.add(prevService.getName());//				flag = true;//			}//			i++;//		}////		while (i < vRank.size())//		{//			System.out.println(i + " - imageNames = " + imageNames);//////			// get the map service////			service = (MapService)htServices.get(vRank.get(i));//			Layer layer = _layers.get(vRank.get(i));//			service = layer.getService();////			//System.out.println("i = " + i + " - vRank.size() = " + vRank.size());//			serverURL = service.getServerURL();//////			if (htShow.get(vRank.get(i)).equals(new Boolean(true)))//			if ( layer.isVisible() )//			{//				if (serverURL.equals(prevService.getServerURL()))//				{//					//System.out.println(ms.getName());//					vImageUrls.add(null);//				}//				else//				{//					vImageUrls.add(prevService.getGroupImageUrl(bBox, width, height, imageNames));//					imageNames.clear();//				}//			}//			else//				vImageUrls.add(null);////			imageNames.add(service.getName());//////			if ((i == vRank.size() - 1) && (prevService.getServerURL().equals(serverURL)))//				vImageUrls.add(service.getGroupImageUrl(bBox, width, height, imageNames));////			prevService = service;////			i++;//		}////		System.out.println("- imageNames = " + imageNames);//		System.out.println("- vImageUrls = " + vImageUrls);////		i++;	}	private List<String> sendGetImageRequests(int width, int height)	{		List<String> vImageUrls = new ArrayList<String>();//		vImageUrls.clear();		//buildWmsRequests(width, height); // TODO: fix that function and uncomment these two lines		//if (false)		{			// Retrieve WMS services urls			if (reaspectWms)				bBox = reaspect(bBox, width, height); // Reaspect the bounding box if no ArcIMS service did it			for (int id: vRank) // takes ids sorted by their ranks			{				Layer layer = _layers.get(id);				MapService ms = layer.getService();				if (layer.isVisible())				{					try { vImageUrls.add(ms.getImageUrl(bBox, width, height)); }					catch (Exception e) { e.printStackTrace(); /* DEBUG */ }				}				else vImageUrls.add(null);			}		}		// Set the scale		degScale = Math.abs(getBoundingBox().getEast() - getBoundingBox().getWest()) / width;		distScale = (long)(423307109.727 * degScale / 96.0 * getDPI());		return vImageUrls;	}	/**	 * <UL>	 *    <LI>Fetch images from remote servers</LI>	 *    <LI>Merge them together</LI>	 *    <LI>Create a temp file containing the merged image</LI>	 * </UL>	 *	 * @return the image file name, or an empty string when	 */	public String merge(int width, int height)		throws Exception	{		// Clear the error list		htErrors.clear();		List<String> vImageUrls = sendGetImageRequests(width, height);//		/*DEBUG*/System.err.println("MERGE");//		/*DEBUG*/System.err.println("  requrls:");//		/*DEBUG*/for(String url : vImageUrls)//		/*DEBUG*/	System.err.println("      " + url);		List<String> files = new Vector<String>();		ConcurrentHTTPTransactionHandler c = new ConcurrentHTTPTransactionHandler();// DEBUG		c.setCache(cache); // DEBUG		c.checkIfModified(false); //DEBUG		for (String url: vImageUrls)		{			if (url != null) { // null if some error encountered (never with WMS servers)				c.register(url);			}			else // Only for ArcIMS services			{// Tell the user			}		}		c.doTransactions();//		System.out.println("vImageUrls.size() = " + vImageUrls.size()); // DEBUG		List<Float> vTransparency = new ArrayList<Float>(); // Image transparency		for (int i = 0; i < vImageUrls.size(); i++)		{			if (vImageUrls.get(i) != null)			{				String path = c.getResponseFilePath(vImageUrls.get(i));	//			System.out.println("vImageUrls.get(i) = " + (String)vImageUrls.get(i));	//			System.out.println("path = " + path);				if (path != null)				{					String contentType = c.getHeaderValue(vImageUrls.get(i), "content-type");	//				System.out.println("contentType = " + contentType); // DEBUG					if (contentType.startsWith("image"))					{						files.add(path);						vTransparency.add(_layers.get(vRank.get(i)).getTransparency());						//System.out.println("file: " + path + "; transparency: " + htTransparency.get(vRank.get(i))); // DEBUG					}				}			}		}//		System.out.println("files.size() = " + files.size()); // DEBUG//		imageName="";		if (files.size() > 1) {			// Merge the images			File output = GlobalTempFiles.getInstance().getFile();			String path = output.getPath();//			System.out.println("vTransparency" + vTransparency); // DEBUG			Collections.reverse(files);			Collections.reverse(vTransparency);			ImageMerger.mergeAndSave(files, vTransparency, path, ImageMerger.GIF);			imageName = output.getName();			imagePath = output.getPath();//			System.out.println("\n\n\nimagePath: " + imagePath + "\n\n\n");//			return(imageName);		}		else if (files.size() == 1) {//			System.out.println("files.get(0) = " + files.get(0)); // DEBUG			File f = new File( files.get(0) );			File out = GlobalTempFiles.getInstance().getFile();//			System.out.println("out.getPath() = " + out.getPath()); // DEBUG			BufferedInputStream is = new BufferedInputStream(new FileInputStream(f));			BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out));			byte buf[] = new byte[1024];			for (int nRead; (nRead = is.read(buf, 0, 1024)) > 0; os.write(buf, 0, nRead))				;			os.flush();			os.close();			is.close();			imageName = out.getName();//			return imageName;		}		else		{			System.out.println("\n\n\nno change to imagename"); // DEBUG//			return ""; // no change to imagename		}		System.out.println("\n\n\nimagePath: " + imagePath + "\n\n\n"); // DEBUG		return imageName;	}	public String getImageName()	{		return imageName;	}	public File getImageLocalPath()	{		return GlobalTempFiles.getInstance().getDir();	}//	public String getImagePath() { return imagePath; }	public String getDegScale() {		DecimalFormat df = new DecimalFormat("###,###");		return df.format(degScale);	}	public String getDistScale() {		DecimalFormat df = new DecimalFormat("###,###");		return df.format(distScale);	}	private static BoundingBox reaspect(BoundingBox bb, int w, int h) {		// Get boundaries		float north = bb.getNorth();		float south = bb.getSouth();		float east = bb.getEast();		float west = bb.getWest();		float dx = Math.abs(east - west);		float dy = Math.abs(north - south);		// Reaspect		if ((w / dx) > (h / dy))		{			float d = dy * w / h - dx;			west -= d / 2;			east += d / 2;			System.out.println("REASPECTING - changing ratio WE += " + d);		}		else if ((h / dy) > (w / dx))		{			float d = dx * h / w - dy;			south -= d / 2;			north += d / 2;			System.out.println("REASPECTING - changing ratio NS += " + d);		}		// Check for pan overflows: shift the map up or down if it can		// N-S: limit navigation		if(north > 90 && south>-90)		{			float off = north - 90;			north = 90;			south -= off;			System.out.println("REASPECTING - shifting NS -= " + off);		}		if(south < -90 && north < 90)		{			float off = - 90 - south;			south = -90;			north += off;			System.out.println("REASPECTING - shifting NS += " + off);		}		// If the map has scrolled enough sideways, then roll the view		// W-E: wrap navigation		if(west > 180)		{			east -= 180;			west -= 180;			System.out.println("REASPECTING - wrapping WE -= 180");		}		if(east < -180)		{			east += 180;			west += 180;			System.out.println("REASPECTING - wrapping WE += 180");		}		// If the map is too much reduced, zoom it to fit the view		if ((Math.abs(east - west)) > 360 && (Math.abs(north - south)) > 180)		{			// Which side can be fully extended?			if(w/360f > h/180f)			{				north = 90;				south = -90;				float we = 180.0f/h*w;				west = -we/2;				east = we/2;				System.out.println("REASPECTING - NS fit, WE = " + we);			}			else			{				west = -180;				east = 180;				float ns = 360.0f/w*h;				north = ns/2;				south = -ns/2;				System.out.println("REASPECTING - WE fit, NS = " + ns);			}		}//		System.out.println("north = " + north + "; south = " + south + "; east = " + east + "; west = " + west);		return new BoundingBox(north, south, east, west);	}//	private class GetImageUrlThread extends Thread {//		private MapService service;//		private BoundingBox bb;//		private int width, height;//		private String url;//		private boolean serviceError = false; // Flag used to detect if a serviceException was thrown by getImageUrl//		private Element error;////		public void run() { sendRequest(); }////		private void sendRequest() {//			try {//				url = service.getImageUrl(bb, width, height);//			}//			catch (ServiceException e) {//				// The service returned an error message (ArcIMS services only)//				serviceError = true;//			}//			catch (Exception e) {//				// Generic error////				e.printStackTrace(); // DEBUG//				serviceError = true;//				url = null;//			}//		}////		public MapService getService() { return service; }////		public void setParameters(MapService service, BoundingBox bb, int width, int height) {//			this.service = service;//			this.bb = bb;//			this.width = width;//			this.height = height;//		}////		public String getUrl() throws ServiceException {//			if (serviceError) {//				throw new ServiceException();//			}//			return url;//		}////		public Element getResponse() { return service.getLastResponse(); }////	}////	private class HttpThread extends Thread {//		private static final int BUF_LEN = 1024;////		private String stUrl;//		private String path;//		private HttpClient c;////		public void run() { connect(); }////		public void setParameters(String url) { stUrl = url; }////		public String getPath() { return path; }////		public HttpClient getHttpClient() { return c; }////		private void connect() {//			BufferedInputStream is = null;//			BufferedOutputStream os = null;////			try {//				c = new HttpClient(stUrl);//				File tf = GlobalTempFiles.getInstance().getFile();//				c.getFile(tf);//				path = tf.getPath();//			}//			catch (Exception e) {//				path = null;//				e.printStackTrace(); // DEBUG//			}//			finally {//				// Close the streams//				try { is.close(); } catch (Exception e) {}//				try { os.close(); } catch (Exception e) {}//			}//		}//	}}

⌨️ 快捷键说明

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