nucleon
nucleon

Reputation: 937

Optimizing and tracking Mapbox mapviews

I have a Mapbox mapping application that gets a LOT of map views per user — on the order of 30 per hit. Which seems kind of high! (And expensive!)

(The application tries to use MapboxGL by default and falls back to Mapbox.js if it can't. All versions also use Leaflet for whatever that is worth.)

I've been trying to debug this, but it's been hard for me to measure how different changes affect the overall number of map views.

Is there any way one can imagine that will allow me to get a realtime count of how many map views my application is generating? I am reasonably sure there isn't some kind of simple variable to query (that I have found), but maybe there is some way to count/keep track either in JS or the developer console? Any thoughts would be appreciated.

Upvotes: 1

Views: 317

Answers (1)

Scarysize
Scarysize

Reputation: 4281

Are you using a Mapbox Studio style or your own tiles? In both cases you can count the tiles being requested by your app using the data event:

map.on('data', event => {
  if (event.tile) tileCount++;
});

That's a very simple example. AFAIK one map view is consists of four tile requests.

If you got a lot different tile sources loading in parallel you end up with a lot of requests hence map views. If possible you could merge multiple sources into a single tile set (if you are using vector tiles).

If you use your own tiles, e.g. raster tiles, you can increase your tile size from 256px to 512px, which should result in less requests. For vector tiles the size is fixed to 256.

Upvotes: 1

Related Questions