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

📄 htmlembeddedmapservlet.java

📁 java开发的MAP
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		Integer iTool = (Integer)session.getAttribute("mapinfo.toolnumber");
		if (iTool != null) {
			// There was a setting, so use it.
			toolNumber = iTool.intValue();
		} else {
			// There was no setting; default to the Pan tool.
			toolNumber = MapToolkit.MAPTOOL_PAN;
		}
		sb.append("<p ALIGN=\"LEFT\">" +
			toolkit.getHTMLMapToolsControl(toolNumber) + "</p>");
					
		// Place the zoom (map width) control, if it's wanted.
		if (m_bIncludeZoomWidth) { 
			sb.append("<HR><P ALIGN=\"LEFT\">" + 
				toolkit.getString("app.map_width", "Map width:") + "<BR>" +
				toolkit.getHTMLZoomControl(myMap, 
					toolkit.getString("app.apply", "Apply")) + "</p>");
		}

		// Place a link that brings up Layer Control
		if (m_bIncludeLayerControl) {		 
			sb.append("<HR><P ALIGN=\"CENTER\"><A HREF=\"" +
				res.encodeURL(m_thisServletURL + "?" + FF_REQUEST_TYPE +
				"=LS&" + getHiddenQueryString(myMap, session)) + "\">" +
				toolkit.getString("app.layer_settings", "Layer settings") + "</A></P>");
		}

		// Place a link to toggle the map size large/small
		if (m_bIncludeToggleSize) {		 
			String strToggle;
			if (bSmallMap) {
				strToggle = toolkit.getString("app.enlarge_map", "Enlarge map");
			} else {
				strToggle = toolkit.getString("app.reduce_map", "Reduce map");
			}
			sb.append("<HR><P ALIGN=\"CENTER\"><A HREF=\"" +
				res.encodeURL(m_thisServletURL + "?" + FF_REQUEST_TYPE +
				"=TS&" + getHiddenQueryString(myMap, session)) +
				"\">" + strToggle + "</A></P>");
		}		 

		// End the cell, the row and the table. 
		sb.append("</td></tr></table>");

		// Underneath the table, display a scalebar. 
		if (m_bIncludeScalebar) {
			com.mapinfo.unit.LinearUnit lUnit = myMap.getDistanceUnits(); 
			sb.append("<BR>" +
				toolkit.getHTMLScaleBar(myMap,0,lUnit.getAbbreviation()) );
		}

		// Include hidden form fields in the page, to record the
		// map's status (zoom level, center point) so that we can
		// restore the map status if the user submits the form
		// *after* their session has expired.
		sb.append(getHiddenFormFields(myMap, session));

		sb.append("</form>");
		if (m_bDebug) {
			sb.append(m_debugMessage + "<BR>\n");
			sb.append(getParamInfo());
		}
		// Finish the HTML 
		sb.append("</BODY></HTML>");
		return sb.toString();
	}

	// Return a String of HTML that represents an error message HTML page.
	private String getErrorPage(String str) {
		StringBuffer sb = new StringBuffer();
		sb.append("<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>");
		sb.append("<h2><font FACE=\"Verdana,Geneva,Arial,Helvetica\">Error</font></h2>");
		sb.append("<P>" + str + "</P>");
		if (m_bDebug) {
			sb.append(m_debugMessage + "<BR>\n");
			sb.append(getParamInfo());
		}
		sb.append("</BODY></HTML>");
		return sb.toString();
	}

	// Return a String of HTML that defines a Layer Settings page
	// (aka Layer Control).
	private String getLayerSettingsPage(
			MapJ map, MapToolkit toolkit, HttpSession session, HttpServletResponse res) {
		StringBuffer sb = new StringBuffer();
		sb.append("<HTML><HEAD><TITLE>" +
      toolkit.getString("app.layer_settings", "Layer settings"));
		sb.append("</TITLE></HEAD><BODY>");
		sb.append("<h2><font FACE=\"Verdana,Geneva,Arial,Helvetica\">");
		sb.append(toolkit.getString("app.layer_settings", "Layer settings"));
		sb.append("</font></h2>");
		sb.append("<form method=\"POST\" action=\"" +
			res.encodeURL(m_thisServletURL) + "\">");

		// Use a routine in the toolkit class to build the main part of the page
		sb.append(toolkit.getHTMLLayerListControl(map,
			"Verdana,Geneva,Arial,Helvetica"));

		// Add Apply and Cancel buttons
		sb.append("<BR>" + getHTMLApplyCancel(FF_LS_APPLY, FF_LS_CANCEL));

		// Include hidden form fields in the page, to record the
		// map's status (zoom level, center point) so that we can
		// restore the map status if the user submits the form
		// *after* their session has expired.
		sb.append(getHiddenFormFields(map, session));

		sb.append("</form>");
		sb.append("</BODY></HTML>");

		return sb.toString();
	}

	/** getHTMLApplyCancel:
	* Return the HTML code that defines an Apply button and a Cancel button.
	* @param	applyFieldname	the caption to appear on the Apply button
	* @param	cancelFieldname the caption to appear on the Cancel button
	*
	* @return	a String representing the HTML for "Apply" and "Cancel" buttons.
	*/
	String getHTMLApplyCancel(String applyFieldname, String cancelFieldname) {
		StringBuffer sb = new StringBuffer();
		sb.append("<INPUT TYPE=\"SUBMIT\" NAME=\"" + applyFieldname + "\" ");
		sb.append("VALUE=\"" + "Apply" + "\">");
		sb.append("&nbsp;&nbsp;&nbsp;&nbsp;");
		sb.append("<INPUT TYPE=\"SUBMIT\" NAME=\"" + cancelFieldname + "\" ");
		sb.append("VALUE=\"" + "Cancel" + "\">");
		return sb.toString();
	}

	/**
	* This method returns a set of HTML "hidden form fields" to store
	* information about the map's current zoom level and center point.
	* This information can be included in the web page to allow us
	* to restore the user to the correct view of the map, if the user
	* submits the map page form *after* their session has expired.
	*/
	String getHiddenFormFields(MapJ myMap, HttpSession session) {
		StringBuffer sb = new StringBuffer();
		try {
			DoublePoint dp = myMap.getCenter();
			double zoom = myMap.getZoom();
			sb.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FF_OLD_X +
				"\" VALUE=\"" + dp.x + "\">");
			sb.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FF_OLD_Y +
				"\" VALUE=\"" + dp.y + "\">");
			sb.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FF_OLD_ZOOM +
				"\" VALUE=\"" + zoom + "\">");

			// If the user has switched to the large map size,
			// store a size flag.
			Boolean bSize = (Boolean)session.getAttribute("mapinfo.mapsize");
			if (bSize != null  &&  bSize.booleanValue() == false) {
				// The 'small' setting was false (meaning that the user
				// was viewing the large-sized map), so output a size flag.
				// Later, if the flag is present at all, we will know to use
				// the large sized map.
				sb.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + FF_OLD_SIZE_LARGE +
					"\" VALUE=\"true\">");
			}
		}
		catch (Exception e) {
			return "";
		}
		return sb.toString();
	}

	/**
	* This method returns a set of query strings to store
	* information about the map's current zoom level and center point.
	* This information can be included in a link's URL, to allow us
	* to restore the user to the correct view of the map, if the user
	* clicks the link *after* the session has expired.
	*/
	String getHiddenQueryString(MapJ myMap, HttpSession session) {
		StringBuffer sb = new StringBuffer();
		try {
			DoublePoint dp = myMap.getCenter();
			double zoom = myMap.getZoom();
			sb.append(FF_OLD_X + "=" + dp.x);
			sb.append("&" + FF_OLD_Y + "=" + dp.y);
			sb.append("&" + FF_OLD_ZOOM + "=" + zoom);
			// If the user has switched to the large map size,
			// store a size flag.
			Boolean bSize = (Boolean)session.getAttribute("mapinfo.mapsize");
			if (bSize != null  &&  bSize.booleanValue() == false) {
				// The 'small' setting was false (meaning that the user
				// was viewing the large-sized map), so output a size flag.
				// Later, if the flag is present at all, we will know to use
				// the large sized map.
				sb.append("&" + FF_OLD_SIZE_LARGE + "=true");
			}
		}
		catch (Exception e) {
			return "";
		}
		return sb.toString();
	}

	/**
	* This sets the map to the zoom level and center point position
	* that were stored in the map page's hidden form fields.
	* Call this method if a user's session has expired, and you want
	* to set the new session to a state that matches the old session.
	*/
	void applyHiddenFormFields(MapJ myMap, Hashtable ht, HttpSession session) {
		try {
			DoublePoint mapPoint = (DoublePoint)ht.get(HT_OLD_MAP_LOCATION);
			if (mapPoint != null) {
				myMap.setCenter(mapPoint);
			}
			Double zoom = (Double)ht.get(FF_OLD_ZOOM);
			if (zoom != null) {
				myMap.setZoom(zoom.doubleValue() );
			}
			// If the page included a hidden form field named FF_OLD_SIZE_LARGE,
			// it means the user had switched to the large map size, in which
			// case we will set our MapJ to large size.
			String sizeTest = (String)ht.get(FF_OLD_SIZE_LARGE);
			if (sizeTest != null) {
				// The user was using a large map image previously.
				// Set the map's size setting, and store the size setting
				// in the session object (specifying false as the "small" flag).
				setMapSize(myMap, false);
				session.setAttribute("mapinfo.mapsize", new Boolean(false));
			}
		}
		catch (Exception e) {
		}
	}

	/**
	* This method returns servlet status info.
	* Used when the m_bDebug flag is true.
	*/
	private String getSessionInfo(HttpServletRequest req, HttpSession session)
	{
		StringBuffer sb = new StringBuffer();

		sb.append("<h3>Request and Session Data:</h3>");
		sb.append("Session ID in Request: " +
				req.getRequestedSessionId());
		sb.append("<br>Session ID in Request from Cookie: " +
				req.isRequestedSessionIdFromCookie());

		sb.append("<br>Session ID in Request from URL: " +
				req.isRequestedSessionIdFromURL() );
		sb.append("<br>Valid Session ID: " +
				req.isRequestedSessionIdValid() );

		sb.append("<h3>Session Data:</h3>");
		sb.append("New Session: " + session.isNew());
		sb.append("<br>Session ID: " + session.getId());
		sb.append("<br>Creation Time: " + session.getCreationTime());
		sb.append("<br>Last Accessed Time: " +
				session.getLastAccessedTime());
		return sb.toString();
	}

	/**
	* This method returns servlet status info.
	* Used when the m_bDebug flag is true.
	*/
	private String getParamInfo() {
		StringBuffer sb = new StringBuffer();

		sb.append("<h3>Parameters: </h3>");
		sb.append("m_fileToLoad ('filetoload' property): " + m_fileToLoad + "<BR>");
		sb.append("m_mapImagePath ('mapimagepath' property): " + m_mapImagePath + "<BR>");
		sb.append("m_mapImageURL ('mapimageurl' property): " + m_mapImageURL + "<BR>");
		sb.append("m_mxtURL ('mapxtremeurl' property): " + m_mxtURL + "<BR>");
		return sb.toString();
	}

	// This method returns a unique filename, so that the map images
	// created for one user will not conflict with or overwrite
	// the images created for another user.
	private synchronized String getImageName()
	{
		m_imageCounter++;
		return m_imagePrefix + m_imageCounter;
	}


	/**
	*	This class is used to remove the temporary image file when the
	*	client session expires.
	*/
	class CleanUp implements HttpSessionBindingListener
	{
		String m_filename = null;			// Image filename

		public CleanUp(String filename) {
			m_filename = filename;
		}

		public void valueBound(HttpSessionBindingEvent e)	{
			// The user's session has begun;	m_filename	indicates
			// the name of the image file that will be used for this user's session.
			//System.out.println("Bound event: " + e.toString()
			//	 + "\n m_filename: " + m_filename);
		}

		public void valueUnbound(HttpSessionBindingEvent e) {
			//	The user's session expired; delete the image file.
			File delFile = new File(m_filename);
			if (delFile != null) {
				delFile.delete();
			}
			//System.out.println("Unbound event: " + e.toString()
			//	+ "\n m_filename: " + m_filename);
		}
	}
}


class ServletFieldReader implements FieldReader	{
	private transient HttpServletRequest m_HTMLRequest;

	public ServletFieldReader(HttpServletRequest	HTMLRequest) {
		 m_HTMLRequest = HTMLRequest;
	}
	public String getField(String strFieldName) {
		try {
			return m_HTMLRequest.getParameter(strFieldName);
		} catch (Exception e) { }
		return null;
	}
}

⌨️ 快捷键说明

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