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

📄 imagebean.java

📁 代码名称:简单的动态监控示例(带定位数据库) 作者/收集者:kj_wang_20 开发环境:MapXtreme for Java + access 代码介绍: 基于Ma
💻 JAVA
字号:

package sample;

// Java imports
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;

// MXJ imports
import com.mapinfo.mapj.MapJ;
import com.mapinfo.mapxtreme.client.EncodedImageRenderer;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import com.mapinfo.xmlprot.MapImageResponse;
import com.mapinfo.graphics.Rendition;
import com.mapinfo.graphics.RenditionImpl;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.util.Overlay;
import com.mapinfo.theme.OverrideTheme;
import com.mapinfo.unit.LinearUnit;

/**
 * OverlayImageServlet is a sample application that demonstrates how overlay
 * images can be displayed on a map in a thin client scenario. In this example,
 * an animated GIF image ("ColorStar.gif") is used as the overlay.
 */
public class  ImageBean
{
	/* TODO: Specify the URL of the MapXtremeServlet that will
	 * service our mapping requests.
	 *
	 * Or, instead of specifying a literal string value here, you can
	 * specify this value using an init parameter called 'mapxtremeurl'.
	 */
	private String m_mxjURL = "http://localhost:8080/mapxtreme45/mapxtreme";

	//private String m_baseImageURL = "http://wangkj:8088/overlay/";

	private String m_mdf = "f:/Program Files/MapInfo/MapXtreme-4.5.0/examples/server/data/wangkj/world.mdf";


	// constants
	private static final String BASE_IMAGE    = "basemap.gif";
	private static final String OVERLAY_IMAGE = "ColorStar.gif";
	//private static final String IMAGE_HTML    = "images.htm";

	// full path & filename of the base map image
	private String m_imgOutputFile = null;
        double centerPointX,centerPointY,minX,maxX,minY,maxY;
        DoubleRect  doubleRect = null;

        int zoom = 0;
        String imageFileName = null;
        String contextPath = null;
              //new Double(x)).doubleValue()
	// full path & filename of the images HTML file
	//private String m_htmlOutputFile = null;

        private ServletConfig servletConfig;

        private ServletContext servletContext;


	public ImageBean()
	{





	}


        public void init(ServletContext servlet, ServletConfig config) throws ServletException {
                //System.out.println("Starting struts-menu initialization");

                this.servletContext = servlet;
                this.servletConfig = config;
                //m_imgOutputFile  = m_baseImageURL + "/" + BASE_IMAGE;

                contextPath = servletContext.getRealPath("/");
                contextPath = contextPath.replace('\\', '/');

                                // build the path where our base map image will be saved
                //m_imgOutputFile  = contextPath + "/" + BASE_IMAGE;
        }



        public void setCenterPoint(double x,double y){
          centerPointX = x;
          centerPointY = y;
        }

        public void setZoom(int Zoom){
          zoom = Zoom;
        }

        public String getImageUrl(){
          if(imageFileName != null)
            return imageFileName;
          return imageFileName;
        }

        public double getMinX(){
          return minX;
        }

        public double getMaxX(){
          return maxX;
        }

        public double getMinY(){
          return minY;
        }

        public double getMaxY(){
          return maxY;
        }

        public DoubleRect getDoubleRect(){
          return doubleRect;
        }







	public void createOverlayMap()
	{
		try
		{
			// Load the MDF, set the zoom & center
			MapJ map = new MapJ();
			map.loadMapDefinition(m_mdf);

			DoublePoint centerPoint = new DoublePoint(centerPointX, centerPointY);
			map.setCenter(centerPoint);
			map.setDistanceUnits(LinearUnit.mile);
			map.setZoom(this.zoom);

                        minX = map.getDeviceBounds().xmin;
                        maxX = map.getDeviceBounds().xmax;
                        minY = map.getDeviceBounds().ymin;
                        maxY = map.getDeviceBounds().ymax;

                        doubleRect = map.getDeviceBounds();

			// Create a Rendition to indicate that a symbol should not be drawn
			// into the map, but added to the list of Overlay images
/*			Rendition rendition = new RenditionImpl();
			rendition.setValue(
				Rendition.SYMBOL_MODE, Rendition.SymbolMode.OVERLAY_IMAGE);

			// Specify the location of the Overlay image (animated gif in this
			// example) to use
			rendition.setValue(
				Rendition.SYMBOL_URL, m_baseImageURL + OVERLAY_IMAGE);

			// Create an OverrideTheme on the "World Capitals" layer using the
			// above rendition
			OverrideTheme ovrTheme = new
				OverrideTheme(rendition, "AnimatedImages");
			map.getLayers().elementAt(0).getThemeList().add(ovrTheme);
*/

			/* Use the EncodedImageRenderer to submit the mapping request. This
			 * will create the base map image and the list of Overlay images.
			 * We then use the MapImageResponse object to access these items.
			 * Note that you must use EncodedImageRenderer to create the
			 * appropriate mime type, as shown below.
			 */
			EncodedImageRenderer renderer = new EncodedImageRenderer(m_mxjURL);
			String mimeType = renderer.createMimeType("image/gif");


			ImageRequestComposer irc = ImageRequestComposer.create(
				map, ImageRequestComposer.MAX_COLORS_TRUECOLOR, Color.blue, mimeType);

			renderer.render(irc);

			// now work with the response object
			MapImageResponse response = renderer.getResponse();
                        imageFileName = "baseMap" + centerPointX + centerPointY + ".gif";
                        m_imgOutputFile  = contextPath + "/" + imageFileName;

			// save the base map image to the path we've determined
			FileOutputStream fos = new FileOutputStream(m_imgOutputFile);
			fos.write(response.getEncodedImage() );
			fos.close();

			// Pause for a second to allow the image to be written to disk
			Thread.sleep(1000);


			// Get the List of Overlay objects and pass them to the method that
			// constructs the images HTML page.
			//List overlayImages = response.getOverlayList();
			//createImageHTML(overlayImages);


			// For informational purposes, print each Overlay's position to
			// the console
			//for (Iterator i = overlayImages.iterator(); i.hasNext(); )
			//{
		//		Overlay overlay = (Overlay)i.next();

				//output the screen coordinates of each overlay image
		//		System.out.println("Image: " + overlay.getPoint());
		//	}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

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