# WeatherNow **Repository Path**: mirrors_tangrams/WeatherNow ## Basic Information - **Project Name**: WeatherNow - **Description**: OpenWeatherMap experiment with Tangram - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: gh-pages - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-26 - **Last Updated**: 2026-03-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Using 3er Party APIs on Tangram This guide provides an example of how to use the [Tangram maps engine](https://github.com/tangrams/tangram) with other 3rd party APIs. It's written for an audience with some technical knowledge about JavaScript, [OpenStreetMap](http://leafletjs.com/) data and [Mapzen vector tiles](https://mapzen.com/projects/vector-tiles). It is best if you have some previous experience editing [Tangram's](https://github.com/tangrams/tangram) [```.yaml``` scene files](https://mapzen.com/documentation/tangram/Scene-file/). In case you don't, don't worry! A good place to start is explore the examples using [TangramPlay](https://mapzen.com/tangram/play/), our online editor, and reading [Tangram Documentation](https://mapzen.com/documentation/tangram/), specially following this nice [walkthrough of how to make a Tangram map](https://mapzen.com/documentation/tangram/walkthrough/#put-your-tangram-map-on-the-web). Also feel free to clone this repository in your computer, run it as a local server and make it your own. Tweaking and modifying is the best way to learn. How? Type this on your command line: ```bash git clone https://github.com/tangrams/OWM.git python -m SimpleHTTPServer 8000 ``` If that doesn’t work, try: ```bash python -m http.server 8000 ``` To view the content on your browser, navigate to: [http://localhost:8000](http://localhost:8000) ***Note:*** Please keep in mind that this example use one free API Key for [OpenWeatherMap service](http://openweathermap.org/api). If you get carried away using it, there is the chance you will run out of calls to the servers. In that case it is probably time to get your own free API key. ### Before starting Take a moment to look the files inside this repository and see how they relate to each other. You will note: - There is a **JS file** (```main.js```) file that loads [Leaflet](http://leafletjs.com/) map and a [Tangram Layer](https://github.com/tangrams/tangram) on top of it. This file also makes API calls to [OpenWeatherMap server](http://openweathermap.org/api), asking for weather station data every time the user finishes moving the map. The responses to this calls are transformed into [GeoJSON](http://geojson.org/) to be passed to [Tangram engine](https://github.com/tangrams/tangram) for rendering and display. - The **YAML file** (```scene.yaml```) is a scene file that will tell Tangram.js how to style the map and make sense of the weather station data. - the **HTML file** (```index.html```) is the glue that holds it all together. It contains a ```
``` holder for the map, a minimal amount of CSS styling, together with the calls to the JavaScript files needed for this project. The rest of the files on this repository are not strictly necessary for this example. - The ```README.md``` is the guide you are reading. - The ```LICENSE``` file is the [MIT License](https://opensource.org/licenses/MIT) we add to all our work here at [Mapzen](https://mapzen.com/). ### Inside ```index.html``` Let's jump inside and take a look at the glue that holds everything together to be served to browsers, the ```index.html``` file. Although it was almost self-explanatory, let's do a brief recap of some of its important components: #### Dependencies ```html ``` This is our tool box, the set of libraries (hosted somewhere else) that we are going to use to compose our map. Which are they? What they do? - [**Leaflet**](http://leafletjs.com/): this leading open-source JavaScript library for interactive maps is probably one of our best friends. There is a big community around it. Is easy to use, well documented and incredible flexible. Note how we are adding both ```leaflet.js``` and ```leaflet.css``` of the version ```v1.0.0-beta.2```. - [Michael Lawrence Evans's](https://github.com/mlevans) [**Leaflet Hash plugin**](https://github.com/mlevans/leaflet-hash) adds dynamic URL hashes to Leaflet maps. In other words it will let us easily let users link to specific map views. - [**Tangram**](https://mapzen.com/projects/tangram) ```0.5``` version: Our beloved and flexible browser-based mapping engine, designed for real-time rendering of 2D and 3D maps from vector tiles. [Learn more here](https://mapzen.com/documentation/tangram/). - [**Fetch**](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) is a more powerful and flexible coming version of [```XMLRequest```](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest). Because is not supported by all browsers yet, we are using [Github's polyfill](https://github.com/github/fetch) of it. Hopefully in a near future this will not be necessary. #### Styling ```html ``` The main idea here is to use all the space on your browser to display the map. **Note**: the map is going to be placed on the ```
``` element with the ```id``` name ```map```. #### The beating heart ```html
``` As we noted previously, the [Leaflet](http://leafletjs.com/) map with the [Tangram](https://mapzen.com/projects/tangram) layer is going to be loaded inside the ```
``` element with the ```map``` id. Where and when does that happens? Immediately after the ```
``` is created the ```main.js``` script is loaded. Soon we will see what this JavaScript do. #### Mapzen's standard features The rest of the HTML code in ```index.html``` are a bunch of standard lines we add to all our demos. ```html ``` This lines keeps our maps looking good and healthy when they are loaded as ```