Exemplo n.º 1
0
 /// <summary>
 /// stores an MapElementContainer that clashesWith from one tile (the one being drawn) to
 /// another (which must not have been drawn before). </summary>
 /// <param name="from"> origin tile </param>
 /// <param name="to"> tile the label clashesWith to </param>
 /// <param name="element"> the MapElementContainer in question </param>
 internal virtual void AddOverlappingElement(Tile from, Tile to, MapElementContainer element)
 {
     if (!overlapData.ContainsKey(from))
     {
         overlapData[from] = new Dictionary <Tile, ISet <MapElementContainer> >();
     }
     if (!overlapData[from].ContainsKey(to))
     {
         overlapData[from][to] = new HashSet <MapElementContainer>();
     }
     overlapData[from][to].Add(element);
 }
Exemplo n.º 2
0
        private ISet <MapElementContainer> ProcessLabels(RenderContext renderContext)
        {
            // if we are drawing the labels per tile, we need to establish which tile-overlapping
            // elements need to be drawn.

            ISet <MapElementContainer> labelsToDraw = new HashSet <MapElementContainer>();

            lock (tileDependencies)
            {
                // first we need to get the labels from the adjacent tiles if they have already been drawn
                // as those overlapping items must also be drawn on the current tile. They must be drawn regardless
                // of priority clashes as a part of them has alread been drawn.
                ISet <Tile> neighbours = renderContext.rendererJob.tile.Neighbours;
                ISet <MapElementContainer> undrawableElements = new HashSet <MapElementContainer>();

                tileDependencies.AddTileInProgress(renderContext.rendererJob.tile);
                for (var i = neighbours.Count - 1; i >= 0; i--)
                {
                    Tile neighbour = neighbours.ElementAt(i);

                    if (tileDependencies.IsTileInProgress(neighbour) || tileCache.ContainsKey(renderContext.rendererJob.OtherTile(neighbour)))
                    {
                        // if a tile has already been drawn, the elements drawn that overlap onto the
                        // current tile should be in the tile dependencies, we add them to the labels that
                        // need to be drawn onto this tile. For the multi-threaded renderer we also need to take
                        // those tiles into account that are not yet in the TileCache: this is taken care of by the
                        // set of tilesInProgress inside the TileDependencies.
                        labelsToDraw.UnionWith(tileDependencies.GetOverlappingElements(neighbour, renderContext.rendererJob.tile));

                        // but we need to remove the labels for this tile that overlap onto a tile that has been drawn
                        foreach (MapElementContainer current in renderContext.labels)
                        {
                            if (current.Intersects(neighbour.BoundaryAbsolute))
                            {
                                undrawableElements.Add(current);
                            }
                        }
                        // since we already have the data from that tile, we do not need to get the data for
                        // it, so remove it from the neighbours list.
                        neighbours.Remove(neighbour);
                    }
                    else
                    {
                        tileDependencies.RemoveTileData(neighbour);
                    }
                }

                // now we remove the elements that overlap onto a drawn tile from the list of labels
                // for this tile
                foreach (var element in undrawableElements)
                {
                    renderContext.labels.Remove(element);
                }

                // at this point we have two lists: one is the list of labels that must be drawn because
                // they already overlap from other tiles. The second one is currentLabels that contains
                // the elements on this tile that do not overlap onto a drawn tile. Now we sort this list and
                // remove those elements that clash in this list already.
                IList <MapElementContainer> currentElementsOrdered = LayerUtil.CollisionFreeOrdered(renderContext.labels);

                // now we go through this list, ordered by priority, to see which can be drawn without clashing.
                IEnumerator <MapElementContainer> currentMapElementsIterator = currentElementsOrdered.GetEnumerator();
                while (currentMapElementsIterator.MoveNext())
                {
                    MapElementContainer current = currentMapElementsIterator.Current;
                    foreach (MapElementContainer label in labelsToDraw)
                    {
                        if (label.ClashesWith(current))
                        {
                            break;
                        }
                    }
                }

                labelsToDraw.UnionWith(currentElementsOrdered);

                // update dependencies, add to the dependencies list all the elements that overlap to the
                // neighbouring tiles, first clearing out the cache for this relation.
                foreach (Tile tile in neighbours)
                {
                    tileDependencies.RemoveTileData(renderContext.rendererJob.tile, tile);
                    foreach (MapElementContainer element in labelsToDraw)
                    {
                        if (element.Intersects(tile.BoundaryAbsolute))
                        {
                            tileDependencies.AddOverlappingElement(renderContext.rendererJob.tile, tile, element);
                        }
                    }
                }
            }
            return(labelsToDraw);
        }