leaflet - count number of requests sent by leaflet to osm (openstreetmap)

你。 提交于 2019-12-24 07:22:05

问题


I'm using leaflet.js for a project. Leaflet sends requests to open street map (osm) tile server to get its tiles. As these requests are sent directly from the client, I have a hard time finding about the requests on my server.

Question: Is there a way to find out the number of requests sent by leaflet to the tile servers at osm?

(I was not able to find any $.ajax / $.get / $.post in leaflet.js!)


回答1:


Please note that $.ajax / $.get / $.post are methods from jQuery. Leaflet does not depend on jQuery.

Furthermore, there is no need for special AJAX requests to get tiles. As you know, tiles are plain images, so simple <img src="path/to/tile" /> tags are used, adjusting the src attribute as necessary. The browser automatically makes the HTTP request.

Finally, the browser may serve tiles directly from its cache, decreasing the actual OSM server requests.

If you still want to monitor the count of tiles requests (remember that on client browser, you will not be able to differentiate between a server response and a browser cache), you could instrument the L.TileLayer.createTile or L.TileLayer.getTileUrl methods (like adding 1 to a global variable anytime one of those methods are executed).



来源:https://stackoverflow.com/questions/38705374/leaflet-count-number-of-requests-sent-by-leaflet-to-osm-openstreetmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!