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.interfaces.Service;
027: import jeeves.server.ServiceConfig;
028: import jeeves.server.context.ServiceContext;
029: import org.jdom.Element;
030: import org.wfp.vam.intermap.Constants;
031: import org.wfp.vam.intermap.kernel.map.MapMerger;
032: import org.wfp.vam.intermap.kernel.map.mapServices.BoundingBox;
033: import org.wfp.vam.intermap.kernel.marker.MarkerSet;
034: import org.wfp.vam.intermap.util.Util;
035:
036: //=============================================================================
037:
038: /** main.result service. shows search results
039: */
040:
041: public class Action implements Service {
042: public void init(String appPath, ServiceConfig config)
043: throws Exception {
044: }
045:
046: //--------------------------------------------------------------------------
047: //---
048: //--- Service
049: //---
050: //--------------------------------------------------------------------------
051:
052: public Element exec(Element params, ServiceContext context)
053: throws Exception {
054: String mapTool = params.getChildText("maptool");
055: int mapimgx = Integer.parseInt(params.getChildText("mapimgx"));
056: int mapimgy = Integer.parseInt(params.getChildText("mapimgy"));
057: int mapimgx2 = Integer
058: .parseInt(params.getChildText("mapimgx2"));
059: int mapimgy2 = Integer
060: .parseInt(params.getChildText("mapimgy2"));
061:
062: // int width = Util.parseInt(params.getChildText("width"), MapUtil.getImageWidth(context));
063: // int height = Util.parseInt(params.getChildText("height"), MapUtil.getImageHeight(context));
064: int width = Integer.parseInt(params.getChildText("width"));
065: int height = Integer.parseInt(params.getChildText("height"));
066:
067: MapMerger mm = MapUtil.getMapMerger(context);
068:
069: BoundingBox bb = Util.parseBoundingBox(params); // search bb in params
070: if (bb == null)
071: bb = mm.getBoundingBox();
072:
073: // zoom in
074: if ("zoomin".equals(mapTool)) {
075: if (mapimgx2 == mapimgx && mapimgy2 == mapimgy) {
076: MapUtil.moveTo(bb, mapimgx, mapimgy, width, height);
077: bb.zoom(2);
078: } else {
079: BoundingBox newbb = MapUtil.zoomInBox(bb, mapimgx,
080: mapimgy, mapimgx2, mapimgy2, width, height);
081: mm.setBoundingBox(newbb);
082: }
083: }
084:
085: // zoom out
086: if ("zoomout".equals(mapTool)) {
087: if (mapimgx2 == mapimgx && mapimgy2 == mapimgy) {
088: MapUtil.moveTo(bb, mapimgx, mapimgy, width, height);
089: bb.zoom(1 / (float) 2);
090: } else { // TODO
091: BoundingBox newbb = MapUtil.zoomOutBox(bb, mapimgx,
092: mapimgy, mapimgx2, mapimgy2, width, height);
093: mm.setBoundingBox(newbb);
094: }
095: }
096:
097: // zoom out
098: if ("pan".equals(mapTool)) {
099: MapUtil.moveTo(bb, mapimgx, mapimgy, width, height);
100: }
101:
102: if ("identify".equals(mapTool)) {
103: // reanslate arguments to keep compatibility with previous versions
104: params.addContent(new Element(Constants.MAP_X).setText(""
105: + mapimgx));
106: params.addContent(new Element(Constants.MAP_Y).setText(""
107: + mapimgy));
108: Identify identify = new Identify();
109: return identify.exec(params, context);
110: }
111:
112: // Merge the images now
113: String imagename = mm.merge(width, height);
114: String url = MapUtil.getTempUrl() + "/" + imagename;
115:
116: // Prepare response
117: Element response = new Element("response").addContent(
118: new Element("imgUrl").setText(url)).addContent(
119: new Element("scale").setText(mm.getDistScale()))
120: .addContent(mm.getBoundingBox().toElement())
121: .addContent(new Element("width").setText("" + width))
122: .addContent(new Element("height").setText("" + height));
123:
124: MarkerSet ms = (MarkerSet) context.getUserSession()
125: .getProperty(Constants.SESSION_MARKERSET);
126: if (ms != null)
127: response.addContent(ms.select(mm.getBoundingBox())
128: .toElement());
129:
130: return response;
131: }
132: }
133:
134: //=============================================================================
|