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

📄 mapviewui.java

📁 实现了一个基于j2me移动gps定位系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright 2001, 2002, 2003 Sun Microsystems, Inc. All Rights Reserved.
 * Except for any files in PNG format (which are marked with the filename
 * extension ".png"), GIF format (which are marked with the filename
 * extension ".gif"), or JPEG format (which are marked with the filename
 * extension ".jpg"), redistribution and use in source and binary forms,
 * with or without modification, are permitted provided that the
 * following conditions are met:
 * - Redistribution of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * - Redistribution in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * You may compile, use, perform and display the following files with
 * original Java Smart Ticket Sample Application code obtained from Sun
 * Microsystems, Inc. only:
 * - files in PNG format and having the ".png" extension
 * - files in GIF format and having the ".gif" extension
 * - files in JPEG format and having the ".jpg" extension
 * You may contents not modify or redistribute .png, .gif, or .jpg files in any
 * form, in whole or in part, by any means without prior written
 * authorization from Sun Microsystems, Inc. and its licensors, if any.
 * Neither the name of Sun Microsystems, Inc., the 'Java Smart Ticket
 * Sample Application', 'Java', 'Java'-based names, or the names of
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
 * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * You acknowledge that this software is not designed, licensed or
 * intended for use in the design, construction, operation or maintenance
 * of any nuclear facility.
 */

/*
 * $Id: MapViewUI.java 291 2008-10-06 09:03:15Z khanh.lnq $
 * $URL: https://jvnmobilegis.googlecode.com/svn/trunk/src/org/javavietnam/gis/client/midp/ui/MapViewUI.java $
 * $Author: khanh.lnq $
 * $Revision: 291 $
 * $Date: 2008-10-06 16:03:15 +0700 (Mon, 06 Oct 2008) $
 *
 * ====================================================================
 *
 * Copyright (C) 2006-2007 by JVNGIS
 *
 * All copyright notices regarding JVNMobileGIS MUST remain
 * intact in the Java codes and resource files.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Support can be obtained from project homepage at:
 * http://code.google.com/p/jvnmobilegis/
 *
 * Correspondence and Marketing Questions can be sent to:
 * khanh.lnq AT gmail.com
 *
 * @version: 1.0
 * @author: Khanh Le
 * @Date Created: 22 Jun 2007
 */
package org.javavietnam.gis.client.midp.ui;

import henson.midp.Float;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

import org.javavietnam.gis.shared.midp.model.MapFeature;
import org.javavietnam.gis.shared.midp.model.WMSRequestParameter;

/**
 * @author khanhlnq
 */
