Ejemplo n.º 1
0
        public override void Initialize(DrawArgs drawArgs)
        {
            try {
                m_Sprite = new Sprite(drawArgs.Device);
                if (m_IconFilePath != null
                    && File.Exists(m_IconFilePath)) {
                    m_IconTexture = ImageHelper.LoadIconTexture(m_IconFilePath);
                    m_IconTextureDescription = m_IconTexture.GetLevelDescription(0);
                }
                loadShapeFile(m_ShapeFilePath);

                if ((m_ShapeTileArgs.ShowLabels && m_ShapeTileArgs.DataKey != null)
                    || m_IconTexture != null) {
                    foreach (ShapeFileRecord record in m_ShapeTileArgs.ShapeRecords) {
                        if (record.Value != null) {
                            if (record.Point != null) {
                                Shapefile_Point p = new Shapefile_Point();
                                p.X = record.Point.X;
                                p.Y = record.Point.Y;
                                p.Tag = record.Value;
                                m_LabelList.Add(p);
                            }
                            else if (record.MultiPoint != null) {
                                Shapefile_Point p = new Shapefile_Point();
                                p.X = 0.5*(record.MultiPoint.BoundingBox.West + record.MultiPoint.BoundingBox.East);
                                p.Y = 0.5*(record.MultiPoint.BoundingBox.North + record.MultiPoint.BoundingBox.South);
                                p.Tag = record.Value;
                                m_LabelList.Add(p);
                            }
                            else if (record.PolyLine != null) {
                                Shapefile_Point p = new Shapefile_Point();
                                p.X = 0.5*(record.PolyLine.BoundingBox.West + record.PolyLine.BoundingBox.East);
                                p.Y = 0.5*(record.PolyLine.BoundingBox.North + record.PolyLine.BoundingBox.South);
                                p.Tag = record.Value;
                                m_LabelList.Add(p);
                            }
                            else if (record.Polygon != null) {
                                Shapefile_Point p = new Shapefile_Point();
                                p.X = 0.5*(record.Polygon.BoundingBox.West + record.Polygon.BoundingBox.East);
                                p.Y = 0.5*(record.Polygon.BoundingBox.North + record.Polygon.BoundingBox.South);
                                p.Tag = record.Value;
                                m_LabelList.Add(p);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                Log.Write(ex);
            }
            finally {
                Inited = true;
            }
        }
Ejemplo n.º 2
0
        private Point[] getScreenPoints(Shapefile_Point[] sourcePoints, int offset, int length, GeographicBoundingBox dstBB, Size dstImageSize)
        {
            double degreesPerPixelX = (dstBB.East - dstBB.West)/(double) dstImageSize.Width;
            double degreesPerPixelY = (dstBB.North - dstBB.South)/(double) dstImageSize.Height;

            ArrayList screenPointList = new ArrayList();
            for (int i = offset; i < offset + length; i++) {
                double screenX = (sourcePoints[i].X - dstBB.West)/degreesPerPixelX;
                double screenY = (dstBB.North - sourcePoints[i].Y)/degreesPerPixelY;

                if (screenPointList.Count > 0) {
                    Point v = (Point) screenPointList[screenPointList.Count - 1];
                    if (v.X == (int) screenX
                        && v.Y == (int) screenY) {
                        continue;
                    }
                }

                screenPointList.Add(new Point((int) screenX, (int) screenY));
            }

            if (screenPointList.Count <= 1) {
                return new Point[] {new Point(0, 0), new Point(0, 0)};
            }

            return (Point[]) screenPointList.ToArray(typeof (Point));
        }