001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.wfp.vam.intermap.services.map;
025:
026: import jeeves.exceptions.MissingParameterEx;
027: import jeeves.interfaces.Service;
028: import jeeves.server.ServiceConfig;
029: import jeeves.server.context.ServiceContext;
030: import org.jdom.Element;
031: import org.wfp.vam.intermap.Constants;
032: import org.wfp.vam.intermap.kernel.map.MapMerger;
033: import org.wfp.vam.intermap.kernel.map.mapServices.BoundingBox;
034: import org.wfp.vam.intermap.kernel.marker.MarkerSet;
035: import org.wfp.vam.intermap.util.Util;
036:
037: //=============================================================================
038:
039: /**
040: */
041:
042: public class Update implements Service {
043: public void init(String appPath, ServiceConfig config)
044: throws Exception {
045: }
046:
047: //--------------------------------------------------------------------------
048: //---
049: //--- Service
050: //---
051: //--------------------------------------------------------------------------
052:
053: public Element exec(Element params, ServiceContext context)
054: throws Exception {
055: String pwidth = params.getChildText("width");
056: String pheight = params.getChildText("height");
057:
058: // Sanity check
059: if (pwidth == null || pheight == null)
060: throw new MissingParameterEx(
061: "Width and height parameters are required");
062:
063: MapMerger mm = MapUtil.getMapMerger(context);
064:
065: // Add default context if none exists
066: if (mm.size() == 0) // No layers to merge
067: {
068: System.out.println("Update: SETTING DEFAULT CONTEXT");
069: MapUtil.setDefaultContext(mm);
070: // Update the user session
071: context.getUserSession().setProperty(Constants.SESSION_MAP,
072: mm);
073: }
074:
075: BoundingBox bb = Util.parseBoundingBox(params); // search bb in params
076: if (bb != null)
077: mm.setBoundingBox(bb);
078:
079: // Merge the images now
080: int width = Integer.parseInt(pwidth);
081: int height = Integer.parseInt(pheight);
082:
083: String imagename = mm.merge(width, height);
084: String url = MapUtil.getTempUrl() + "/" + imagename;
085:
086: // Prepare response
087: Element response = new Element("response").addContent(
088: new Element("imgUrl").setText(url)).addContent(
089: new Element("scale").setText(mm.getDistScale()))
090: .addContent(mm.getBoundingBox().toElement())
091: .addContent(new Element("width").setText("" + width))
092: .addContent(new Element("height").setText("" + height));
093:
094: MarkerSet ms = (MarkerSet) context.getUserSession()
095: .getProperty(Constants.SESSION_MARKERSET);
096: if (ms != null)
097: response.addContent(ms.select(mm.getBoundingBox())
098: .toElement());
099:
100: return response;
101: }
102:
103: }
104:
105: //=============================================================================
|