////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 14JAN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * constructor.
  * @param clipRect
  * 	clip region
  */
 public SutherlandHodgman(GeoLatLngBounds clipRect)
 {
     _stageOut = new OutputStage();
     _stageBottom = new ClipStage(_stageOut, 3, (clipRect.Y + clipRect.Height));
     _stageLeft = new ClipStage(_stageBottom, 4, clipRect.X);
     _stageTop = new ClipStage(_stageLeft, 1, clipRect.Y);
     _stageRight = new ClipStage(_stageTop, 2, (clipRect.X + clipRect.Width));
     _rectBounds = new GeoLatLngBounds(clipRect);
 }
Example #2
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Creates a polygon from an array of vertices.  The weight is the Width of
         * the line in pixels. The opacity is given as a number between 0 and 1.
         * The line will be antialiased and semitransparent.
         * @param _latlngs array of points.
         * @param _strokeColor the color of the polygon stroke.
         * @param _strokeWeight the Width of the polygon stroke.
         * @param _strokeOpacity the opacity of the polygon stroke.
         * @param _fillColor the inner color of the polygon.
         * @param _fillOpacity the inner opacity of the polygon.
         */
        public GeoPolygon(GeoLatLng[] latlngs, int strokeColor, int strokeWeight,
                          double strokeOpacity, int fillColor, double fillOpacity)
        {
            if (latlngs != null)
            {
                _latlngs = new GeoLatLng[latlngs.Length];
                Array.Copy(latlngs, 0, _latlngs, 0, latlngs.Length);
                _levels = new int[latlngs.Length];
                for (int i = 0; i < _levels.Length; i++)
                {
                    _levels[i] = 0;
                }
                double      maxlat = 0, minlat = 0, maxlon = 0, minlon = 0;
                GeoLatLng[] points = _latlngs;
                for (int i = 0; i < points.Length; i++)
                {
                    // determin _bounds (Max/Min Lat/lon)
                    if (i == 0)
                    {
                        maxlat = minlat = points[i].Lat();
                        maxlon = minlon = points[i].Lng();
                    }
                    else
                    {
                        if (points[i].Lat() > maxlat)
                        {
                            maxlat = points[i].Lat();
                        }
                        else if (points[i].Lat() < minlat)
                        {
                            minlat = points[i].Lat();
                        }
                        else if (points[i].Lng() > maxlon)
                        {
                            maxlon = points[i].Lng();
                        }
                        else if (points[i].Lng() < minlon)
                        {
                            minlon = points[i].Lng();
                        }
                    }
                }
                GeoLatLng sw, ne;
                sw      = new GeoLatLng(minlat, minlon);
                ne      = new GeoLatLng(maxlat, maxlon);
                _bounds = new GeoLatLngBounds(sw, ne);
            }
            _strokeColor   = strokeColor;
            _strokeOpacity = strokeOpacity;
            _strokeWeight  = strokeWeight;
            _fillColor     = fillColor;
            _fillOpacity   = fillOpacity;
            _zoomFactor    = 1;
            _numLevels     = 0;
            _visible       = true;
        }
Example #3
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Creates a polyline from an array of vertices.  The _weight is the Width of
         * the line in pixels. The _opacity is given as a number between 0 and 1.
         * The line will be antialiased and semitransparent.
         * @param _latlngs array of points.
         * @param _color the _color of the polyline.
         * @param _weight the Width of the polyline.
         * @param _opacity the _opacity of the polyline.
         */
        public GeoPolyline(GeoLatLng[] latlngs, int color, int weight,
                           double opacity)
        {
            if (latlngs != null)
            {
                _latlngs = new GeoLatLng[latlngs.Length];
                Array.Copy(latlngs, 0, _latlngs, 0, latlngs.Length);
                _levels = new int[latlngs.Length];
                for (int i = 0; i < _levels.Length; i++)
                {
                    _levels[i] = 0;
                }
                double      maxlat = 0, minlat = 0, maxlon = 0, minlon = 0;
                GeoLatLng[] points = _latlngs;
                for (int i = 0; i < points.Length; i++)
                {
                    // determin bounds (Max/Min Lat/lon)
                    if (i == 0)
                    {
                        maxlat = minlat = points[i].Lat();
                        maxlon = minlon = points[i].Lng();
                    }
                    else
                    {
                        if (points[i].Lat() > maxlat)
                        {
                            maxlat = points[i].Lat();
                        }
                        else if (points[i].Lat() < minlat)
                        {
                            minlat = points[i].Lat();
                        }
                        else if (points[i].Lng() > maxlon)
                        {
                            maxlon = points[i].Lng();
                        }
                        else if (points[i].Lng() < minlon)
                        {
                            minlon = points[i].Lng();
                        }
                    }
                }
                GeoLatLng sw = new GeoLatLng(minlat, minlon);
                GeoLatLng ne = new GeoLatLng(maxlat, maxlon);
                _bounds = new GeoLatLngBounds(sw, ne);
            }
            _color     = color;
            _weight    = weight;
            _opacity   = opacity;
            ZoomFactor = 1;
            NumLevels  = 0;
            _visible   = true;
        }
