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

📄 mapperservlet.java

📁 实现网络GPS定位车辆的位置
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.awt.Color;
import java.*;
import java.lang.*;
import java.net.*;
import java.text.DecimalFormat;
import java.sql.*;

// Needed in this servlet for MapJ support
import java.net.Socket;

// MapInfo classes
import com.mapinfo.mapj.*;
import com.mapinfo.mapj.Layers;
import com.mapinfo.util.*;
import com.mapinfo.unit.*;
import com.mapinfo.mapxtreme.client.*;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import com.mapinfo.util.*;
import com.mapinfo.dp.Feature;
import com.mapinfo.dp.FeatureSet;
import com.mapinfo.dp.TableInfo;
import com.mapinfo.dp.Geometry;
import com.mapinfo.dp.VectorGeometry;
import com.mapinfo.dp.PointGeometry;
import com.mapinfo.dp.PointList;
import com.mapinfo.dp.util.*;
import com.mapinfo.dp.jdbc.*;
import com.mapinfo.dp.QueryParams;
import com.mapinfo.dp.SearchType;
import com.mapinfo.dp.Attribute;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.dp.annotation.*;
import com.mapinfo.graphics.Rendition;
import com.mapinfo.coordsys.*;
import com.mapinfo.dp.PrimaryKey;
import com.mapinfo.graphics.RenditionImpl;
import com.mapinfo.unit.LinearUnit;

public class MapperServlet extends HttpServlet {
/*//////////////////////////////////////////////////////////////////////////////////////////////////
初始化变量
///////////////////////////////////////////////////////////////////////////////////////////////////*/
         private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
         private static String m_mapPath = "C:\\MapInfo\\MapXtreme-4.7.0\\examples\\server\\data\\219.237.4.34\\";
//                                               C:\MapInfo\MapXtreme-4.7.0\examples\server\data\219.237.4.34
         private static String m_fileToLoad = "C:\\MapInfo\\MapXtreme-4.7.0\\examples\\server\\data\\219.237.4.34\\beijing.mdf";
         private static String m_mxtURL =
                  "http://219.237.4.34:8080/mapxtreme47/servlet/mapxtreme";//http://219.237.4.29:8080/examples/servlet/mapxtreme";
                  //"http://localhost:8080/mapxtreme45/servlet/mapxtreme";
         private boolean m_debug = false;
         public int m_mapWidth = 600;
         public int m_mapHeight = 400;
         //OracleQueryBuilder MyQuery;
         // Tools
         private final int NO_TOOL = 0;
         private final int ZOOM_IN_TOOL = 1;
         private final int ZOOM_OUT_TOOL = 2;
         private final int PAN_TOOL = 3;
         private final int Telephone_tool=4;
         private final int FIND_TOOL = 5;
         private final int TRACE_TOOL = 6;
         private final int SETSIZE = 7;
         public final int INITCAR_TOOL = 8;
         public final int  CENTER_TOOL = 9;
         //测距工具
         public final  int  RULER_TOOL = 10;
         public final int RESET_TOOL=18;
         //清除画线
         boolean clearLine;
         // Define constants to control various rendering options
         public static final int NUM_OF_COLORS = 256;
         public static final Color BACKGROUND_COLOR = Color.blue;
         public Socket tcpSocket;
         double[][] m_PointArrary= new double[1][5000];
         //测量距离临时变量
          Double xStrTemp = null;
          Double yStrTemp = null ;
          int iLineCount = 0;
          public double iDistance = 0;
  //Initialize global variables
    public void init() throws ServletException {
                  super.init();
                  clearLine=false;
                  String strParam = getInitParameter("mappath");
                  if (strParam != null) {
                           m_mapPath = strParam;
                  }

                  strParam = getInitParameter("filetoload");
                  if (strParam != null) {
                           m_fileToLoad = strParam;
                  }

                  strParam = getInitParameter("mapxtremeurl");
                  if (strParam != null  &&  strParam.length() > 0) {
                           m_mxtURL = strParam;
                  }

                  strParam = getInitParameter("mapwidth");
                  if (strParam != null) {
                           m_mapWidth = Integer.valueOf(strParam).intValue();
                  }

                  strParam = getInitParameter("mapheight");
                  if (strParam != null) {
                           m_mapHeight = Integer.valueOf(strParam).intValue();
                  }

                  strParam = getInitParameter("debug");
                  if (strParam != null  &&  strParam.equalsIgnoreCase("true") ) {
                           m_debug = true;
                  }
  }
/*//////////////////////////////////////////////////////////////////////////////////////////////////
查找数据库
///////////////////////////////////////////////////////////////////////////////////////////////////*/
/*  public Vector getSearchResult(String strSQL){

   Vector v = new Vector();
   try{
     DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
     java.sql.Connection Conn = DriverManager.getConnection ("jdbc:oracle:oci8:@webgis",
                                "webgis", "webgis");;
     java.sql.Statement Stmt = Conn.createStatement();

     java.sql.ResultSet RS = Stmt.executeQuery(strSQL);
     while(RS.next()){
       v.addElement(RS.getString("Country"));
     }
   }catch(Exception e){
     e.printStackTrace();
   }
   return v;
  }*/
/*//////////////////////////////////////////////////////////////////////////////////////////////////
servlet服务
///////////////////////////////////////////////////////////////////////////////////////////////////*/

