Convert Figma logo to code with AI

tangrams logotangram

WebGL map rendering engine for creative cartography

2,205
290
2,205
67

Top Related Projects

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL

OpenLayers

40,934

πŸƒ JavaScript library for mobile-friendly interactive maps πŸ‡ΊπŸ‡¦

MapLibre GL JS - Interactive vector tile maps in the browser

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.

12,690

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:

Quick Overview

Tangram is an open-source mapping library for web browsers, developed by Mapzen. It uses WebGL to render 2D and 3D maps with custom styling and real-time data overlays. Tangram allows developers to create highly customizable, interactive maps using simple styling rules and a flexible scene description format.

Pros

  • Highly customizable map styling with a powerful, easy-to-use scene file format
  • Excellent performance due to WebGL rendering
  • Supports both 2D and 3D map visualizations
  • Active community and ongoing development

Cons

  • Steeper learning curve compared to some other mapping libraries
  • Limited documentation for advanced features
  • Requires WebGL support, which may not be available on all devices or browsers
  • Smaller ecosystem compared to more established mapping libraries like Leaflet or Mapbox GL JS

Code Examples

  1. Basic map initialization:
var map = L.map('map');
var layer = Tangram.leafletLayer({
    scene: 'scene.yaml'
});
layer.addTo(map);
  1. Changing map style dynamically:
layer.scene.load('new-style.yaml');
  1. Adding a custom data source:
layer.scene.setDataSource('mydata', { type: 'GeoJSON', url: 'data.geojson' });
  1. Applying a filter to map features:
layer.scene.config.layers.buildings.filter = function(feature) {
    return feature.properties.height > 100;
};
layer.scene.updateConfig();

Getting Started

  1. Include Leaflet and Tangram in your HTML:
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/tangram/dist/tangram.min.js"></script>
  1. Create a map container:
<div id="map" style="height: 400px;"></div>
  1. Initialize the map with Tangram:
var map = L.map('map');
var layer = Tangram.leafletLayer({
    scene: 'https://tangrams.github.io/cinnabar-style/cinnabar-style.yaml'
});
layer.addTo(map);
map.setView([40.70531, -74.00976], 13);

This setup creates a basic map using Tangram's Cinnabar style. You can customize the map further by modifying the scene file or adding your own data sources.

Competitor Comparisons

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL

Pros of Mapbox GL JS

  • More extensive documentation and community support
  • Better performance for large datasets and complex visualizations
  • Wider range of built-in features and customization options

Cons of Mapbox GL JS

  • Requires a Mapbox account and API key for full functionality
  • Steeper learning curve for beginners
  • Larger file size and potentially higher resource usage

Code Comparison

Tangram (JavaScript):

var map = L.map('map');
var layer = Tangram.leafletLayer({
    scene: 'scene.yaml',
    attribution: '...'
});
layer.addTo(map);

Mapbox GL JS:

mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v11',
    center: [-74.5, 40],
    zoom: 9
});

Both libraries offer powerful mapping capabilities, but Mapbox GL JS provides more advanced features and better performance for complex visualizations. However, it comes with a steeper learning curve and requires an API key. Tangram, on the other hand, is more lightweight and easier to set up for simple mapping needs. The choice between the two depends on the specific requirements of your project, such as the complexity of visualizations, performance needs, and budget constraints.

OpenLayers

Pros of OpenLayers

  • More comprehensive and feature-rich library for web mapping
  • Larger community and ecosystem, with extensive documentation and examples
  • Supports a wider range of data formats and sources

Cons of OpenLayers

  • Steeper learning curve due to its extensive API and features
  • Larger file size, which may impact page load times
  • Less focus on modern, performant vector tile rendering compared to Tangram

Code Comparison

Tangram:

var map = L.map('map');
var layer = Tangram.leafletLayer({
    scene: 'scene.yaml',
    attribution: '...'
});
layer.addTo(map);

OpenLayers:

var map = new ol.Map({
    target: 'map',
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],
    view: new ol.View({
        center: [0, 0],
        zoom: 2
    })
});

Both libraries offer ways to create maps, but OpenLayers requires more setup code for basic functionality. Tangram focuses on vector tile rendering with a more concise API, while OpenLayers provides a more comprehensive set of mapping tools and options.

40,934

πŸƒ JavaScript library for mobile-friendly interactive maps πŸ‡ΊπŸ‡¦