Example #4
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * copy constructor.
         * @param pline pline object copied from.
         */
        public GeoPolyline(GeoPolyline pline)
        {
            if (pline._latlngs != null)
            {
                _latlngs = new GeoLatLng[pline._latlngs.Length];
                Array.Copy(_latlngs, 0, _latlngs, 0, _latlngs.Length);
                _levels = new int[pline._levels.Length];
                for (int i = 0; i < _levels.Length; i++)
                {
                    _levels[i] = pline._levels[i];
                }
                _bounds = new GeoLatLngBounds(pline._bounds);
            }
            _color     = pline._color;
            _weight    = pline._weight;
            _opacity   = pline._opacity;
            ZoomFactor = pline.ZoomFactor;
            NumLevels  = pline.NumLevels;
            _visible   = pline._visible;
        }
Example #5
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * copy constructor.
         * @param polygon polygon object copied from.
         */
        public GeoPolygon(GeoPolygon polygon)
        {
            if (polygon._latlngs != null)
            {
                _latlngs = new GeoLatLng[polygon._latlngs.Length];
                Array.Copy(_latlngs, 0, _latlngs, 0, _latlngs.Length);
                _levels = new int[polygon._levels.Length];
                for (int i = 0; i < _levels.Length; i++)
                {
                    _levels[i] = polygon._levels[i];
                }
                _bounds = new GeoLatLngBounds(polygon._bounds);
            }
            _strokeColor   = polygon._strokeColor;
            _strokeOpacity = polygon._strokeOpacity;
            _strokeWeight  = polygon._strokeWeight;
            _fillColor     = polygon._fillColor;
            _fillOpacity   = polygon._fillOpacity;
            _zoomFactor    = polygon._zoomFactor;
            _numLevels     = polygon._numLevels;
            _visible       = polygon._visible;
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * draw a map object.
         * @param mapObject the map object to be drawing.
         * @param drawBoundary the drawing boundry.
         * @param zoomLevel the current zoomLevel.
         */
        public override void DrawMapObject(MapObject mapObject, GeoLatLngBounds drawBoundary,
                int zoomLevel)
        {
            GeoLatLng drawPt = new GeoLatLng();
            _sutherlandHodgman = new SutherlandHodgman(drawBoundary);
            _mapZoomLevel = zoomLevel;
            _mapCenterPt.X = drawBoundary.GetCenterX();
            _mapCenterPt.Y = drawBoundary.GetCenterY();
            bool pointFound = false;
            switch (mapObject.GetMapObjectType())
            {
                case MapObject.NONE:
                    break;
                case MapObject.POINT:
                    {
                        MapPoint mapPoint = (MapPoint)mapObject;
                        DrawPoint(mapPoint);
                        drawPt.X = mapPoint.Point.X;
                        drawPt.Y = mapPoint.Point.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIPOINT:
                    {
                        MapMultiPoint mapMultiPoint = (MapMultiPoint)mapObject;
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            MapPoint mapPoint = new MapPoint
                                                    {
                                                        SymbolType = mapMultiPoint.SymbolType,
                                                        Point = new GeoLatLng(mapMultiPoint.Points[i])
                                                    };
                            DrawPoint(mapPoint);
                        }
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            if (drawBoundary.Contains(mapMultiPoint.Points[i]))
                            {
                                drawPt.X = mapMultiPoint.Points[i].X;
                                drawPt.Y = mapMultiPoint.Points[i].Y;
                                pointFound = true;
                                break;
                            }
                        }

                    }
                    break;
                case MapObject.PLINE:
                    {
                        MapPline mapPline = (MapPline)mapObject;
                        DrawPline(mapPline.PenStyle, mapPline.Pline);
                        for (int i = 0; i < mapPline.Pline.GetVertexCount(); i++)
                        {
                            if (drawBoundary.Contains(mapPline.Pline.GetVertex(i)))
                            {
                                drawPt.X = mapPline.Pline.GetVertex(i).X;
                                drawPt.Y = mapPline.Pline.GetVertex(i).Y;
                                pointFound = true;
                                break;
                            }
                        }
                    }
                    break;
                case MapObject.MULTIPLINE:
                    {
                        MapMultiPline mapMultiPline = (MapMultiPline)mapObject;
                        for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                        {
                            DrawPline(mapMultiPline.PenStyle,
                                    mapMultiPline.Plines[i]);
                            for (int j = 0; j < mapMultiPline.Plines[i].GetVertexCount(); j++)
                            {
                                if (drawBoundary.Contains(mapMultiPline.Plines[i].GetVertex(j)))
                                {
                                    drawPt.X = mapMultiPline.Plines[i].GetVertex(j).X;
                                    drawPt.Y = mapMultiPline.Plines[i].GetVertex(j).Y;
                                    pointFound = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case MapObject.REGION:
                    {
                        MapRegion mapRegion = (MapRegion)mapObject;
                        DrawRegion(mapRegion.PenStyle, mapRegion.BrushStyle,
                                mapRegion.Region);
                        drawPt.X = mapRegion.CenterPt.X;
                        drawPt.Y = mapRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIREGION:
                    {
                        MapMultiRegion mapMultiRegion = (MapMultiRegion)mapObject;
                        for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                        {
                            DrawRegion(mapMultiRegion.PenStyle,
                                    mapMultiRegion.BrushStyle,
                                    mapMultiRegion.Regions[i]);

                        }
                        drawPt.X = mapMultiRegion.CenterPt.X;
                        drawPt.Y = mapMultiRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.COLLECTION:
                    {
                        MapCollection mapCollection = (MapCollection)mapObject;
                        if (mapCollection.MultiRegion != null)
                        {
                            MapMultiRegion mapMultiRegion = mapCollection.MultiRegion;
                            for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                            {
                                DrawRegion(mapMultiRegion.PenStyle,
                                        mapMultiRegion.BrushStyle,
                                        mapMultiRegion.Regions[i]);
                            }
                        }
                        if (mapCollection.MultiPline != null)
                        {
                            MapMultiPline mapMultiPline = mapCollection.MultiPline;
                            for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                            {
                                DrawPline(mapMultiPline.PenStyle,
                                        mapMultiPline.Plines[i]);
                            }
                        }
                        if (mapCollection.MultiPoint != null)
                        {
                            MapMultiPoint mapMultiPoint = mapCollection.MultiPoint;
                            for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                            {
                                MapPoint mapPoint = new MapPoint
                                                        {
                                                            SymbolType = mapMultiPoint.SymbolType,
                                                            Point = new GeoLatLng(mapMultiPoint.Points[i])
                                                        };
                                DrawPoint(mapPoint);
                            }
                        }
                        pointFound = true;
                        drawPt.X = mapCollection.Bounds.X + mapCollection.Bounds.Width / 2;
                        drawPt.Y = mapCollection.Bounds.Y + mapCollection.Bounds.Height / 2;

                    }
                    break;
                case MapObject.TEXT:
                    {
                        MapText mapText = (MapText)mapObject;
                        drawPt.X = mapText.Point.X;
                        drawPt.Y = mapText.Point.Y;
                        pointFound = true;
                    }
                    break;
            }
            if (!mapObject.Name.ToLower().Equals("unknown") && pointFound)
            {
                MapText mapName = new MapText {Font = _font};
                mapName.SetForeColor(_fontColor);
                mapName.TextString = mapObject.Name;
                GeoPoint screenPt = FromLatLngToMapPixel(drawPt);
                mapName.Point.X = screenPt.X;
                mapName.Point.Y = screenPt.Y;
                mapName.Bounds.X = mapName.Point.X;
                mapName.Bounds.Y = mapName.Point.Y;
                if (_font != null)
                {
                    mapName.Bounds.Height = IMAGE_PATERN_WIDTH;
                    mapName.Bounds.Width = _font.CharsWidth(mapObject.Name.ToCharArray(), 0,
                            mapObject.Name.ToCharArray().Length);

                }
                AddMapName(mapName);

            }
        }
 public abstract void DrawMapObject(MapObject mapObject, GeoLatLngBounds drawBoundary,
                           int zoomLevel);
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 21JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Open the map layer.
  */
 public void Open()
 {
     if (!_opened)
     {
         _opened = true;
         _mapFile.Open();
         DataTable = new DataTable(_mapFile.TabularData, _mapFile.Header.Fields,
                 _mapFile.Header.RecordCount);
         int foundName = -1;
         for (int i = 0; i < _mapFile.Header.Fields.Length; i++)
         {
             KeyField = _mapFile.Header.Fields[i];
             if (KeyField.GetName().ToLower().StartsWith("name"))
             {
                 foundName = i;
                 _keyFieldIndex = i;
                 break;
             }
         }
         if (foundName == -1)
         {
             for (int i = 0; i < _mapFile.Header.Fields.Length; i++)
             {
                 KeyField = _mapFile.Header.Fields[i];
                 if (KeyField.GetFieldType() == DataField.TYPE_CHAR)
                 {
                     foundName = i;
                     _keyFieldIndex = i;
                     break;
                 }
             }
         }
         if (foundName == -1)
         {
             KeyField = _mapFile.Header.Fields[0];
             _keyFieldIndex = 0;
         }
         if (_mapFile.Header.DominantType.ToUpper().Equals("POINT"))
         {
             PredominantFeatureType = FEATURE_TYPE_POINT;
         }
         else if (_mapFile.Header.DominantType.ToUpper().Equals("PLINE"))
         {
             PredominantFeatureType = FEATURE_TYPE_PLINE;
         }
         else
         {
             PredominantFeatureType = FEATURE_TYPE_REGION;
         }
         Bounds = _mapFile.Header.MapBounds;
     }
 }
Example #9
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 20JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Open the map file.
         * @throws IOException
         */
        public void Open()
        {
            if (_opened)
            {
                return;
            }

            _opened = true;
            DataReader.Seek(_reader, 0);
            DataReader.ReadString(_reader);
            DataReader.Seek(_reader, 16);
            DataReader.ReadString(_reader);

            DataReader.Seek(_reader, 32);
            string mapTile = DataReader.ReadString(_reader);
            if (!mapTile.ToUpper().Equals("TILE"))
            {
                throw new IOException("Invalid map format!");
            }
            DataReader.Seek(_reader, 48);
            MapType = DataReader.ReadInt(_reader);
            int numOfLevel = DataReader.ReadInt(_reader);
            double minY = DataReader.ReadDouble(_reader);
            double minX = DataReader.ReadDouble(_reader);
            double maxY = DataReader.ReadDouble(_reader);
            double maxX = DataReader.ReadDouble(_reader);
            Bounds = new GeoLatLngBounds(minX, minY, maxX - minX, maxY - minY);
            DataReader.Seek(_reader, HEADSIZE);
            _levelInfos = new LevelInfo[numOfLevel];
            for (int i = 0; i < numOfLevel; i++)
            {
                _levelInfos[i] = new LevelInfo
                                    {
                                        LevelNo = DataReader.ReadInt(_reader),
                                        MinX = DataReader.ReadInt(_reader),
                                        MinY = DataReader.ReadInt(_reader),
                                        MaxX = DataReader.ReadInt(_reader),
                                        MaxY = DataReader.ReadInt(_reader),
                                        Offset = DataReader.ReadInt(_reader),
                                        Length = DataReader.ReadInt(_reader)
                                    };
            }
        }
Example #10
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Creates a polyline from an array of vertices.  The _weight is the Width of
         * the line in pixels. The _opacity is given as a number between 0 and 1.
         * The line will be antialiased and semitransparent.
         * @param _latlngs array of points.
         * @param _color the _color of the polyline.
         * @param _weight the Width of the polyline.
         * @param _opacity the _opacity of the polyline.
         */
        public GeoPolyline(GeoLatLng[] latlngs, int color, int weight,
                double opacity)
        {
            if (latlngs != null)
            {
                _latlngs = new GeoLatLng[latlngs.Length];
                Array.Copy(latlngs, 0, _latlngs, 0, latlngs.Length);
                _levels = new int[latlngs.Length];
                for (int i = 0; i < _levels.Length; i++)
                {
                    _levels[i] = 0;
                }
                double maxlat = 0, minlat = 0, maxlon = 0, minlon = 0;
                GeoLatLng[] points = _latlngs;
                for (int i = 0; i < points.Length; i++)
                {

                    // determin bounds (Max/Min Lat/lon)
                    if (i == 0)
                    {
                        maxlat = minlat = points[i].Lat();
                        maxlon = minlon = points[i].Lng();
                    }
                    else
                    {
                        if (points[i].Lat() > maxlat)
                        {
                            maxlat = points[i].Lat();
                        }
                        else if (points[i].Lat() < minlat)
                        {
                            minlat = points[i].Lat();
                        }
                        else if (points[i].Lng() > maxlon)
                        {
                            maxlon = points[i].Lng();
                        }
                        else if (points[i].Lng() < minlon)
                        {
                            minlon = points[i].Lng();
                        }
                    }
                }
                GeoLatLng sw = new GeoLatLng(minlat, minlon);
                GeoLatLng ne = new GeoLatLng(maxlat, maxlon);
                _bounds = new GeoLatLngBounds(sw, ne);
            }
            _color = color;
            _weight = weight;
            _opacity = opacity;
            ZoomFactor = 1;
            NumLevels = 0;
            _visible = true;
        }
Example #11
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * get all records based on given rectangle.
         * @param rectGeo the boundary..
         * @return a hashtable array Contains of all matched record.
         *  the key is the mapInfo ID. the value is the MBR of map object.
         * @
         */
        public Hashtable[] Search(GeoLatLngBounds rectGeo)
        {
            lock (_mapFeatureLayers)
            {
                Hashtable[] retTable = new Hashtable[_mapFeatureLayers.Count];
                GeoLatLng pt1 = new GeoLatLng(rectGeo.Y, rectGeo.X);
                GeoLatLng pt2 = new GeoLatLng(rectGeo.Y + rectGeo.Height,
                        rectGeo.X + rectGeo.Width);
                double distance = GeoLatLng.Distance(pt1, pt2);

                if (_mapUnit == MAPUNIT_MILE)
                {
                    distance /= 1.632;
                }

                for (int i = 0; i < _mapFeatureLayers.Count; i++)
                {
                    MapFeatureLayer mapLayer = (MapFeatureLayer)_mapFeatureLayers[i];
                    if (mapLayer.CanBeShown(distance))
                    {
                        retTable[i] = mapLayer.Search(rectGeo);
                    }
                    else
                    {
                        retTable[i] = new Hashtable();
                    }
                }
                return retTable;
            }
        }
Example #12
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Open the map.
         * @
         */
        public void Open()
        {
            lock (_mapFeatureLayers)
            {
                int layerCount = _mapFeatureLayers.Count;

                if (layerCount > 0)
                {
                    ((MapFeatureLayer)_mapFeatureLayers[0]).Open();
                    _bounds = ((MapFeatureLayer)_mapFeatureLayers[0]).Bounds;
                }
                else
                {
                    _bounds = new GeoLatLngBounds();
                }

                for (int i = 1; i < layerCount; i++)
                {
                    MapFeatureLayer mapLayer = (MapFeatureLayer)_mapFeatureLayers[i];
                    mapLayer.Open();
                    GeoBounds.Union(mapLayer.Bounds, _bounds, _bounds);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * draw a map object.
         * @param mapObject the map object to be drawing.
         * @param drawBoundary the drawing boundry.
         * @param zoomLevel the current zoomLevel.
         */
        public override void DrawMapObject(MapObject mapObject, GeoLatLngBounds drawBoundary,
                int zoomLevel)
        {
            GeoLatLng drawPt = new GeoLatLng();
            _sutherlandHodgman = new SutherlandHodgman(drawBoundary);
            _mapZoomLevel = zoomLevel;
            _mapCenterPt.X = drawBoundary.GetCenterX();
            _mapCenterPt.Y = drawBoundary.GetCenterY();
            bool pointFound = false;
            Point[] plinePoints=null;
            switch (mapObject.GetMapObjectType())
            {
                case MapObject.NONE:
                    break;
                case MapObject.POINT:
                    {
                        MapPoint mapPoint = (MapPoint)mapObject;
                        DrawPoint(mapPoint);
                        drawPt.X = mapPoint.Point.X;
                        drawPt.Y = mapPoint.Point.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIPOINT:
                    {
                        MapMultiPoint mapMultiPoint = (MapMultiPoint)mapObject;
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            MapPoint mapPoint = new MapPoint
                            {
                                SymbolType = mapMultiPoint.SymbolType,
                                Point = new GeoLatLng(mapMultiPoint.Points[i])
                            };
                            DrawPoint(mapPoint);
                        }
                        for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                        {
                            if (drawBoundary.Contains(mapMultiPoint.Points[i]))
                            {
                                drawPt.X = mapMultiPoint.Points[i].X;
                                drawPt.Y = mapMultiPoint.Points[i].Y;
                                pointFound = true;
                                break;
                            }
                        }

                    }
                    break;
                case MapObject.PLINE:
                    {
                        MapPline mapPline = (MapPline)mapObject;
                        plinePoints=DrawPline(mapPline.PenStyle, mapPline.Pline);
                        for (int i = 0; i < mapPline.Pline.GetVertexCount(); i++)
                        {
                            if (drawBoundary.Contains(mapPline.Pline.GetVertex(i)))
                            {
                                drawPt.X = mapPline.Pline.GetVertex(i).X;
                                drawPt.Y = mapPline.Pline.GetVertex(i).Y;
                                pointFound = true;
                                break;
                            }
                        }
                    }
                    break;
                case MapObject.MULTIPLINE:
                    {
                        MapMultiPline mapMultiPline = (MapMultiPline)mapObject;
                        for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                        {
                            DrawPline(mapMultiPline.PenStyle,
                                    mapMultiPline.Plines[i]);
                            for (int j = 0; j < mapMultiPline.Plines[i].GetVertexCount(); j++)
                            {
                                if (drawBoundary.Contains(mapMultiPline.Plines[i].GetVertex(j)))
                                {
                                    drawPt.X = mapMultiPline.Plines[i].GetVertex(j).X;
                                    drawPt.Y = mapMultiPline.Plines[i].GetVertex(j).Y;
                                    pointFound = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case MapObject.REGION:
                    {
                        MapRegion mapRegion = (MapRegion)mapObject;
                        DrawRegion(mapRegion.PenStyle, mapRegion.BrushStyle,
                                mapRegion.Region);
                        drawPt.X = mapRegion.CenterPt.X;
                        drawPt.Y = mapRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.MULTIREGION:
                    {
                        MapMultiRegion mapMultiRegion = (MapMultiRegion)mapObject;
                        for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                        {
                            DrawRegion(mapMultiRegion.PenStyle,
                                    mapMultiRegion.BrushStyle,
                                    mapMultiRegion.Regions[i]);

                        }
                        drawPt.X = mapMultiRegion.CenterPt.X;
                        drawPt.Y = mapMultiRegion.CenterPt.Y;
                        pointFound = true;
                    }
                    break;
                case MapObject.COLLECTION:
                    {
                        MapCollection mapCollection = (MapCollection)mapObject;
                        if (mapCollection.MultiRegion != null)
                        {
                            MapMultiRegion mapMultiRegion = mapCollection.MultiRegion;
                            for (int i = 0; i < mapMultiRegion.Regions.Length; i++)
                            {
                                DrawRegion(mapMultiRegion.PenStyle,
                                        mapMultiRegion.BrushStyle,
                                        mapMultiRegion.Regions[i]);
                            }
                        }
                        if (mapCollection.MultiPline != null)
                        {
                            MapMultiPline mapMultiPline = mapCollection.MultiPline;
                            for (int i = 0; i < mapMultiPline.Plines.Length; i++)
                            {
                                DrawPline(mapMultiPline.PenStyle,
                                        mapMultiPline.Plines[i]);
                            }
                        }
                        if (mapCollection.MultiPoint != null)
                        {
                            MapMultiPoint mapMultiPoint = mapCollection.MultiPoint;
                            for (int i = 0; i < mapMultiPoint.Points.Length; i++)
                            {
                                MapPoint mapPoint = new MapPoint
                                {
                                    SymbolType = mapMultiPoint.SymbolType,
                                    Point = new GeoLatLng(mapMultiPoint.Points[i])
                                };
                                DrawPoint(mapPoint);
                            }
                        }
                        pointFound = true;
                        drawPt.X = mapCollection.Bounds.X + mapCollection.Bounds.Width / 2;
                        drawPt.Y = mapCollection.Bounds.Y + mapCollection.Bounds.Height / 2;

                    }
                    break;
                case MapObject.TEXT:
                    {
                        MapText mapText = (MapText)mapObject;
                        drawPt.X = mapText.Point.X;
                        drawPt.Y = mapText.Point.Y;
                        pointFound = true;
                    }
                    break;
            }
            if (!(mapObject.Name.ToLower().Equals("unknown") || mapObject.Name.Length==0) && pointFound)
            {
                MapText mapName = new MapText { Font = _font };
                mapName.SetForeColor(_fontColor);
                mapName.TextString = mapObject.Name;
                GeoPoint screenPt = FromLatLngToMapPixel(drawPt);
                mapName.Point.X = screenPt.X;
                mapName.Point.Y = screenPt.Y;
                mapName.Bounds.X = mapName.Point.X;
                mapName.Bounds.Y = mapName.Point.Y;
                Font font = null;
                if (_font != null)
                {

                    font = (Font)_font.GetNativeFont();
                    SizeF sizeF = SharedGraphics2D.Graphics.MeasureString(mapName.TextString, font);
                    mapName.Bounds.Height = sizeF.Height;
                    mapName.Bounds.Width = sizeF.Width;

                }
                TextPosInfo textPosInfo = new TextPosInfo();
                textPosInfo._mapText = mapName;
                if(mapObject.GetMapObjectType()==MapObject.PLINE)
                {
                    if(plinePoints!=null)
                    {
                        GraphicsPath graphicsPath = new GraphicsPath();
                        graphicsPath.AddLines(plinePoints);
                        RectangleF []rectangleF;
                        double angle = GetAngle(plinePoints[0], plinePoints[plinePoints.Length - 1]);
                        if (angle < 180)
                        {
                            graphicsPath.Reverse();
                        }
                        angle = GetAngle(plinePoints[0], plinePoints[plinePoints.Length - 1]);

                        float rotateAngle = GetRotateAngle(angle);
                        rectangleF = SharedGraphics2D.Graphics.MeasureString(mapName.TextString, font,
                                                                                new SolidBrush(
                                                                                    Color.FromArgb(_fontColor)),
                                                                                TextPathAlign.Center,
                                                                                TextPathPosition.CenterPath, 100, rotateAngle,
                                                                                graphicsPath);

                        textPosInfo._graphicsPath = graphicsPath;
                        textPosInfo._rectangles = rectangleF;

                        if (rectangleF.Length == mapName.TextString.Length)
                        {

                            //RectangleF[] rectangleFs = new RectangleF[rectangleF.Length];
                            //Array.Copy(rectangleF, rectangleFs, rectangleF.Length);
                            //for (int i = 0; i < rectangleFs.Length;i++ )
                            //{
                            //    for(int j=0;j<rectangleF.Length;j++)
                            //    {
                            //        if(i!=j)
                            //        {
                            //            if(rectangleFs[i].IntersectsWith(rectangleF[j]))
                            //            {
                            //                return;
                            //            }
                            //        }
                            //    }
                            //}

                           AddMapName(textPosInfo);
                        }

                    }
                }else
                {
                    textPosInfo._graphicsPath = null;
                    textPosInfo._rectangles = new[]{new RectangleF((float)textPosInfo._mapText.Bounds.X, (float)textPosInfo._mapText.Bounds.Y,
                                                           (float)textPosInfo._mapText.Bounds.Width,
                                                           (float)textPosInfo._mapText.Bounds.Height)};
                    AddMapName(textPosInfo);
                }

            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 14JAN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * clip the a pline.
         * @param input the pline to be clipped.
         * @return the clipped pline.
         */
        public ArrayList ClipPline(GeoLatLng[] input)
        {
            ArrayList clipped = new ArrayList();
            GeoLatLng p, prev = null;
            bool isInsidePrev = false;
            clipped.Clear();
            for (int i = 0; i < input.Length; i++)
            {
                p = input[i];
                bool isInside = _rectBounds.Contains(p);
                if (isInside)
                {
                    if (!isInsidePrev && (((clipped.Count != 0) &&
                            (!prev.Equals(clipped[clipped.Count - 1]))) ||
                            ((clipped.Count == 0 && (prev != null)))))
                    {
                        clipped.Add(prev);
                    }
                    clipped.Add(p);
                }
                else if (isInsidePrev)
                {
                    clipped.Add(p);
                }
                else if (prev != null)
                {

                    GeoLatLngBounds rect = new GeoLatLngBounds(Math.Min(p.X, prev.X),
                            Math.Min(p.Y, prev.Y),
                            Math.Max(p.X, prev.X) - Math.Min(p.X, prev.X),
                            Math.Max(p.Y, prev.Y) - Math.Min(p.Y, prev.Y));

                    if (rect.Intersects(_rectBounds))
                    {

                        ArrayList line1 = new ArrayList();
                        line1.Add(prev);
                        line1.Add(p);

                        ArrayList line2 = new ArrayList();
                        line2.Add(new GeoLatLng(_rectBounds.Y, _rectBounds.X));
                        line2.Add(new GeoLatLng(
                                (_rectBounds.Y + _rectBounds.Height),
                                (_rectBounds.X + _rectBounds.Width)));

                        ArrayList line3 = new ArrayList();
                        line3.Add(new GeoLatLng((_rectBounds.Y + _rectBounds.Height),
                                _rectBounds.X));
                        line3.Add(new GeoLatLng(
                                _rectBounds.Y,
                                (_rectBounds.X + _rectBounds.Width)));

                        if (IsLineInter(line1, line2) ||
                                IsLineInter(line1, line3))
                        {

                            clipped.Add(prev);
                            clipped.Add(p);
                        }
                    }
                }
                isInsidePrev = isInside;
                prev = p;

            }

            return clipped;
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- 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;
        }
Example #16
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 18JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * copy constructor.
  * @param pline pline object copied from.
  */
 public GeoPolyline(GeoPolyline pline)
 {
     if (pline._latlngs != null)
     {
         _latlngs = new GeoLatLng[pline._latlngs.Length];
         Array.Copy(_latlngs, 0, _latlngs, 0, _latlngs.Length);
         _levels = new int[pline._levels.Length];
         for (int i = 0; i < _levels.Length; i++)
         {
             _levels[i] = pline._levels[i];
         }
         _bounds = new GeoLatLngBounds(pline._bounds);
     }
     _color = pline._color;
     _weight = pline._weight;
     _opacity = pline._opacity;
     ZoomFactor = pline.ZoomFactor;
     NumLevels = pline.NumLevels;
     _visible = pline._visible;
 }
Example #17
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 21JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * get all records based on given rectangle in give map layer.
  * @param index the index of given map layer.
  * @param rectGeo the boundary..
  * @return a hashtable of all matched record.the key is the mapInfo ID.
  * @
  */
 public Hashtable Search(int index, GeoLatLngBounds rectGeo)
 {
     lock (_mapFeatureLayers)
     {
         MapFeatureLayer mapLayer = GetMapFeatureLayer(index);
         if (mapLayer != null)
         {
             return mapLayer.Search(rectGeo);
         }
         return null;
     }
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 18JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Resize the map to a level that include given bounds
  * @param bounds new bound.
  */
 public override void Resize(GeoLatLngBounds bounds)
 {
     lock (_mapLayers)
     {
         for (int i = 0; i < _mapLayers.Count; i++)
         {
             MapLayer mapLayer = (MapLayer)_mapLayers[i];
             mapLayer.Resize(bounds);
         }
     }
     base.Resize(bounds);
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 20JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Open the map.
  * @throws IOException if there's problem opening the map.
  */
 public void Open()
 {
     lock (_mapTiledZones)
     {
         int layerCount = _mapTiledZones.Count;
         if (layerCount > 0)
         {
             ((MapTiledZone)_mapTiledZones[0]).Open();
             _bounds = ((MapTiledZone)_mapTiledZones[0]).Bounds;
         }
         else
         {
             _bounds = new GeoLatLngBounds();
         }
         for (int i = 1; i < layerCount; i++)
         {
             MapTiledZone mapTiledZone = (MapTiledZone)_mapTiledZones[i];
             mapTiledZone.Open();
             GeoBounds.Union(mapTiledZone.Bounds, _bounds, _bounds);
         }
     }
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- 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 )
                {

                }
            }
        }
Example #21
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 18JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * copy constructor.
  * @param polygon polygon object copied from.
  */
 public GeoPolygon(GeoPolygon polygon)
 {
     if (polygon._latlngs != null)
     {
         _latlngs = new GeoLatLng[polygon._latlngs.Length];
         Array.Copy(_latlngs, 0, _latlngs, 0, _latlngs.Length);
         _levels = new int[polygon._levels.Length];
         for (int i = 0; i < _levels.Length; i++)
         {
             _levels[i] = polygon._levels[i];
         }
         _bounds = new GeoLatLngBounds(polygon._bounds);
     }
     _strokeColor = polygon._strokeColor;
     _strokeOpacity = polygon._strokeOpacity;
     _strokeWeight = polygon._strokeWeight;
     _fillColor = polygon._fillColor;
     _fillOpacity = polygon._fillOpacity;
     _zoomFactor = polygon._zoomFactor;
     _numLevels = polygon._numLevels;
     _visible = polygon._visible;
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 21JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * get all records based on given rectangle.
  * @param rectGeo the boundary..
  * @return a hashtable of all matched record.the key is the mapInfo ID. the
  * value is the matched MapObject's MBR.
  */
 public Hashtable Search(GeoLatLngBounds rectGeo)
 {
     return _mapFile.SearchMapObjectsInRect(rectGeo);
 }
Example #23
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 18JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Creates a polygon from an array of vertices.  The weight is the Width of
         * the line in pixels. The opacity is given as a number between 0 and 1.
         * The line will be antialiased and semitransparent.
         * @param _latlngs array of points.
         * @param _strokeColor the color of the polygon stroke.
         * @param _strokeWeight the Width of the polygon stroke.
         * @param _strokeOpacity the opacity of the polygon stroke.
         * @param _fillColor the inner color of the polygon.
         * @param _fillOpacity the inner opacity of the polygon.
         */
        public GeoPolygon(GeoLatLng[] latlngs, int strokeColor, int strokeWeight,
                double strokeOpacity, int fillColor, double fillOpacity)
        {
            if (latlngs != null)
            {
                _latlngs = new GeoLatLng[latlngs.Length];
                Array.Copy(latlngs, 0, _latlngs, 0, latlngs.Length);
                _levels = new int[latlngs.Length];
                for (int i = 0; i < _levels.Length; i++)
                {
                    _levels[i] = 0;
                }
                double maxlat = 0, minlat = 0, maxlon = 0, minlon = 0;
                GeoLatLng[] points = _latlngs;
                for (int i = 0; i < points.Length; i++)
                {

                    // determin _bounds (Max/Min Lat/lon)
                    if (i == 0)
                    {
                        maxlat = minlat = points[i].Lat();
                        maxlon = minlon = points[i].Lng();
                    }
                    else
                    {
                        if (points[i].Lat() > maxlat)
                        {
                            maxlat = points[i].Lat();
                        }
                        else if (points[i].Lat() < minlat)
                        {
                            minlat = points[i].Lat();
                        }
                        else if (points[i].Lng() > maxlon)
                        {
                            maxlon = points[i].Lng();
                        }
                        else if (points[i].Lng() < minlon)
                        {
                            minlon = points[i].Lng();
                        }
                    }
                }
                GeoLatLng sw, ne;
                sw = new GeoLatLng(minlat, minlon);
                ne = new GeoLatLng(maxlat, maxlon);
                _bounds = new GeoLatLngBounds(sw, ne);
            }
            _strokeColor = strokeColor;
            _strokeOpacity = strokeOpacity;
            _strokeWeight = strokeWeight;
            _fillColor = fillColor;
            _fillOpacity = fillOpacity;
            _zoomFactor = 1;
            _numLevels = 0;
            _visible = true;
        }
Example #24
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 21DEC2008  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * get all records based on given rectangle.
         * @param rectGeo the boundary..
         * @return a hashtable of all matched record.the key is the mapInfo ID.
         */
        public Hashtable SearchMapObjectsInRect(GeoLatLngBounds rectGeo)
        {
            Point pt1, pt2;
            pt1 = new Point(new[]{
                    (int) (rectGeo.X * DOUBLE_PRECISION+0.5),
                    (int) (rectGeo.Y * DOUBLE_PRECISION+0.5)});
            pt2 = new Point(new int[]{
                    (int) ((rectGeo.X + rectGeo.Width) * DOUBLE_PRECISION+0.5),
                    (int) ((rectGeo.Y + rectGeo.Height) * DOUBLE_PRECISION+0.5)});
            HyperCube h1 = new HyperCube(pt1, pt2);
            Hashtable retArrayList = new Hashtable();
            Point p11, p12;
            for (IEnumeration e1 = _tree.Intersection(h1); e1.HasMoreElements(); )
            {

                AbstractNode node = (AbstractNode)(e1.NextElement());
                if (node.IsLeaf())
                {
                    int index = 0;
                    HyperCube[] data = node.GetHyperCubes();
                    HyperCube cube;
                    for (int cubeIndex = 0; cubeIndex < data.Length; cubeIndex++)
                    {
                        cube = data[cubeIndex];
                        if (cube.Intersection(h1))
                        {
                            p11 = cube.GetP1();
                            p12 = cube.GetP2();
                            int mapinfoId = ((Leaf)node).GetDataPointer(index);
                            int mapInfoId = mapinfoId;
                            GeoLatLngBounds mbr = new GeoLatLngBounds();
                            mbr.X = p11.GetFloatCoordinate(0) / DOUBLE_PRECISION;
                            mbr.Y = p11.GetFloatCoordinate(1) / DOUBLE_PRECISION;
                            mbr.Width = ((p12.GetFloatCoordinate(0) - p11.GetFloatCoordinate(0))) / DOUBLE_PRECISION;
                            mbr.Height = ((p12.GetFloatCoordinate(1) - p11.GetFloatCoordinate(1))) / DOUBLE_PRECISION;
                            if (!retArrayList.Contains(mapInfoId))
                            {
                                retArrayList.Add(mapInfoId, mbr);
                            }

                        }
                        index++;

                    }
                }
            }
            return retArrayList;
        }
Example #25
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 21JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * get all records based on given rectangle.
  * @param rectGeo the boundary..
  * @return a hashtable array Contains of all matched record.
  *  the key is the mapInfo ID. the value is the MBR of map object.
  * @
  */
 public Hashtable[] Search(GeoLatLngBounds rectGeo)
 {
     if (_geoSet != null)
     {
         return _geoSet.Search(rectGeo);
     }
     return null;
 }
Example #26
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 18JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Resize the map to a level that include given bounds
  * @param bounds new bound.
  */
 public virtual void Resize(GeoLatLngBounds bounds)
 {
     lock (_syncObject)
     {
         GeoLatLng sw = bounds.GetSouthWest();
         GeoLatLng ne = bounds.GetNorthEast();
         GeoLatLng center = new GeoLatLng {X = (sw.X + ne.X)/2.0, Y = (sw.Y + ne.Y)/2.0};
         GeoPoint pt1, pt2;
         for (int i = MAX_ZOOMLEVEL; i >= MIN_ZOOMLEVEL; i--)
         {
             pt1 = FromLatLngToPixel(sw, i);
             pt2 = FromLatLngToPixel(ne, i);
             double dblWidth = Math.Abs(pt1.X - pt2.X);
             double dblHeight = Math.Abs(pt1.Y - pt2.Y);
             if (dblWidth < _mapSize.Width && dblHeight < _mapSize.Height)
             {
                 _mapZoomLevel = i;
                 SetCenter(center, i);
                 break;
             }
         }
     }
 }
Example #27
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 21JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * get all records based on given rectangle in give map layer.
  * @param index the index of given map layer.
  * @param rectGeo the boundary..
  * @return a hashtable of all matched record.the key is the mapInfo ID.
  * @
  */
 public Hashtable Search(int index, GeoLatLngBounds rectGeo)
 {
     if (_geoSet != null)
     {
         return _geoSet.Search(index, rectGeo);
     }
     return null;
 }