传单-计算传单发送给osm的请求数(openstreetmap) [英] leaflet - count number of requests sent by leaflet to osm (openstreetmap)

查看:60
本文介绍了传单-计算传单发送给osm的请求数(openstreetmap)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用leaflet.js进行项目. Leaflet发送请求以打开街道地图(osm)磁贴服务器以获取其磁贴.由于这些请求是直接从客户端发送的,因此我很难在服务器上找到这些请求.

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.

问题:是否可以找出由传单发送给osm上的切片服务器的请求数量?

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

(我无法在 leaflet.js 中找到任何$ .ajax/$ .get/$ .post !)

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

推荐答案

请注意,$.ajax/$.get/$.post是jQuery的方法.传单不依赖jQuery.

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

此外,不需要特殊的AJAX请求即可获取图块.如您所知,图块是纯图像,因此使用简单的<img src="path/to/tile" />标签,并根据需要调整src属性.浏览器会自动发出HTTP请求.

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.

最后,浏览器可以直接从其缓存中提供切片,从而减少了实际的OSM服务器请求.

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

如果您仍想监视切片请求的数量(请记住,在客户端浏览器上,您将无法区分服务器响应和浏览器缓存),则可以使用 L.TileLayer.getTileUrl 方法(例如在执行这些方法之一时将1加到全局变量中).

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).

这篇关于传单-计算传单发送给osm的请求数(openstreetmap)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