Esempio n. 1
0
        // TODO: handle exception
        public Label[] getNextLabels(int id, int count)
        {
            string strSelect = "SELECT data FROM label WHERE id >= " + id.ToString();
            ObservableCollection<TableLable> _labelEntries = null;
            _labelEntries = (Application.Current as App).db.SelectObservableCollection<TableLable>(strSelect);
            int countOfEntries = _labelEntries.Count;

            List<Label> result = new List<Label>();
            for(int index = 0; index < _labelEntries.Count; index++)
            {
                Label label = new Label(new System.IO.MemoryStream(_labelEntries[index].data));
                result.Add(label);
            }
            return result.ToArray();
        }
Esempio n. 2
0
        public QuadtreeEntry getEntry(string quadKey)
        {
            string strSelect = "SELECT data FROM quadtree WHERE quadkey = '" + quadKey + "'";
            ObservableCollection<TableQuadtree> _quadtableEntries = null;
            _quadtableEntries = (Application.Current as App).db.SelectObservableCollection<TableQuadtree>(strSelect);
            int countOfEntries = _quadtableEntries.Count;

            if (countOfEntries == 0)
                return new QuadtreeEntry();

            byte[] temp = _quadtableEntries[0].data;

            MemoryStream ms = new MemoryStream(temp);
            BinaryReader buffer = new BinaryReader(ms);

            Path[] paths = new Path[buffer.ReadInt32()];
            for (int index = 0; index < paths.Length; index++)
            {
                int id = buffer.ReadInt32();
                Path path = getPath(id);
                int size = buffer.ReadInt32();
                Object[] content = new Object[size];
                for (int i = 0, j = -1; i < size; i++)
                {
                    while (true)
                    {
                        int offset = buffer.ReadByte();
                        offset &= 0xff;
                        if (offset == 0)
                        {
                            j += 255;
                        }
                        else
                        {
                            j += offset;
                            break;
                        }
                    }
                    content[i] = path.content[j];
                }
                paths[index] = new Path(id, content);
            }

            Label[] labels = new Label[buffer.ReadInt32()];
            for (int index = 0; index < labels.Length; index++)
            {
                int id = buffer.ReadInt32();
                Label label = getLabel(id);
                labels[index] = label;
            }

            return new QuadtreeEntry(quadKey, paths, labels);
        }
Esempio n. 3
0
        // TODO: handle exception
        public Label getLabel(int id)
        {
            Label label = labelCache.get(id);
            if(label != null)
                return label;

            string strSelect = "SELECT data FROM label WHERE id = " + id.ToString();
            ObservableCollection<TableLable> _labelEntries = null;
            _labelEntries = (Application.Current as App).db.SelectObservableCollection<TableLable>(strSelect);
            int countOfEntries = _labelEntries.Count;

            if(countOfEntries == 0)
                return null;
            System.IO.Stream tmpStream = new System.IO.MemoryStream(_labelEntries[0].data);
            label = new Label(tmpStream);
            labelCache.put(id, label);
            return label;
        }
Esempio n. 4
0
 private static bool contain(RectangleF rect, Label label)
 {
     PointF point = new PointF((float)label.lon, (float)label.lat);
     return rect.Contains(point);
 }
Esempio n. 5
0
 private static bool isLabelVisible(Label label, int zoomLevel)
 {
     switch (zoomLevel)
     {
         case 17:
             return label.text.Length <= 4;
         case 18:
             return label.text.Length <= 8;
         case 19:
             return true;
         default:
             return zoomLevel >= Index.MAX_ZOOM_LEVEL;
     }
 }
Esempio n. 6
0
        private static RectangleF getLabelRect(Label label, int level)
        {
            double charSize = 14.0 / 160.0;
            double borderSize = 4.0 / 160.0;
            double size = fullTileSize(level);
            double len = charSize * (label.text.Length + 1);

            PointD p = geoToView(label.lat, label.lon);
            PointD q = new PointD(p.x * size, p.y * size);

            if (label.type.Contains("road"))
            {
                return new RectangleF((float)(q.x - len / 2 - charSize - borderSize),
                    (float)(q.y - len / 2 - charSize - borderSize),
                    (float)(len + borderSize * 2 + charSize * 2),
                    (float)(len + borderSize * 2 + charSize * 2));
            }
            else
            {
                return new RectangleF((float)(q.x - charSize / 2 - borderSize),
                    (float)(q.y - charSize / 2 - borderSize),
                    (float)(len + borderSize * 2),
                    (float)(charSize + borderSize * 2));
            }
        }
Esempio n. 7
0
        public static Label pathToLabel(Path path)
        {
            Node node = path.getNextNode(null);
            if (node == null)
                return null;
            if (path.getNextNode(node) != null)
                return null;

            Tag curr = null;
            Tag nameTag = null, typeTag = null;
            while (true)
            {
                curr = path.getNextTag(curr);
                if (curr == null)
                    break;

                if (curr.key.CompareTo("name") == 0)
                {
                    nameTag = curr;
                }
                else
                {
                    typeTag = curr;
                }
            }

            Label label = new Label(0, node.lat, node.lon, 0, (typeTag == null) ? "" : typeTag.key + "_" + typeTag.value,
                (nameTag == null) ? "" : nameTag.value);
            return label;
        }