Package com.lbslocal.api.view

Source Code of com.lbslocal.api.view.MapRender

package com.lbslocal.api.view;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.lbslocal.master.common.ConfigurationManager;
import com.lbslocal.api.revgeo.exception.RevGeoException;
import com.lbslocal.api.utils.CommonRest;
import com.lbslocal.api.utils.CommonRest.ObjectsHelper;
import com.lbslocal.api.utils.CommonRest.PostHelper;
import com.lbslocal.cc.objects.v0.common.Extent;
import com.lbslocal.cc.objects.v0.common.Icon;
import com.lbslocal.cc.objects.v0.common.MapInfo;
import com.lbslocal.cc.objects.v0.common.MapOptions;
import com.lbslocal.cc.objects.v0.common.MapSize;
import com.lbslocal.cc.objects.v0.common.Point;
import com.lbslocal.cc.view.CMapRenderAPI;

public class MapRender extends HttpServlet
{
  private static final long serialVersionUID = 1L;
 
  public MapRender()
  {
    super();
  }
 
 
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
   
  }
 
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
    try
    {
      ConfigurationManager cm = ConfigurationManager.getInstance();
     
      int id_licenca = Integer.parseInt(cm.getAppSettings("ID"));
     

     
      CMapRenderAPI cMr = new CMapRenderAPI(
          cm.getAppSettings("MAQUINA"),
          cm.getAppSettings("SERVER"),
          11188,
          cm.getAppSettings("PATH_FILE_IMAGES"),
          cm.getAppSettings("WEBOUTPUT"),
          cm.getAppSettings("M_BASEDECARTA_MAPAS"));
     
      CommonRest cr = new CommonRest();
     
      PostHelper ph = cr.getDataFromPost(request);
     
      String strLicenca = cr.getFieldFromXML(ph.XMLFile, "token");
      try {
        id_licenca = Integer.parseInt(strLicenca);
      } catch (Exception e) {
      }
     
      if (ph.fields[0].equals("getZoomRadius"))
      {
        MapInfo mi = new MapInfo();
       
        String mapType = cr.getFieldFromXML(ph.XMLFile, "maptype");
       
        if (!mapType.toLowerCase().equals("gif") && !mapType.toLowerCase().equals("png") && !mapType.toLowerCase().equals("jpg") ){
          mapType = "png";
        }
       
        Point point = (Point) cr.getObjectFromXML(ph.XMLFile, "point", Point.class, null);
       
        ObjectsHelper[] mapOptionsDependencyObjects = new ObjectsHelper[4];
       
        mapOptionsDependencyObjects[0] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[0].object = new MapSize();
        mapOptionsDependencyObjects[0].alias = "mapSize";
       
        mapOptionsDependencyObjects[1] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[1].object = new Icon[0];
        mapOptionsDependencyObjects[1].alias = "icon";
       
        mapOptionsDependencyObjects[2] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[2].object = new Icon();
        mapOptionsDependencyObjects[2].alias = "Icon";
       
        mapOptionsDependencyObjects[3] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[3].object = new Point();
        mapOptionsDependencyObjects[3].alias = "point";
 
        MapOptions mo = (MapOptions) cr.getObjectFromXML(ph.XMLFile, "mo", MapOptions.class, mapOptionsDependencyObjects);
       
        String routeId = cr.getFieldFromXML(ph.XMLFile, "routeId");
        int radius = Integer.valueOf(cr.getFieldFromXML(ph.XMLFile, "radius"));
       
        try
        {
          mi = cMr.getZoomRadius(routeId, point, radius, mo, id_licenca, mapType);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
       
        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
       
        ObjectsHelper[] dependencyObjects = new ObjectsHelper[2];
       
        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new Extent();
        dependencyObjects[0].alias = "extent";
       
        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new MapInfo();
        dependencyObjects[1].alias = "MapInfo";

        response.getWriter().write("<?xml version='1.0' encoding='UTF-8'?>\n" + cr.getXMLFromObject(mi, dependencyObjects) + "");
      }
      if (ph.fields[0].equals("getMap"))
      {
        MapInfo mi = new MapInfo();
       
        String mapType = cr.getFieldFromXML(ph.XMLFile, "maptype");
       
        if (!mapType.toLowerCase().equals("gif") && !mapType.toLowerCase().equals("png") && !mapType.toLowerCase().equals("jpg") ){
          mapType = "png";
        }
       
        Extent extent = (Extent) cr.getObjectFromXML(ph.XMLFile, "extent", Extent.class, null);
       
        ObjectsHelper[] mapOptionsDependencyObjects = new ObjectsHelper[4];
       
        mapOptionsDependencyObjects[0] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[0].object = new MapSize();
        mapOptionsDependencyObjects[0].alias = "mapSize";
       
        mapOptionsDependencyObjects[1] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[1].object = new Icon[0];
        mapOptionsDependencyObjects[1].alias = "icon";
       
        mapOptionsDependencyObjects[2] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[2].object = new Icon();
        mapOptionsDependencyObjects[2].alias = "Icon";
       
        mapOptionsDependencyObjects[3] = cr.new ObjectsHelper();
        mapOptionsDependencyObjects[3].object = new Point();
        mapOptionsDependencyObjects[3].alias = "point";
 
        MapOptions mo = (MapOptions) cr.getObjectFromXML(ph.XMLFile, "mo", MapOptions.class, mapOptionsDependencyObjects);
       
        String routeId = cr.getFieldFromXML(ph.XMLFile, "routeId");

       
        try
        {
          mi = cMr.getMap(routeId, extent, mo, id_licenca, mapType);
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
       
        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
       
        ObjectsHelper[] dependencyObjects = new ObjectsHelper[2];
       
        dependencyObjects[0] = cr.new ObjectsHelper();
        dependencyObjects[0].object = new Extent();
        dependencyObjects[0].alias = "extent";
       
        dependencyObjects[1] = cr.new ObjectsHelper();
        dependencyObjects[1].object = new MapInfo();
        dependencyObjects[1].alias = "MapInfo";

        response.getWriter().write("<?xml version='1.0' encoding='UTF-8'?>\n" + cr.getXMLFromObject(mi, dependencyObjects) + "");
      }
     
    }
    catch (NumberFormatException e)
    {
      response.getWriter().write(RevGeoException.getErrorMessage(RevGeoException.NUMBER_ERROR));
    }
  }
}
TOP

Related Classes of com.lbslocal.api.view.MapRender

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.