Pros of Leaflet

  • Widely adopted and mature library with extensive documentation and community support
  • Lightweight and mobile-friendly, offering good performance on various devices
  • Extensive plugin ecosystem for additional functionality

Cons of Leaflet

  • Limited 3D mapping capabilities out of the box
  • Less suitable for complex, data-driven visualizations compared to Tangram

Code Comparison

Leaflet:

var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: 'Β© OpenStreetMap contributors'
}).addTo(map);

Tangram:

var map = L.map('map');
var layer = Tangram.leafletLayer({
    scene: 'scene.yaml',
    attribution: 'Β© OpenStreetMap contributors'
}).addTo(map);

Both libraries use Leaflet as a base, but Tangram provides more advanced rendering capabilities through its scene file system. Leaflet focuses on simplicity and ease of use, while Tangram offers more flexibility for custom styling and data visualization. Leaflet is better suited for standard web mapping applications, whereas Tangram excels in creating visually striking, data-driven maps with 2D and 3D capabilities.

MapLibre GL JS - Interactive vector tile maps in the browser

Pros of MapLibre GL JS

  • More extensive documentation and community support
  • Better performance for large datasets and complex visualizations
  • Wider range of built-in features and styling options

Cons of MapLibre GL JS

  • Steeper learning curve for beginners
  • Larger file size and potentially higher resource usage

Code Comparison

MapLibre GL JS:

const map = new maplibregl.Map({
  container: 'map',
  style: 'https://demotiles.maplibre.org/style.json',
  center: [-74.5, 40],
  zoom: 9
});

Tangram:

var map = L.map('map');
var layer = Tangram.leafletLayer({
  scene: 'scene.yaml',
  attribution: '...'
});
layer.addTo(map);

Key Differences

  • MapLibre GL JS uses WebGL for rendering, while Tangram uses a custom rendering engine
  • MapLibre GL JS has a more flexible styling system with JSON-based styles
  • Tangram focuses on vector tile rendering and scene description using YAML

Use Cases

  • MapLibre GL JS: Complex, interactive maps with large datasets
  • Tangram: Lightweight mapping applications with custom styling needs

Community and Support

  • MapLibre GL JS has a larger and more active community
  • Tangram has a smaller but dedicated user base

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.

Pros of tileserver-gl

  • Supports multiple vector tile formats (MBTiles, PMTiles, GeoJSON)
  • Built-in caching mechanism for improved performance
  • Easier setup and configuration for basic use cases

Cons of tileserver-gl

  • Less flexibility in styling and customization compared to Tangram
  • Limited support for advanced rendering techniques
  • Smaller community and fewer third-party extensions

Code Comparison

Tangram (YAML-based scene file):

layers:
  water:
    data: { source: mapzen }
    draw:
      polygons:
        color: '#353535'

tileserver-gl (JSON-based style):

{
  "layers": [{
    "id": "water",
    "type": "fill",
    "source": "openmaptiles",
    "paint": {
      "fill-color": "#353535"
    }
  }]
}

Both projects aim to render map tiles, but they differ in their approach and capabilities. Tangram focuses on flexible, customizable rendering using WebGL, while tileserver-gl provides a more straightforward solution for serving and styling vector tiles. Tangram offers more advanced rendering techniques and greater control over the map's appearance, but tileserver-gl is often easier to set up and use for basic mapping needs. The choice between the two depends on the specific requirements of your project and the level of customization you need.

12,690

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:

Pros of Cesium

  • More comprehensive 3D geospatial visualization capabilities
  • Larger community and ecosystem with extensive documentation
  • Support for time-dynamic data and animations

Cons of Cesium

  • Steeper learning curve due to its complexity
  • Larger file size and potentially higher resource consumption
  • May be overkill for simple 2D mapping projects

Code Comparison

Cesium:

const viewer = new Cesium.Viewer('cesiumContainer');
viewer.scene.globe.enableLighting = true;
const entity = viewer.entities.add({
  position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  point: { pixelSize: 10, color: Cesium.Color.YELLOW }
});

Tangram:

var map = L.map('map');
var layer = Tangram.leafletLayer({
  scene: 'scene.yaml',
  attribution: '<a href="https://mapzen.com">Mapzen</a>'
});
layer.addTo(map);

Summary

Cesium is a powerful 3D geospatial visualization library with extensive features, while Tangram focuses on 2D vector map rendering. Cesium offers more advanced capabilities but comes with increased complexity, whereas Tangram provides a simpler approach for 2D mapping needs. The choice between the two depends on the specific requirements of your project, such as the need for 3D visualization, time-dynamic data, or simpler 2D map rendering.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Tangram: WebGL Maps for Vector Data

