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

📄 mapcanvas.java

📁 j2me写的google地图
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2008-6-16 11:20:55
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MapCanvas.java

package com.eightmotions.map;

import com.eightmotions.util.UtilMidp;
import henson.midp.Float;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.*;

// Referenced classes of package com.eightmotions.map:
//            Track, OneLoc, MapCanvasListener, OneLocListener, 
//            BufferImageListener, ExtendedMenu, BufferImage, MapCustomOverlay, 
//            oneGPSPos

public class MapCanvas extends Canvas
    implements Runnable, OneLocListener, BufferImageListener, ExtendedMenu
{

    public MapCanvas()
    {
        offx = 0;
        offy = 0;
        ima = null;
        toLoad = null;
        datas = null;
        datad = null;
        array = null;
        m_segments = null;
        m_gpsSegments = null;
        posInSeg = 0;
        lastGPSStamp = 0L;
        currentSel = null;
        listPlaces = new Vector();
        m_listMyPlaces = new Vector();
        px = 0x800000;
        py = 0x800000;
        zoom = 17;
        m_modeSat = false;
        m_drawLon = false;
        m_displayCenterArrow = false;
        m_displaySize = true;
        m_useUSMetrics = false;
        zoomStr = "";
        infoOnScreen = null;
        m_lastLocation = null;
        requestedZoom = 0;
        zoomingMode = false;
        m_useResampledImages = true;
        lastZoomTimeStamp = 0L;
        infoTimeStamp = 0L;
        wayPoint = null;
        m_modeShortkey = false;
        m_autoTrack = true;
        m_record = false;
        m_pause = false;
        m_fullScreen = true;
        m_listTrack = new Vector();
        m_tracks = new Vector();
        curSavedTrack = null;
        m_moreInfo = null;
        m_drawConsumption = true;
        id = -1;
        m_overlay = null;
        isInit = false;
        cont = true;
        dgx = 0;
        dgy = 0;
        offset = new int[5][2];
        oldpx = -1;
        oldpy = -1;
        oldzoom = 0;
        lastMove = 0L;
        m_listeners = new Vector();
        setFullScreenMode(true);
        init();
    }

    public void setExtendedMenu(ExtendedMenu m)
    {
        extendedMenu = m;
    }

    public void init()
    {
        if(!isInit)
        {
            width = getWidth();
            height = getHeight();
            px = 0x1035280;
            py = 0xb02280;
            fontRef = Font.getFont(64, 0, 8);
            fonts = Font.getFont(64, 0, 8);
            fontm = Font.getFont(64, 0, 0);
            fontb = Font.getFont(64, 1, 16);
            OneLoc.m_defaultWidth = width / 2;
            OneLoc.m_defaultHeight = height / 3;
            BufferImage.setImageListener(this);
            BufferImage.initBuffer();
            Thread t = new Thread(this);
            t.start();
            isInit = true;
            setExtendedMenu(this);
            setInfoOnScreen("Use 1 and 3 to zoom/unzoom");
        }
    }

    public int getLonPx()
    {
        return px;
    }

    public int getLatPy()
    {
        return py;
    }

    public void setClipRect(int inMinx, int inMiny, int inWidth, int inHeight)
    {
        offx = inMinx;
        offy = inMiny;
        width = inWidth;
        height = inHeight;
    }

    public int getZoom()
    {
        return zoom;
    }

    public void setZoom(int inZoom)
    {
        if(inZoom < 0)
            inZoom = 0;
        if(inZoom > 17)
            inZoom = 17;
        if(inZoom != zoom)
        {
            zoom = inZoom;
            zoomStr = "Zoom:" + (17 - zoom);
            BufferImage.cleanBuffer();
            requestedZoom = zoom;
        }
        zoomingMode = false;
    }

    public int getBufferSize()
    {
        return BufferImage.m_nbIma;
    }

    public void setTileSize(int inSize)
    {
        m_sizeScr = inSize;
        setModeProxy(true);
    }

    public void setModeProxy(boolean useProxy)
    {
        BufferImage.m_useProxy = useProxy;
        if(useProxy)
        {
            sizeScr = m_sizeScr;
            BufferImage.m_modePacked = true;
        } else
        {
            sizeScr = 256;
            BufferImage.m_modePacked = false;
        }
        setBufferSize(BufferImage.m_nbIma);
    }

    public boolean getModeProxy()
    {
        return BufferImage.m_useProxy;
    }

    public void setBufferSize(int inSize)
    {
        int nbVis = (width / sizeScr + 2) * (height / sizeScr + 2) * 2;
        if(UtilMidp.DEBUG)
            System.out.println("Set buffer size:" + inSize + " Nb Vis:" + nbVis);
        if(nbVis > inSize)
            inSize = nbVis;
        BufferImage.setBufferSize(inSize);
        if(!BufferImage.m_useRMS)
            BufferImage.setVisibleSize(inSize);
        else
            BufferImage.setVisibleSize(nbVis);
    }

    public void setOverlay(MapCustomOverlay inOverlay)
    {
        m_overlay = inOverlay;
    }

    public MapCustomOverlay getOverlay()
    {
        return m_overlay;
    }

    public void run()
    {
        for(cont = true; cont;)
            try
            {
                Thread.sleep(1000L);
                if(infoTimeStamp != 0L && System.currentTimeMillis() - infoTimeStamp > 1000L)
                {
                    infoTimeStamp = 0L;
                    infoOnScreen = null;
                    repaint();
                }
                if(lastZoomTimeStamp != 0L && System.currentTimeMillis() - lastZoomTimeStamp > 1000L)
                {
                    lastZoomTimeStamp = 0L;
                    if(requestedZoom != zoom)
                        setZoom(requestedZoom);
                    repaint();
                }
                checkMove();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

    }

    public void stop()
    {
        BufferImage.stop();
        cont = false;
    }

    public void clear()
    {
        listPlaces = new Vector();
        m_segments = null;
        m_gpsSegments = null;
        wayPoint = null;
        m_moreInfo = null;
    }

    public OneLoc getSelectedItem(Graphics g, int inpx, int inpy, int zoom, int dist, boolean onlyRepaint)
    {
        OneLoc sel = null;
        if(currentSel != null)
        {
            int dist2 = currentSel.distFrom(inpx, inpy, zoom);
            if(dist2 < dist)
            {
                sel = currentSel;
                dist = dist2;
            }
        }
        for(Enumeration en = m_listTrack.elements(); en.hasMoreElements();)
        {
            Track tr = (Track)en.nextElement();
            Enumeration e = tr.getWaypoints().elements();
            while(e.hasMoreElements()) 
            {
                OneLoc elem = (OneLoc)e.nextElement();
                if(elem.m_theListener == null)
                    elem.setListener(this);
                if(g != null)
                    elem.paint(g, this);
                if(!onlyRepaint)
                {
                    int ldist = elem.distFrom(inpx, inpy, zoom);
                    if(ldist < dist)
                    {
                        dist = ldist;
                        sel = elem;
                    }
                }
            }
        }

        Enumeration e = m_listMyPlaces.elements();
        do
        {
            if(!e.hasMoreElements())
                break;
            OneLoc elem = (OneLoc)e.nextElement();
            if(elem.m_theListener == null)
                elem.setListener(this);
            if(g != null)
                elem.paint(g, px, py, offx, offy, width, height, zoom);
            if(!onlyRepaint)
            {
                int ldist = elem.distFrom(inpx, inpy, zoom);
                if(ldist < dist)
                {
                    dist = ldist;
                    sel = elem;
                }
            }
        } while(true);
        if(onlyRepaint)
            sel = currentSel;
        return sel;
    }

    public void sizeChanged(int w, int h)
    {
        width = w;
        height = h;
    }

    public void paint(Graphics g)
    {
        int oldClipX = g.getClipX();
        int oldClipY = g.getClipY();
        int oldWidth = g.getClipWidth();
        int oldHeight = g.getClipHeight();
        g.setClip(offx, offy, width, height);
        if(zoom == 17)
        {
            g.setColor(0);
            g.fillRect(offx, offy, width, height);
        }
        fonth = g.getFont().getHeight();
        int bottomLeft = height - fonth - fonth - 10;
        int div = 1 << zoom;
        int lpx = px / div - width / 2;
        int lpy = py / div - height / 2;
        int starty = offy - lpy % sizeScr;
        int celly = lpy;
        do
        {
            int startx = offx - lpx % sizeScr;
            int cellx = lpx;
            do
            {
                int tmpSat = m_curSat;
                BufferImage.m_customOverlay = m_overlay;
                if(m_overlay == null || m_overlay.isTransparent())
                    drawSquare(g, startx, starty, cellx, celly, zoom, false);
                if(m_overlay != null)
                {
                    m_curSat = 4;
                    drawSquare(g, startx, starty, cellx, celly, zoom, true);
                }
                m_curSat = tmpSat;
                startx += sizeScr;
                cellx += sizeScr;
            } while(startx < width);
            starty += sizeScr;
            celly += sizeScr;
        } while(starty < height);
        int dist = 20;
        if(m_displayCenterArrow)
        {
            g.setColor(0xff0000);
            g.drawRect((offx + width / 2) - dist / 2, (offy + height / 2) - dist / 2, dist, dist);
        }
        g.setFont(fontm);
        if(!BufferImage.m_doNotUseNetwork)
        {
            int toLoad = BufferImage.getPending();
            if(toLoad > 0)
            {
                String disp = " To load:" + toLoad;
                drawString(g, disp, 10 + offx, 1 + offy);
            }
        } else
        {
            drawString(g, "Network disabled", 10 + offx, 1 + offy);
        }
        int tmpy = offy + 1 + fonth + 2;
        drawString(g, zoomStr, 10 + offx, tmpy);
        tmpy += fonth + 1;
        if(m_drawLon)
        {
            drawString(g, "Lon:" + getCoordAsString(true, getLon(), true), offx, tmpy);
            tmpy += fonth + 1;
            drawString(g, "Lat:" + getCoordAsString(false, getLat(), true), offy, tmpy);
            tmpy += fonth + 1;
        }
        Enumeration en = m_listTrack.elements();
        do
        {
            if(!en.hasMoreElements())
                break;
            Track tr = (Track)en.nextElement();
            int seg[] = tr.getTrack();
            if(seg != null)

⌨️ 快捷键说明

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