当您将地图集成到Web应用程序中时,一个架构决策会影响随后的所有内容:栅格瓦片还是矢量瓦片。做对了,您的地图就会快速、美观且易于调整。做错了,您就在发布一个像素化的、迟缓的背景图像,它会在每个转折处与您的设计系统产生冲突。
本指南解释了两种格式之间的技术差异,介绍了对前端开发者真正重要的实际权衡,并为您提供了一个清晰的决策框架。到最后,您将精确了解为您的项目选择哪种格式,以及如何在MapAtlas上开始使用矢量瓦片。
瓦片格式问题在几乎每个地图项目早期都会出现,互联网上充满了停留在「矢量瓦片更新」的肤浅答案。本指南深入探讨,涵盖了渲染管道、有效载荷大小、浏览器兼容性、样式控制,以及栅格瓦片仍然是正确选择的特定场景。
如果您已经在构建并只需要代码,请跳到快速启动部分。
什么是栅格瓦片?
栅格瓦片是预渲染的PNG或JPEG图像,通常为256×256或512×512像素,代表特定缩放级别的世界的固定切片。当用户平移或缩放时,浏览器请求相邻或更高分辨率的瓦片,这些瓦片服务器已经渲染并缓存。
渲染完全在服务器端进行。到达浏览器的瓦片图像是完成的图片,像素已经放置,颜色已经烘焙。浏览器的工作就是简单地显示它。
栅格瓦片服务器如何工作
典型的栅格瓦片堆栈看起来像这样:
- 原始地理数据(OpenStreetMap、地籍数据、高程模型)被处理到数据库中。
- 渲染引擎(Mapnik是经典选择)在每个缩放级别预渲染瓦片到瓦片缓存。
- 瓦片服务器(Raster模式的TileServer GL或托管CDN)通过
/{zoom}/{x}/{y}.pngURL约定提供缓存图像。
结果是简单、快速且无状态的。任何HTTP客户端都可以请求瓦片,浏览器、移动应用程序、生成地图图像的服务器端流程或GIS桌面应用程序。
栅格瓦片的优势
- 零客户端渲染开销。 浏览器只是显示图像。无需WebGL、无需着色器编译、无需字体渲染。
- 通用兼容性。 在任何浏览器、任何版本中工作,包括Internet Explorer和无头渲染环境。
- 可预测的外观。 地图看起来完全像瓦片服务器渲染的那样。没有客户端差异。
- 简便的服务器端图像生成。 非常适合为电子邮件、PDF报告或社交分享卡生成静态地图图像。
栅格瓦片的劣势
- 大文件大小。 典型的256×256 PNG瓦片为30-200 KB,取决于内容密度。Retina(512×512)瓦片是像素数的四倍。
- 高DPI屏幕上的像素化。 为1x显示渲染的瓦片在2x Retina屏幕上看起来模糊,除非您提供@2x瓦片,将带宽加倍。
- 无旋转或倾斜。 如果您旋转栅格地图,文本标签也会随之旋转并变得不可读。这就是为什么栅格地图总是正北方向。
- 无客户端样式更改。 想改变道路颜色、隐藏POI图标或切换到深色模式?您需要一个新的瓦片集,在服务器端预渲染。
- 缩放插值。 在整数缩放级别之间,浏览器缩放现有图像,这会使其模糊。您在矢量瓦片中获得的「平滑缩放」感觉在栅格中不存在。
What Are Vector Tiles?
A vector tile contains the raw geographic data for a map region, road geometries, building polygons, water bodies, land use areas, label placement data, encoded as compact binary (usually Mapbox Vector Tile format, .mvt). The tile contains no pixels. It describes what exists in that region, not how it should look.
The rendering happens entirely client-side, using WebGL. When you load a Mapbox GL JS-compatible map (like MapAtlas), the SDK requests vector tiles, receives geometry data, and uses your style specification to draw every road, building, and label to a <canvas> element in real time, at 60 frames per second.
How vector tile rendering works
Vector tile (.mvt) + Style JSON → WebGL shader → Canvas pixels
The style JSON (a structured file you control) tells the renderer: draw roads in this color, draw building extrusions at this height, use this font for labels, hide these layer types below zoom 12. The style can be changed at runtime, without fetching new tiles.
Vector tile strengths
- Small payloads. Binary-encoded geometry is far more compact than a rendered image. A typical vector tile for a dense urban area is 15–50 KB versus 80–200 KB for the equivalent raster tile.
- Crisp at any resolution. Vector geometry scales mathematically. A Retina display gets the same tile as a standard display, the renderer simply outputs more pixels. No @2x tile variants needed.
- Smooth zoom and rotation. Because the renderer works on raw geometry, zoom can be interpolated continuously (not just at integer levels) and the map can be pitched and rotated with labels always upright.
- Full client-side style control. Change any visual property, road color, label font, layer visibility, opacity, by updating the style object. No new tile requests. Dark mode is a style JSON swap, not a new tile set.
- 3D building extrusion. Vector tiles include building height metadata. Renderers can extrude polygons in 3D using WebGL. Raster tiles have no concept of elevation.
- Data-driven styling. Color roads by speed limit, shade land use by category, scale markers by population, all driven by data properties in the tile without touching the server.
Vector tile weaknesses
- WebGL required. No WebGL support means no vector tile rendering. This excludes very old browsers (IE11) and certain headless environments.
- Client-side CPU/GPU load. The rendering happens on the user's device. On low-end Android phones or heavily loaded desktops, complex map styles with many layers can cause frame drops.
- More complex initial setup. You need a rendering library (Mapbox GL JS, MapLibre GL, or the MapAtlas SDK) and a style JSON, not just an
<img>tag. - Font and glyph loading. Label rendering requires glyph files to be served separately. This adds a few extra network requests on first load.
Performance Comparison: Real Numbers
To make the trade-off concrete, here are real-world measurements for a map tile of central Amsterdam at zoom level 14:
| Metric | Raster (PNG 512px) | Vector (.mvt) |
|---|---|---|
| Tile size | 142 KB | 31 KB |
| Requests for Retina | 1 (@2x tile) | 1 (same tile) |
| Zoom interpolation | Pixel scaling (blurry) | Mathematical (crisp) |
| Rotation support | No | Yes |
| Style change | New tile request | Zero requests |
| WebGL required | No | Yes |
At scale, vector tiles reduce map-related bandwidth by 60–80%. For a medium-traffic app generating 10 million tile requests per month, that difference meaningfully reduces CDN egress costs.
When to Use Raster Tiles
Raster tiles are not obsolete. There are clear scenarios where they remain the right choice:
Legacy system integration. If you're embedding a map in a .NET WebForms app, a server-rendered Rails view, or an environment where you control only HTML and basic JavaScript, a raster tile layer via Leaflet or OpenLayers is simpler and more reliable than introducing a WebGL renderer.
Server-side map image generation. If you need to render map snapshots on a Node.js server for email templates, PDF exports, or open graph images, headless raster rendering is your path. Tools like node-canvas plus a raster tile source work where WebGL does not.
Satellite and aerial imagery. Aerial photography is raster data by nature. Even on a vector map, the satellite imagery layer is always delivered as raster tiles. Hybrid maps mix both formats, vector for roads and labels, raster for the photographic base.
Very simple use cases. Embedding a static location map on a contact page? A simple Leaflet + OpenStreetMap raster setup takes 20 minutes and has zero JavaScript complexity. The upgrade to vector tiles is not justified for a non-interactive location pin.
When to Use Vector Tiles
Choose vector tiles for any modern web application where you care about:
- Custom brand styling. If your design system has specific colors, your map should too. Vector tiles make this a JSON change.
- Dark mode support. A dark style JSON is one configuration file. Switching between light and dark is a
map.setStyle()call. - High-DPI / Retina sharpness. Especially important for mobile-first apps and any UI where crisp rendering is a design priority.
- Smooth user experience. The continuous zoom interpolation and 60fps rendering of a vector map are immediately noticeable to users. Raster maps feel clunky by comparison in interactive contexts.
- Data visualization layers. Adding a heatmap, a choropleth, or a cluster layer to a vector map requires only client-side configuration. On a raster map, you'd tile-blast a new layer or use a canvas overlay hack.
- 3D or tilted perspectives. Only achievable with vector tiles and WebGL.
Quick Start: Vector Tiles with MapAtlas
MapAtlas serves vector tiles via a Mapbox GL JS-compatible API. If you've used Mapbox GL JS before, migration is a style URL change and an API key swap. If you're starting fresh, here's the complete setup.
Install the SDK
npm install @mapmetrics/mapmetrics-gl
Or via CDN for plain HTML projects:
<link rel="stylesheet" href="https://unpkg.com/@mapmetrics/mapmetrics-gl/dist/mapmetrics-gl.css" />
<script src="https://unpkg.com/@mapmetrics/mapmetrics-gl/dist/mapmetrics-gl.js"></script>
Render a vector map
import mapmetricsgl from '@mapmetrics/mapmetrics-gl';
import '@mapmetrics/mapmetrics-gl/dist/mapmetrics-gl.css';
const map = new mapmetricsgl.Map({
container: 'map', // ID of your <div>
style: 'https://tiles.mapatlas.eu/styles/basic/style.json?key=YOUR_API_KEY',
center: [4.9041, 52.3676], // [longitude, latitude], Amsterdam
zoom: 12,
pitch: 0, // 0 = top-down, 60 = 3D tilted
bearing: 0, // 0 = north-up, any value = rotated
});
The style URL points to a JSON file hosted on MapAtlas servers that defines all layers, fonts, and sources. You can also host a custom style JSON yourself to control every visual aspect of the map, see the Map Visualization & Styling guide.
Switch to dark mode at runtime
document.getElementById('toggle-dark').addEventListener('click', () => {
const isDark = map.getStyle().name?.includes('dark');
map.setStyle(
isDark
? 'https://tiles.mapatlas.eu/styles/basic/style.json?key=YOUR_API_KEY'
: 'https://tiles.mapatlas.eu/styles/dark/style.json?key=YOUR_API_KEY'
);
});
No new tile requests are triggered for data that's already cached. Only the style changes, the tiles remain the same binary geometry, re-rendered with new colors.
Add a GeoJSON data layer
One of the most powerful vector tile features is overlaying your own data as a styled layer:
map.on('load', () => {
// Add your own data source
map.addSource('delivery-zones', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [[[4.85, 52.34], [4.95, 52.34], [4.95, 52.40], [4.85, 52.40], [4.85, 52.34]]],
},
properties: { zone: 'Zone A', capacity: 150 },
},
],
},
});
// Style it as a colored fill layer
map.addLayer({
id: 'delivery-zones-fill',
type: 'fill',
source: 'delivery-zones',
paint: {
'fill-color': '#97C70A',
'fill-opacity': 0.2,
},
});
map.addLayer({
id: 'delivery-zones-outline',
type: 'line',
source: 'delivery-zones',
paint: {
'line-color': '#97C70A',
'line-width': 2,
},
});
});
This pattern, add a source, add a layer, paint with style expressions, is the same for heatmaps, route lines, isochrone polygons, and choropleth maps. It works because vector tiles give the renderer raw geometry, not finished pixels.
Migrating from Raster to Vector
If you have an existing Leaflet + raster tile setup and want to upgrade, here's the minimal migration path:
- Replace Leaflet with the MapAtlas SDK (or MapLibre GL JS if you prefer a fully open-source renderer).
- Replace the tile URL with a MapAtlas style JSON URL.
- Move overlays from Leaflet layers to GL JS sources and layers.
- Test on WebGL-lacking environments. Add a fallback or graceful degradation message for the small percentage of users who will not have WebGL available.
The functional result is a map that looks sharper, loads faster, and can be restyled without touching the server.
For a full walkthrough of adding markers, popups, address search, and React integration on top of a vector tile base, see How to Add Interactive Maps to Your Website.
To push the styling further, dark mode, brand colors, custom fonts, watermark removal, see How to Style a Custom Branded Map.
And if you're evaluating MapAtlas against Google Maps from a cost and feature standpoint, MapAtlas vs. Google Maps: Why Developers Are Switching covers the key differences.
Summary: The Decision Framework
| Scenario | Recommended format |
|---|---|
| Modern SPA or PWA (React, Vue, Svelte) | Vector tiles |
| Custom brand colors or dark mode | Vector tiles |
| 3D buildings or map tilt/rotation | Vector tiles |
| Data visualization overlays | Vector tiles |
| Legacy browser support (IE11) | Raster tiles |
| Server-side image generation | Raster tiles |
| Satellite/aerial imagery layer | Raster tiles |
| Simple non-interactive location pin | Raster tiles |
If you're building anything interactive in 2026, vector tiles are the default choice. Raster tiles are the deliberate exception for specific compatibility or rendering constraints.
Ready to build with vector tiles? Sign up for a free MapAtlas API key, no credit card required. Your key works across tiles, geocoding, routing, and isochrone APIs from day one.
常见问题
矢量瓦片比栅格瓦片更好吗?
对于大多数现代Web应用来说,是的。矢量瓦片更小,以60fps平滑缩放和旋转渲染,可以在客户端完全重新设置样式。栅格瓦片实现更简单,在不支持WebGL的环境中工作,但它们较大,在高DPI屏幕上会出现像素化,并且不提供客户端样式控制。
我需要WebGL才能使用矢量瓦片吗?
是的。矢量瓦片渲染器(如Mapbox GL JS和MapAtlas SDK)使用WebGL在画布元素上绘制地图几何体。所有现代浏览器都支持WebGL。如果您需要支持很旧的浏览器或没有画布的服务器端渲染环境,栅格瓦片是更安全的备选方案。
MapAtlas同时支持矢量瓦片和栅格瓦片吗?
MapAtlas主要通过Mapbox GL JS兼容的API提供矢量瓦片。这意味着任何已经熟悉Mapbox GL JS的开发者可以通过更新样式URL和API密钥切换到MapAtlas,无需进行其他代码更改。