Circle CI

tangram-header

Tangram is a JavaScript library for rendering 2D & 3D maps live in a web browser with WebGL. It is tuned for OpenStreetMap but supports any source of GeoJSON/TopoJSON or binary vector data, including tilesets and single files.

Here's a simple demo (repo here) with a basic example of a Tangram map.

Tangram is instantiated as a Leaflet plugin for integration with standard web maps. Tangram ES is a native mobile version of the Tangram library, written in C++.

Getting Started

Tangram is published in two build flavors: one for current browsers (bundled as an ES module, using modern JS and web platform features), and one for older browsers (specifically IE11, with modern JS transpiled to older ES5 syntax). You can use this snippet to automatically load the best one for your browser, using the module/nomodule pattern:

<!-- modern browsers load the optimized .mjs file, older browsers (IE11) load the transpiled .js file -->
<script type="module" src="https://unpkg.com/tangram/dist/tangram.min.mjs"></script>
<script nomodule src="https://unpkg.com/tangram/dist/tangram.min.js"></script>

Note: Because scripts with the module type automatically load in "deferred" mode, you must make sure to include the defer keyword for any scripts you load that depend on Tangram (so that they won't run until Tangram is finished loading). For example, if your app code is in index.js, load it like this (anywhere after the Tangram <script> tag):

<script defer src="index.js"></script>

Specific Tangram library versions can also be loaded with @version syntax(see unpkg for details). Versions earlier than v0.16.0 do not use the module syntax; use a single script tag to load them instead: <script src="https://unpkg.com/tangram@0.15.5/dist/tangram.min.js"></script>.

Tangram is published on NPM and can be bundled using import or require.

The library includes a Leaflet plugin, Tangram.LeafletLayer, to provide basic web map pan/zoom functionality.

Data sources, layers, and styling rules are written in a scene file (here's an example). Armed with a scene file like scene.yaml, you can create a Tangram scene and add it to a Leaflet map like so:

var map = L.map('map');
var layer = Tangram.leafletLayer({ scene: 'scene.yaml' });
layer.addTo(map);

Read on for more info, or see the documentation (github repo).

Demos

simple-demo - A minimal demo showing the basic setup

highways-demo - Zoom-dependent styles and contextual filtering rules

gui-demo - Control styles in real-time with a gui

shaders-demo - Simple glsl shaders

Tangram-sandbox - More complex glsl shaders

More examples are available here.

Vector Tiles

Instead of loading traditional bitmap tiles, Tangram draws its own tiles from scratch, based on vector tiles that contain the source data.

Nextzen provides a free vector tile service based on open data from OpenStreetMap, Natural Earth, Who's On First and other projects, with worldwide coverage updated continuously -- sign up for an API key here.

Tangram currently supports GeoJSON & TopoJSON-based tiles, as well as Mapbox's MVT binary format.

Styling

The scene file is where you specify data sources and layers, filter the data, and define and apply styles. (In our demos, this file is named scene.yaml.) The rules for doing these things are many and various, but the basics are pretty easy, and they are all meticulously documented in the Tangram Documentation.

The scene file is written in YAML, which is a data-serialization format like JSON, but with less punctuation. Instead, data structures are specified with whitespace, like Python. One neat side benefit is that the format is super friendly to strings, which means you can write inline JavaScript and GLSL code straight into the scene file, without needing to wrap it in quotes or concatenate anything.

Support

For technical reference and concept overviews, see the Tangram Documentation.

For questions, comments, suggestions, or to report a bug, please open a new issue.

You can also find us in the Tangram-chat gitter room: https://gitter.im/tangrams/tangram-chat

Browser Support

Tangram JS is officially supported and tested on the last two versions of these browsers:

  • Mac OS: Chrome, Firefox, and Safari
  • Windows: Chrome, Firefox, IE11, and Edge
  • iOS: Safari
  • Android: Chrome

Tangram JS should also run in any browser with WebGL support.

Contributions Welcome

Tangram is open-source, and we eagerly welcome feedback, feature requests, and contributions. WeҀ™re especially interested to see your maps, no matter how simple! Post screenshots, links, and any questions to our gitter chat.

For instructions, see CONTRIBUTING.md.

Tangram JS was created by Mapzen and is now a Linux Foundation Project.