Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support quadkey urls (Bing Maps) #65

Closed
BKSnake opened this issue Feb 9, 2022 · 2 comments
Closed

Support quadkey urls (Bing Maps) #65

BKSnake opened this issue Feb 9, 2022 · 2 comments

Comments

@BKSnake
Copy link

BKSnake commented Feb 9, 2022

Hello

Could you help me to understand? Ho can I use this lib with Bing Maps. I need generate some image and i have Key to Bing Maps

Thanks

@StephanGeorg
Copy link
Owner

Bing Maps Tiles Server uses "quadkeys" to address a specific tile. Currently staticmaps supports the xyz schema only thus does not support Bing Maps, sorry.

Feel free to do a PR with quadKeys implementation yourself. I'm happy to help you with it. Implementation should be relatively easy.

C# implementation source

        public static string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail)  
        {  
            StringBuilder quadKey = new StringBuilder();  
            for (int i = levelOfDetail; i > 0; i--)  
            {  
                char digit = '0';  
                int mask = 1 << (i - 1);  
                if ((tileX & mask) != 0)  
                {  
                    digit++;  
                }  
                if ((tileY & mask) != 0)  
                {  
                    digit++;  
                    digit++;  
                }  
                quadKey.Append(digit);  
            }  
            return quadKey.ToString();  
        } 

JavaScript implementation source

const tileXYToQuadKey = (x, y, z) => {
    var quadKey = [];
    for (var i = z; i > 0; i--) {
        var digit = '0';
        var mask = 1 << (i - 1);
        if ((x & mask) != 0) {
            digit++;
        }
        if ((y & mask) != 0) {
            digit++;
            digit++;
        }
        quadKey.push(digit);
    }
    return quadKey.join('');
}

@StephanGeorg StephanGeorg changed the title How to use staticmaps with Bing Maps Support quadkey urls (Bing Maps) Feb 10, 2022
@StephanGeorg
Copy link
Owner

staticmaps@1.9.1 now supports {quadkeys} and Bing Maps.

const options = {
width: 600,
height: 200,
tileUrl: 'http://ak.dynamic.{s}.tiles.virtualearth.net/comp/ch/{quadkey}?mkt=en-US&it=G,L&shading=hill&og=1757&n=z',
tileSubdomains: ['t0', 't1', 't2', 't3'],
};
const map = new StaticMaps(options);
await map.render([13.437524, 52.4945528], 13);
await map.image.save('test/out/01a-quadkeys.jpg');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants