Nendil
Nendil

Reputation: 85

Improve Api calls to Openweathermap for tiles on Leaflet

I am trying to add to my leaflet map a layer with current weather. For that I am using this leaflet plugin https://github.com/buche/leaflet-openweathermap that is using this call: https://tile.openweathermap.org/map/{layer}/{z}/{x}/{y}.png?appid={API key} The free version of OWM is offering 60 calls per minute, the problem is that every time that I zoom or drag the map 12 petitions to the API are being requested. I thought the free version with the 60c/m should be more than enough for my app, but as soon I zoom few times the API key gets blocked. Is there a better way to work around this?

Upvotes: 0

Views: 415

Answers (1)

treecon
treecon

Reputation: 2835

The more tiles your map requests, the sooner you reach the limit. In order to reduce the amount of tiles requested (with a cost to user experience), consider limiting zoom/drag options.

// change options according to your needs
let mapOptions = {
    zoomControl: false,
    scrollWheelZoom: false,
    boxZoom: false,
    dragging: false
}

let map = L.map('map', mapOptions);

Upvotes: 1

Related Questions