public class MapViewUI extends GameCanvas implements CommandListener,
        WMSRequestParameter {

    private static final int NO_ACTION = 0;
    private static final int MOVE_DOWN = 1;
    private static final int MOVE_LEFT = 2;
    private static final int MOVE_RIGHT = 3;
    private static final int MOVE_UP = 4;
    private static final int ZOOM_IN = 5;
    private static final int ZOOM_OUT = 6;

    private final UIController uiController;
    private final Command backCommand;
    private final Command zoomInCommand;
    private final Command zoomOutCommand;
    private final Command resetCommand;
    private final Command recenterCommand;
    // private Command findPathCommand;
    private final Command whereAmICommand;
    private final Command getFeatureInfoCommand;
    private final Command saveToFileCommand;
    private final Command searchFeatureCommand;
    private final Command helpCommand;
    private final Command refreshCommand;
    private final Font smallFont = Font.getFont(Font.FACE_PROPORTIONAL,
            Font.STYLE_ITALIC, Font.SIZE_SMALL);
    /**
     * @uml.property name="cursorX"
     */
    private int cursorX;
    /**
     * @uml.property name="cursorY"
     */
    private int cursorY;
    // private boolean startPointSelected = false;
    // private boolean endPointSelected = false;
    private boolean isDragging = false;
    private int pointerStartX;
    private int pointerStartY;
    private int pointerEndX;
    private int pointerEndY;
    /**
     * @uml.property name="startPoint"
     * @uml.associationEnd multiplicity="(0 -1)"
     */
    // private Float[] startPoint = new Float[2];
    /**
     */
    // private Float[] endPoint = new Float[2];
    // private boolean isViewPath = false;
    private boolean isViewFeature = false;
    /**
     * @uml.property name="boundingBox"
     * @uml.associationEnd multiplicity="(0 -1)"
     */
    private Float[] boundingBox = new Float[4];
    private Float[] previousBoundingBox = new Float[4];

    private Float[] myLocation = new Float[2];

    private int previousAction = NO_ACTION;
    private boolean isLocated = false;
    /**
     * @uml.property name="getMapURL"
     */
    private String getMapURL = "";
    private Image wmsImg;
    private final int cursorSize;

    public MapViewUI(UIController uiController, boolean suppressKeyEvents) {
        super(suppressKeyEvents);
        // Only set FullScreen for Nokia devices
        try {
            String platform = System.getProperty("microedition.platform");
            System.out.println("******* Platform: " + platform);
            if ((platform != null)
                    && (platform.toLowerCase().trim().indexOf("nokia") >= 0)) {
                this.setFullScreenMode(true);
            }
        } catch (Exception e) {
            // Do nothing
        }

        this.uiController = uiController;

        cursorX = getWidth() / 2;
        cursorY = getHeight() / 2;

        cursorSize = Font.getDefaultFont().charWidth('+');

        backCommand = new Command(uiController.getString(UIConstants.BACK),
                Command.BACK, 5);
        zoomInCommand = new Command(uiController
                .getString(UIConstants.ZOOM_IN_CMD), Command.SCREEN, 1);
        zoomOutCommand = new Command(uiController
                .getString(UIConstants.ZOOM_OUT_CMD), Command.SCREEN, 2);
        resetCommand = new Command(uiController
                .getString(UIConstants.RESET_VIEW_CMD), Command.SCREEN, 3);
        recenterCommand = new Command(uiController
                .getString(UIConstants.RECENTER_CMD), Command.SCREEN, 4);
        refreshCommand = new Command(uiController
                .getString(UIConstants.REFRESH), Command.SCREEN, 5);
        // findPathCommand = new
        // Command(uiController.getString(UIConstants.FIND_PATH_CMD),
        // Command.SCREEN, 5);
        whereAmICommand = new Command(uiController
                .getString(UIConstants.WHERE_AM_I), Command.SCREEN, 6);
        getFeatureInfoCommand = new Command(uiController
                .getString(UIConstants.GET_FEATURE_INFO), Command.SCREEN, 7);
        searchFeatureCommand = new Command(uiController
                .getString(UIConstants.SEARCH_FEATURE_UI_TITLE),
                Command.SCREEN, 8);
        saveToFileCommand = new Command(uiController
                .getString(UIConstants.SAVE_TO_FILE), Command.SCREEN, 9);
        helpCommand = new Command(uiController.getString(UIConstants.HELP_CMD),
                Command.SCREEN, 10);

        addCommand(zoomInCommand);
        addCommand(zoomOutCommand);
        addCommand(resetCommand);
        addCommand(recenterCommand);
        addCommand(backCommand);
        addCommand(refreshCommand);
        // addCommand(findPathCommand);
        addCommand(whereAmICommand);
        addCommand(getFeatureInfoCommand);
        addCommand(searchFeatureCommand);
        addCommand(saveToFileCommand);
        addCommand(helpCommand);

        previousAction = NO_ACTION;

        uiController.setCommands(this);

        setCommandListener(this);
    }

    public void init(Image img) {
        this.wmsImg = img;
        repaint();
    }

    public void initParam(Float[] latLonBoundingBox, String getMapURL,
            String srs) {
        System.arraycopy(latLonBoundingBox, 0, boundingBox, 0, 4);
        this.getMapURL = getMapURL;

        // Resize bounding box to device dimension
        Float boxWidth = (getBoxHeight().Mul(getWidth())).Div(getHeight());
        if (boxWidth.Less(getBoxWidth())) {
            boxWidth = getBoxWidth();
        }

        Float boxHeight = (getBoxWidth().Mul(getHeight())).Div(getWidth());
        if (boxHeight.Less(getBoxHeight())) {
            boxHeight = getBoxHeight();
        }

        // Note, the coordinate of map is decart coordinate
        boundingBox[0] = boundingBox[2].Sub(boxWidth);
        boundingBox[1] = boundingBox[3].Sub(boxHeight);

        previousAction = NO_ACTION;

        // startPointSelected = false;
        // endPointSelected = false;
    }

    /**
     * @param latLonBoundingBox
     *            the boundingBox to set
     * @uml.property name="boundingBox"
     */
    public void setBoundingBox(Float[] latLonBoundingBox) {
        System.arraycopy(latLonBoundingBox, 0, boundingBox, 0, 4);

        // Resize bounding box to device dimension
        Float boxWidth = (getBoxHeight().Mul(getWidth())).Div(getHeight());
        if (boxWidth.Less(getBoxWidth())) {
            boxWidth = getBoxWidth();
        }

        Float boxHeight = (getBoxWidth().Mul(getHeight())).Div(getWidth());
        if (boxHeight.Less(getBoxHeight())) {
            boxHeight = getBoxHeight();
        }

        // Note, the coordinate of map is decart coordinate
        boundingBox[0] = boundingBox[2].Sub(boxWidth);
        boundingBox[1] = boundingBox[3].Sub(boxHeight);

        previousAction = NO_ACTION;

        // startPointSelected = false;
        // endPointSelected = false;
    }

    /**
     * @return the boundingBox
     * @uml.property name="boundingBox"
     */
    public Float[] getBoundingBox() {
        return boundingBox;
    }

    public Float getBoundingX1() {
        return boundingBox[0];
    }

    public Float getBoundingY1() {
        return boundingBox[1];
    }

    public Float getBoundingX2() {
        return boundingBox[2];
    }

    public Float getBoundingY2() {
        return boundingBox[3];
    }

    public String getImageFormat() {
        return ("image/png");
    }

    public String getXmlFormat() {
        return ("text/xml");
    }

    public String getTextFormat() {
        return ("text/plain");
    }

    public String getPNGFormat() {
        return ("image/png");
    }

    /*
     * public void setIsViewPath(boolean viewPath) { this.isViewPath = viewPath;
     * }
     */
    public void setIsViewFeature(boolean viewFeature) {
        this.isViewFeature = viewFeature;
    }

    public String getSRS() {

⌨️ 快捷键说明

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