admin管理员组

文章数量:1127055

I am working on a UI that will have a map integration written in react. The code is very simple:

return (
    <TileLayer
        attribution='&copy; <a href=";>OpenStreetMap</a> contributors'
        url="https://{s}.tile.openstreetmap/{z}/{x}/{y}.png"
    />
);

However I want the source to sometimes be from a different map, the idea is that the important parts of the map can be cached and viewed even when offline (this project will only run locally)

So something like this

if(0<=x<=5 && 8<=y<=12)
    return (
        <TileLayer
            attribution='&copy; <a href=";>OpenStreetMap</a> contributors'
            url="https://localhost/{z}/{x}/{y}.png"
        />
    );
else
    return (
        <TileLayer
            attribution='&copy; <a href=";>OpenStreetMap</a> contributors'
            url="https://{s}.tile.openstreetmap/{z}/{x}/{y}.png"
        />
    );

The problem with this javascript-like pseudo code is that I don't have access to x, y and z. Is there a way to get these values when creating a request?

本文标签: javascriptHow to change leafletjs source based on locationStack Overflow