         public void service (HttpServletRequest req, HttpServletResponse res)
         throws ServletException, IOException
         {
                  // Get the session object
                  HttpSession session = req.getSession(true);
                  String Sql ;
                  String findSql;
                  PrintWriter out;
                 if (req.getParameter("findsql")!=null)
                 {
                  findSql=req.getParameter("findsql");
                  //Sql="select country from world where country like '"+ findSql +"%'";
                  //Vector v = new Vector();
                  //v= getSearchResult(Sql);
                  //res.setContentType("text/html");
                  //out = new PrintWriter(res.getOutputStream());
                  //out.println(v);
                  //out.close();
                 }
               else{
                   if (req.getParameter("init") != null)
                    {
                           res.setContentType("text/html;charset=UTF-8");
                           m_mapWidth=Integer.valueOf(req.getParameter("m_Width")).intValue();
                           m_mapHeight=Integer.valueOf(req.getParameter("m_Height")).intValue();
                           out = new PrintWriter(res.getOutputStream());
                           String thisServletName = HttpUtils.getRequestURL(req).toString();
                           out.println(res.encodeURL(thisServletName));
                           out.close();
                    }
                    else
                    {
                           if (m_debug)
                           {
                                    debugSession(req, session);
                           }
                           // Draw the map and encode the URL
                           try
                           {
                                    renderMap(session, req, res);
                           }
                           catch (ServletException se)
                           {
                                    log(se.getMessage());
                                    throw se;
                           }
                           catch (IOException ioe)
                           {
                                    log(ioe.getMessage());
                                    throw ioe;
                           }
                           // only handle errors the map generation process caused
                           catch (Exception e)
                           {
                                    log(e.getMessage());
                           }
                     }
              }
         }

         /**
          *  This method returns an About string for this servlet
          */
         public String getServletInfo()
         {
                  return "webgis";
         }
/*//////////////////////////////////////////////////////////////////////////////////////////////////
初始化地图
///////////////////////////////////////////////////////////////////////////////////////////////////*/
/*         public MapJ initMapJ()	throws Exception
         {
                 // instantiate a MapJ and set the bounds
                 MapJ myMap = new MapJ();    // this MapJ object
                 myMap.setDeviceBounds(new DoubleRect(0, 0, m_mapWidth, m_mapHeight));

                 // Query for image locations and load the geoset
                 try
                 {
                         if (m_fileToLoad.endsWith(".gst"))
                         {
                                 myMap.loadGeoset(m_fileToLoad, m_mapPath, null);
                         }
                         else {
                           System.out.println("the fucking map has loaded!!!");
                                 myMap.loadMapDefinition(m_fileToLoad);
                           System.out.println("here is the seconds times fuck");
                         }
                 }
                 catch(Exception e)
                 {
                         log("Can't load geoset: " + m_fileToLoad + "\n");
                         throw e;
                 }
                 //System.out.println("here is the fucking third!!!");
                 return myMap;
         }
*/

         public MapJ initMapJ()	throws Exception
         {
                  // instantiate a MapJ and set the bounds
                  MapJ myMap = new MapJ();    // this MapJ object

                  myMap.setDeviceBounds(new DoubleRect(0, 0,m_mapWidth,m_mapHeight));
                  //System.out.println(m_mapWidth+"*"+m_mapHeight);
                  // Query for image locations and load the geoset
                  try
                  {
                           if (m_fileToLoad.endsWith(".gst"))
                           {
                                    myMap.loadGeoset(m_fileToLoad, m_mapPath, null);
                           }
                           else {
                                    myMap.loadMapDefinition(m_fileToLoad);
                                    //System.out.println("the fucking map has already load!!!");
                           }
                           //conn();
                  }
                  catch(Exception e)
                  {
                           log("Can't load geoset: " + m_fileToLoad + "\n");
                           throw e;
                  }
                   iLineCount = 0;
                  return myMap;

         }

/*//////////////////////////////////////////////////////////////////////////////////////////////////
根据applet调用的条件,重新绘制地图,返回给applet
///////////////////////////////////////////////////////////////////////////////////////////////////*/
private void renderMap(HttpSession session,HttpServletRequest req,
                                    HttpServletResponse res)
         throws Exception
         {
                  String reqParam;                   // to hold request parameter
                  Double xStr = null;                // to hold x request params
                  Double yStr = null;                // to hold y request params

                  int tool = NO_TOOL;                // Zoom In, Out or Pan
                  String sFind;
                  Vector cloumns = new Vector();
                  DoublePoint newpoint;
                  DoublePoint newpoint1;
                  DoublePoint newpoint2;

                  String sDistance = null;
                  //PrintWriter out;

                  // Try to retrieve the user's previous MapJ object.
                  MapJ myMap = (MapJ) session.getAttribute("mapinfo.mapj");
                  if (myMap == null) {
                           // This is probably the user's first time requesting a map.
                           //System.out.println("This is probably the user's first time requesting a map.");
                           myMap = initMapJ();

                  }

                  // Check to see if which tool, if any, was set
                  if ((reqParam = req.getParameter("tool"))!=null) {
                    tool = Integer.valueOf(reqParam).intValue();

⌨️ 快捷键说明

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