示例#1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Returns the point at the center of the rectangle.
         * @return the point at the center of the rectangle.
         */
        public GeoLatLng GetCenter()
        {
            GeoPoint pt1 = MapLayer.FromLatLngToPixel(GetSouthWest(), 15);
            GeoPoint pt2 = MapLayer.FromLatLngToPixel(GetNorthEast(), 15);
            GeoPoint pt  = new GeoPoint();

            pt.X = pt1.X + (pt2.X - pt1.X) / 2;
            pt.Y = pt1.Y + (pt2.Y - pt1.Y) / 2;
            return(MapLayer.FromPixelToLatLng(pt, 15));
        }
示例#2
0
        private void ProcessTileIndex()
        {
            while (!stopThread)
            {
                int newX = 0;
                int newY = 0;
                int newZ = 0;
                lock (_tileIndexList)
                {
                    if (_tileIndexList.Count > 0)
                    {
                        MapTileIndex mapTileIndex = _tileIndexList[_tileIndexList.Count - 1];
                        newX = mapTileIndex.XIndex;
                        newY = mapTileIndex.YIndex;
                        newZ = mapTileIndex.ZoomLevel;
                        _tileIndexList.Clear();
                    }
                    else
                    {
                        Thread.Sleep(5000);
                    }
                }
                if (newZ != 0)
                {
                    int       oldZoom = _rasterMap.GetZoom();
                    GeoLatLng latLng  = MapLayer.FromPixelToLatLng(new GeoPoint(newX * 256 + 128, newY * 256 + 128), newZ);
                    if (newZ != oldZoom)
                    {
                        _rasterMap.SetCenter(latLng, newZ);
                    }
                    else
                    {
                        GeoLatLng center = _rasterMap.GetCenter();
                        GeoPoint  pt1    = _rasterMap.FromLatLngToScreenPixel(center);

                        GeoPoint pt2 = _rasterMap.FromLatLngToScreenPixel(latLng);

                        _rasterMap.PanDirection((int)(pt1.X - pt2.X), (int)(pt1.Y - pt2.Y));
                    }
                }
            }
        }
