private void UpdateBuildings()
    {
        if (!zoomRange.InRange(api.zoom))
        {
            RemoveAllBuildings();
            return;
        }

        OnlineMapsVector2i newTopLeft     = OnlineMapsUtils.LatLongToTile(api.topLeftPosition, api.zoom) - new OnlineMapsVector2i(1, 1);
        OnlineMapsVector2i newBottomRight = OnlineMapsUtils.LatLongToTile(api.bottomRightPosition, api.zoom) + new OnlineMapsVector2i(1, 1);

        if (newTopLeft != topLeft || newBottomRight != bottomRight)
        {
            topLeft     = newTopLeft;
            bottomRight = newBottomRight;
            LoadNewBuildings();
        }

        UpdateBuildingsPosition();
    }
Example #2
0
    private bool UpdateBackBuffer(double px, double py, int zoom, bool fullRedraw)
    {
        const int s      = OnlineMapsUtils.tileSize;
        int       countX = api.width / s + 2;
        int       countY = api.height / s + 2;

        OnlineMapsVector2i pos = OnlineMapsUtils.LatLongToTile(px, py, zoom);

        pos.x -= countX / 2;
        pos.y -= countY / 2;

        int maxY = (2 << zoom) / 2;

        if (pos.y < 0)
        {
            pos.y = 0;
        }
        if (pos.y >= maxY - countY - 1)
        {
            pos.y = maxY - countY - 1;
        }

        if (api.target == OnlineMapsTarget.texture)
        {
            if (frontBuffer == null || frontBuffer.Length != api.width * api.height)
            {
                frontBuffer = new Color[api.width * api.height];
                fullRedraw  = true;
            }

            if (backBuffer == null || width != countX * s || height != countY * s)
            {
                width      = countX * s;
                height     = countY * s;
                backBuffer = new Color[height * width];

                fullRedraw = true;
            }
        }

        if (!updateBackBuffer && !fullRedraw && bufferZoom == zoom && bufferPosition != null &&
            bufferPosition == pos)
        {
            return(false);
        }

        updateBackBuffer = false;

        bufferPosition = pos;
        bufferZoom     = zoom;

        OnlineMapsBufferZoom activeZoom = GetActiveZoom(zoom);

        List <OnlineMapsTile> newBaseTiles = new List <OnlineMapsTile>();

        lock (OnlineMapsTile.tiles)
        {
            foreach (OnlineMapsTile tile in OnlineMapsTile.tiles)
            {
                tile.used = false;
            }

            InitTiles(zoom, activeZoom, countX, pos, countY, maxY, newBaseTiles);

            if (!api.useCurrentZoomTiles)
            {
                List <OnlineMapsTile> newParentTiles = CreateParents(newBaseTiles, zoom - 1);
                if (zoom - 2 > 2)
                {
                    newParentTiles = CreateParents(newParentTiles, zoom - 2);
                    if (zoom - 3 > 2)
                    {
                        CreateParents(newParentTiles, zoom - 3);
                    }
                }
            }

            if (api.target == OnlineMapsTarget.texture)
            {
                SetMarkersToBuffer(api.markers);
            }
        }

        needUnloadTiles = true;

        return(true);
    }