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

📄 mapcanvas.java

📁 j2me写的google地图
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

                case 8: // '\b'
                    for(Enumeration en = m_listTrack.elements(); en.hasMoreElements();)
                    {
                        Track tr = (Track)en.nextElement();
                        if(tr.listPlaces.contains(currentSel) && tr.fireOpened(currentSel))
                            return;
                    }

                    fireOnLocationSelected(currentSel);
                    break;
                }
            else
                switch(action)
                {
                case 2: // '\002'
                    zpx -= 4;
                    break;

                case 5: // '\005'
                    zpx += 4;
                    break;

                case 1: // '\001'
                    zpy -= 4;
                    break;

                case 6: // '\006'
                    zpy += 4;
                    break;

                case 8: // '\b'
                    stopZooming();
                    break;
                }
        repaint();
    }

    public void stopZooming()
    {
        zoomingMode = false;
        int f = 1 << zoom;
        px += (zpx - width / 2) * f;
        py += (zpy - height / 2) * f;
        setZoom(requestedZoom);
    }

    public boolean changeSatMode()
    {
        m_modeSat = !m_modeSat;
        BufferImage.cleanBuffer();
        if(m_modeSat)
            setInfoOnScreen("Switching to satellite mode");
        else
            setInfoOnScreen("Switching to map mode");
        return m_modeSat;
    }

    public int getCurSat()
    {
        return m_curSat;
    }

    public void setCurSat(int inNumSat)
    {
        inNumSat %= 4;
        if(inNumSat != m_curSat)
        {
            m_curSat = inNumSat;
            BufferImage.cleanBuffer();
        }
    }

    private void fireOnLocationSelected(OneLoc currentSel)
    {
        if(currentSel != null)
        {
            for(int i = 0; i < m_listeners.size(); i++)
                ((MapCanvasListener)m_listeners.elementAt(i)).oneLocationSelected(this, currentSel);

        }
    }

    private void fireOnMoveEnd()
    {
        for(int i = 0; i < m_listeners.size(); i++)
            ((MapCanvasListener)m_listeners.elementAt(i)).onMoveEnd(this);

    }

    private boolean fireMapKeyPressed(int code)
    {
        for(int i = 0; i < m_listeners.size(); i++)
            if(!((MapCanvasListener)m_listeners.elementAt(i)).mapKeyPressed(this, code))
                return false;

        return true;
    }

    public void addListener(MapCanvasListener inListener)
    {
        if(!m_listeners.contains(inListener))
            m_listeners.addElement(inListener);
    }

    public void removeListener(MapCanvasListener inListener)
    {
        m_listeners.removeElement(inListener);
    }

    public void iconDownloaded(OneLoc theLoc)
    {
        repaint();
    }

    public void drawArrow(Graphics g, oneGPSPos pos, int x, int y, int col)
    {
        g.setColor(col);
        if(pos.m_dir != null)
        {
            g.fillTriangle(x, y, x + pos.dx1, y + pos.dy1, x + pos.dx, y + pos.dy);
            g.fillTriangle(x, y, x - pos.dy1, y + pos.dx1, x + pos.dx, y + pos.dy);
            g.setColor(0);
            g.drawLine(x, y, x + pos.dx1, y + pos.dy1);
            g.drawLine(x, y, x - pos.dy1, y + pos.dx1);
            g.drawLine(x + pos.dx, y + pos.dy, x - pos.dy1, y + pos.dx1);
            g.drawLine(x + pos.dx, y + pos.dy, x + pos.dx1, y + pos.dy1);
        } else
        {
            g.drawArc(x - 20, y - 20, 39, 39, 0, 360);
            g.drawArc(x - 20, y - 20, 40, 40, 0, 360);
        }
    }

    public void paintGPSPos(Graphics g, oneGPSPos pos, int inpx, int inpy, int w, int h, int zoom)
    {
        int x = w / 2 + (pos.px - inpx) / (1 << zoom);
        int y = h / 2 + (pos.py - inpy) / (1 << zoom);
        g.setColor(0xffffff);
        drawArrow(g, pos, x - 1, y + 2, 0);
        if(pos.isValid)
        {
            drawArrow(g, pos, x, y, 65280);
        } else
        {
            drawArrow(g, pos, x, y, 0x808080);
            drawInfo(g, "No valid positionning data", 10, 10, 0xff0000, 0xffffff);
        }
        if(pos.speed != null)
        {
            String speedstr = pos.speed.toShortString();
            g.setColor(0);
            Font oldF = g.getFont();
            g.setFont(fontb);
            g.drawString(speedstr, width, height / 2, 72);
            g.setColor(0xffffff);
            g.drawString(speedstr, width - 1, height / 2 + 1, 72);
            g.setFont(oldF);
        }
    }

    public void setLoc(oneGPSPos newLoc)
    {
        m_lastLocation = newLoc;
        BufferImage.extraInfo = null;
        if(newLoc.isValid)
        {
            if(m_gpsSegments == null)
            {
                m_gpsSegments = new int[200];
                m_gpsSegments[0] = -1;
                posInSeg = 0;
            }
            if(posInSeg >= 100)
            {
                System.arraycopy(m_gpsSegments, 2, m_gpsSegments, 0, 198);
                posInSeg--;
            }
            m_gpsSegments[posInSeg * 2] = newLoc.py;
            m_gpsSegments[posInSeg * 2 + 1] = newLoc.px;
            if(posInSeg + 1 < 100)
                m_gpsSegments[(posInSeg + 1) * 2] = -1;
            if(m_record && !m_pause)
                curSavedTrack.addRecord(newLoc);
            String cellID = System.getProperty("com.sonyericsson.net.cellid");
            String mcc = "";
            String mnc = "";
            String lac = "";
            if(cellID != null)
            {
                mcc = System.getProperty("com.sonyericsson.net.mcc");
                mnc = System.getProperty("com.sonyericsson.net.mnc");
                lac = System.getProperty("com.sonyericsson.net.lac");
            } else
            {
                cellID = System.getProperty("CellID");
                if(cellID != null)
                {
                    lac = System.getProperty("LocAreaCode");
                    String imsi = System.getProperty("IMSI");
                    mcc = imsi.substring(0, 3);
                    mnc = imsi.substring(3, 6);
                }
            }
            if(cellID != null)
                BufferImage.extraInfo = "&cellId=" + cellID + "&lac=" + lac + "&mcc=" + mcc + "&mnc=" + mnc + "&lat=" + UtilMidp.toString(newLoc.m_lat) + "&lon=" + UtilMidp.toString(newLoc.m_lon) + "&extra=" + id;
        }
        if(newLoc.stamp - lastGPSStamp > 1000L)
        {
            lastGPSStamp = newLoc.stamp;
            posInSeg++;
        }
        int dist = OneLoc.distFrom(px, py, newLoc.px, newLoc.py, zoom);
        if(m_autoTrack || dist < 20)
        {
            gotoLonLat(newLoc.m_lon, newLoc.m_lat, zoom, m_modeSat);
            m_autoTrack = true;
        }
        repaint();
    }

    public void saveRecords()
    {
        Track _tmp = curSavedTrack;
        setInfoOnScreen("Saving " + Track.currRecord + " datas...");
        curSavedTrack.saveTrack();
    }

    public void imageLoaded(BufferImage ima)
    {
        repaint();
    }

    public void displayTrack(Track track, boolean doRecenter)
    {
        clear();
        if(!isTrackDisplayed(track) && track.m_refreshType != 0)
            track.refreshTrack(this);
        m_listTrack.removeAllElements();
        m_segments = track.getTrack();
        listPlaces = track.getWaypoints();
        m_moreInfo = track.m_name;
        m_listTrack.addElement(track);
        if(doRecenter)
            recenterMapAroundSel();
        else
            repaint();
    }

    public boolean isTrackDisplayed(Track track)
    {
        for(Enumeration en = m_listTrack.elements(); en.hasMoreElements();)
            if(track == (Track)en.nextElement())
                return true;

        return false;
    }

    public void removeTrack(Track track)
    {
        clear();
    }

    public String locateURL(String theUrl)
    {
        theUrl = UtilMidp.strReplace(theUrl, "!lat!", getLat());
        theUrl = UtilMidp.strReplace(theUrl, "!lon!", getLon());
        theUrl = UtilMidp.strReplace(theUrl, "!alt!", getAlt());
        theUrl = UtilMidp.strReplace(theUrl, "!dir!", getDir());
        theUrl = UtilMidp.strReplace(theUrl, "!speed!", getSpeed());
        int px = getLonPx();
        int py = getLatPy();
        int wx = (width * (1 << getZoom()) * 9) / 10;
        int wy = (height * (1 << getZoom()) * 9) / 10;
        Float minLat = convLat(py - wy / 2);
        Float maxLat = convLat(py + wy / 2);
        if(minLat.Great(maxLat))
        {
            Float tmp = minLat;
            minLat = maxLat;
            maxLat = tmp;
        }
        theUrl = UtilMidp.strReplace(theUrl, "!minlon!", convLon(px - wx / 2));
        theUrl = UtilMidp.strReplace(theUrl, "!minlat!", minLat);
        theUrl = UtilMidp.strReplace(theUrl, "!maxlon!", convLon(px + wx / 2));
        theUrl = UtilMidp.strReplace(theUrl, "!maxlat!", maxLat);
        theUrl = UtilMidp.strReplace(theUrl, "!zoom!", 17 - zoom);
        theUrl = UtilMidp.strReplace(theUrl, "[bboxWest]", convLon(px - wx / 2));
        theUrl = UtilMidp.strReplace(theUrl, "[bboxSouth]", minLat);
        theUrl = UtilMidp.strReplace(theUrl, "[bboxEast]", convLon(px + wx / 2));
        theUrl = UtilMidp.strReplace(theUrl, "[bboxNorth]", maxLat);
        theUrl = UtilMidp.strReplace(theUrl, "[lookatLon]", getLon());
        theUrl = UtilMidp.strReplace(theUrl, "[lookatLat]", getLat());
        theUrl = UtilMidp.strReplace(theUrl, "[lookatTilt]", "0.0");
        theUrl = UtilMidp.strReplace(theUrl, "[lookatHeading]", "0.0");
        theUrl = UtilMidp.strReplace(theUrl, "[lookatRange]", 2000 * (1 << zoom));
        return theUrl;
    }

    protected int offx;
    protected int offy;
    protected int width;
    protected int height;
    Image ima;
    String toLoad;
    static Float F180 = new Float(180L);
    static Float F1 = new Float(1L);
    int datas[];
    int datad[];
    int array[];
    public int m_segments[];
    public int m_gpsSegments[];
    static final int MAX_GPS_SEGMENTS = 100;
    int posInSeg;
    long lastGPSStamp;
    public OneLoc currentSel;
    public Vector listPlaces;
    public Vector m_listMyPlaces;
    protected int px;
    protected int py;
    protected static final int size = 256;
    static int m_sizeScr = 128;
    protected static int sizeScr = 128;
    protected int zoom;
    private Font fontRef;
    public boolean m_modeSat;
    public boolean m_drawLon;
    public boolean m_displayCenterArrow;
    public boolean m_displaySize;
    public boolean m_useUSMetrics;
    public static final int SAT_GOOGLE = 0;
    public static final int SAT_MSN = 1;
    public static final int SAT_ASK = 2;
    public static final int SAT_YAHOO = 3;
    protected static int m_curSat = 0;
    static final int SIZE_INDICATOR = 20;
    private String zoomStr;
    private final Float miles = (new Float(0x188e83L)).Div(1000L);
    private String infoOnScreen;
    public oneGPSPos m_lastLocation;
    public boolean m_autoPositionningEnabeld;
    private int requestedZoom;
    private boolean zoomingMode;
    private int zpx;
    private int zpy;
    public boolean m_useResampledImages;
    private long lastZoomTimeStamp;
    private long infoTimeStamp;
    public OneLoc wayPoint;
    public boolean m_modeShortkey;
    public boolean m_autoTrack;
    public boolean m_record;
    public boolean m_pause;
    private static Font fonts = null;
    public static Font fontm = null;
    private static Font fontb = null;
    private static int fonth;
    private boolean m_fullScreen;
    public static final int ST_NORMAL = 0;
    public static final int ST_ZOOM = 1;
    public static final int ST_MOVE_PIN = 2;
    private Vector m_listTrack;
    private Vector m_tracks;
    public static int m_state = 0;
    public Track curSavedTrack;
    public String m_moreInfo;
    private static String maps[] = {
        "Google", "MSN", "Ask.com", "Yahoo"
    };
    public boolean m_drawConsumption;
    public int id;
    private MapCustomOverlay m_overlay;
    private ExtendedMenu extendedMenu;
    boolean isInit;
    boolean cont;
    protected String menus[] = {
        "Extended Menu:", "'1' Enable/Dis Lat/Lon", "'2' Enable Scale Bar", "'3' Center to GPS pos (GPS)", "'4' Record (GPS)", "'5' Pause", "'6' Do not use network"
    };
    static int sizeIcon = 20;
    static int posPlusIcon = 30;
    int dgx;
    int dgy;
    int offset[][];
    int oldpx;
    int oldpy;
    int oldzoom;
    long lastMove;
    Vector m_listeners;

}

⌨️ 快捷键说明

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