示例#3
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Get the image at given X,Y zoom level.
         * @param X  X index of the map tile
         * @param Y  Y index of the map tile.
         * @param zoomLevel zoom level of the map tile
         * @return the given image.
         */
        public IImage GetImage(int x, int y, int zoomLevel)
        {
            MapDirection mapDirection = GetMapDirection();

            if (mapDirection != null)
            {
                try
                {
                    const int shiftWidth = 4;
                    GeoPoint  pt1        = new GeoPoint(x * MapLayer.MAP_TILE_WIDTH - shiftWidth,
                                                        y * MapLayer.MAP_TILE_WIDTH - shiftWidth);
                    GeoPoint pt2 = new GeoPoint((x + 1) * MapLayer.MAP_TILE_WIDTH + shiftWidth,
                                                (y + 1) * MapLayer.MAP_TILE_WIDTH + shiftWidth);
                    GeoLatLng       latLng1   = MapLayer.FromPixelToLatLng(pt1, zoomLevel);
                    GeoLatLng       latLng2   = MapLayer.FromPixelToLatLng(pt2, zoomLevel);
                    double          minY      = Math.Min(latLng1.Lat(), latLng2.Lat());
                    double          maxY      = Math.Max(latLng1.Lat(), latLng2.Lat());
                    double          minX      = Math.Min(latLng1.Lng(), latLng2.Lng());
                    double          maxX      = Math.Max(latLng1.Lng(), latLng2.Lng());
                    GeoLatLngBounds geoBounds = new GeoLatLngBounds(minX, minY,
                                                                    maxX - minX, maxY - minY);
                    GeoLatLng centerPt = geoBounds.GetCenter();
                    _mapDirectionLayer.SetCenter(centerPt, zoomLevel);
                    _mapDirectionLayer._screenBounds = geoBounds;
                    _mapTileGraphics.SetColor(TRANSPARENCY);
                    _mapTileGraphics.FillRect(0, 0, MapLayer.MAP_TILE_WIDTH,
                                              MapLayer.MAP_TILE_WIDTH);
                    _mapDirectionLayer.Paint(_mapTileGraphics);
                    IsImagevalid = true;
                    if (_readListener != null)
                    {
                        _readListener.readProgress(16, 16);
                    }
                    return(_mapTileImage.ModifyAlpha(160,
                                                     TRANSPARENCY));
                }
                catch (Exception)
                {
                }
            }
            return(null);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * @inheritDoc
         */
        public override void GetImage(int mtype, int x, int y, int zoomLevel)
        {
            lock (VectorMapAbstractCanvas.GRAPHICS_MUTEX)
            {
                int      shiftWidth = 32;
                GeoPoint pt1        = new GeoPoint(x * MapLayer.MAP_TILE_WIDTH - shiftWidth,
                                                   y * MapLayer.MAP_TILE_WIDTH - shiftWidth);
                GeoPoint pt2 = new GeoPoint((x + 1) * MapLayer.MAP_TILE_WIDTH + shiftWidth,
                                            (y + 1) * MapLayer.MAP_TILE_WIDTH + shiftWidth);
                GeoLatLng latLng1 = MapLayer.FromPixelToLatLng(pt1, zoomLevel);
                GeoLatLng latLng2 = MapLayer.FromPixelToLatLng(pt2, zoomLevel);
                double    minY    = Math.Min(latLng1.Lat(), latLng2.Lat());
                double    maxY    = Math.Max(latLng1.Lat(), latLng2.Lat());
                double    minX    = Math.Min(latLng1.Lng(), latLng2.Lng());
                double    maxX    = Math.Max(latLng1.Lng(), latLng2.Lng());
                double    width   = 0.00;
                double    height  = 0.00;

                //width = width < 0.06 ? 0.06 : width;
                //height = height < 0.06 ? 0.06 : height;

                GeoLatLngBounds geoBounds = new GeoLatLngBounds(minX - width / 2.0, minY - height / 2.0,
                                                                maxX - minX + width, maxY - minY + height);

                try
                {
                    Hashtable[] mapFeatures = _geoSet.Search(geoBounds);
                    int         totalSize   = 0;
                    for (int i = 0; i < mapFeatures.Length; i++)
                    {
                        Hashtable mapFeaturesInLayer = mapFeatures[i];
                        totalSize += mapFeaturesInLayer.Count;
                    }
                    totalSize += 1;
                    int mapObjectIndex = 0;
                    _vectorMapCanvas.ClearCanvas(0xffffff);

                    for (int i = 0; i < mapFeatures.Length; i++)
                    {
                        int             zOrder             = mapFeatures.Length - 1 - i;
                        Hashtable       mapFeaturesInLayer = mapFeatures[zOrder];
                        ICollection     enuKeys            = mapFeaturesInLayer.Keys;
                        MapFeatureLayer mapLayer           = _geoSet.GetMapFeatureLayer(zOrder);

                        foreach (var o in enuKeys)
                        {
                            int        mapInfoID  = (int)o;
                            MapFeature mapFeature = mapLayer
                                                    .GetMapFeatureByID(mapInfoID);
                            mapObjectIndex++;
                            _vectorMapCanvas.SetFont(GetFont(mapLayer.FontName));
                            _vectorMapCanvas.SetFontColor(mapLayer.FontColor);
                            _vectorMapCanvas.DrawMapObject(mapFeature.MapObject,
                                                           geoBounds, zoomLevel);
                            if (_readListener != null)
                            {
                                _readListener.readProgress(mapObjectIndex,
                                                           totalSize);
                            }
                        }
                    }
                    _vectorMapCanvas.DrawMapText();
                    ImageArray = PNGEncoder.GetPngrgb(MapLayer.MAP_TILE_WIDTH,
                                                      MapLayer.MAP_TILE_WIDTH,
                                                      _vectorMapCanvas.GetRGB());
                    ImageArraySize = ImageArray.Length;
                    IsImagevalid   = true;

                    if (ImageArraySize == 1933)
                    {
                        ImageArray     = null;
                        IsImagevalid   = false;
                        ImageArraySize = 0;
                    }


                    if (_readListener != null)
                    {
                        _readListener.readProgress(totalSize, totalSize);
                    }
                }
                catch (Exception e)
                {
                }
            }
        }