Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kambrium/staticmapservice
A web service that generates static maps
https://github.com/kambrium/staticmapservice
api generator map python service static
Last synced: 1 day ago
JSON representation
A web service that generates static maps
- Host: GitHub
- URL: https://github.com/kambrium/staticmapservice
- Owner: kambrium
- License: mit
- Created: 2018-10-21T13:09:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T20:25:32.000Z (over 1 year ago)
- Last Synced: 2024-08-12T03:06:33.325Z (3 months ago)
- Topics: api, generator, map, python, service, static
- Language: Python
- Size: 60.5 KB
- Stars: 18
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
staticmapservice - A web service that generates static maps
===========================================================![staticmapservice logo](logo.png)
About
-----
staticmapservice is a configurable web service written in Python that generates static maps similar to the Maps Static API by Google. Essentially this software is a [Flask](http://flask.pocoo.org/) wrapper around the Python library [staticmap](https://github.com/komoot/staticmap). At the moment, this software can generate static maps based on XYZ tiles (e.g. [OpenStreetMap based data](https://wiki.openstreetmap.org/wiki/Tile_servers)) and TMS tiles with circle markers, polylines, polygons and icons.Quick start
-----------
1. Create a venv and activate it.
```
python3 -m venv /path/to/venv/of/staticmapservice
source /path/to/venv/of/staticmapservice/bin/activate
```
2. Upgrade pip. This is necessary because one of the dependencies of staticmapservice, the library [staticmap](https://github.com/komoot/staticmap), can't be installed with older versions of pip.
```
pip install --upgrade pip
```
3. Clone staticmapservice and change to the application directory.
```
git clone https://github.com/kambrium/staticmapservice
cd staticmapservice
```
4. Install requirements.
```
pip install -r requirements.txt
```
5. Export the FLASK_APP variable and run the software.
```
export FLASK_APP=staticmapservice.py
flask run
```
6. In your browser, send a request with some query parameters to the API. Here's an example that should work:
```
http://127.0.0.1:5000/?w=400&h=300&z=9&marker=coords:48.25,11.22|diam:10|color:%233F33FF
```
As a response you should get a static map of southern Bavaria with a blue marker next to the city of Munich. See below for a detailed list of currently supported query parameters.Query parameters
----------------
This is a list of currently supported query parameters. Please see below for working example requests.| Parameter | Meaning |
| --- | --- |
| w | Width of the map (in pixels) |
| h | Height of the map (in pixels) |
| z | Zoom level |
| center | Coordinate of the center of the map (one lat/lon pair) |
| marker | Properties of a circle marker separated by `\|`: coordinates (`coords`, one lat/lon pair), diameter (`diam`, in pixels) and color (`color`, hexadecimal code, # encoded as %23) |
| line | Properties of a polyline separated by `\|`: coordinates (`coords`, multiple lat/lon pairs), width (`width`, in pixels) and color (`color`, hexadecimal code, # encoded as %23) |
| polygon | Properties of a polygon separated by `\|`: coordinates (`coords`, multiple lat/lon pairs), fill and outline color (`fcolor`, `ocolor`, hexadecimal codes, # encoded as %23) |
| icon | Properties of an icon marker separated by `\|`: coordinates (`coords`, one lat/lon pair), name of the icon (`name`, must be identical with the name of the icon file to be displayed, icons must be stored in the folder ./icons) and offset (`offx`, `offy`, in pixels) |Examples
--------
Here are some examples how to use staticmapservice.### Map with marker
The following request creates a 400 pixels wide and 300 pixels high map. The zoom level is 9. A marker is set at 48.25 (latitude) and 11.22 (longitude). The marker has a diameter of 10 pixels and the color #3F33FF (blue).
```
http://127.0.0.1:5000/?w=400&h=300&z=9&marker=coords:48.25,11.22|diam:10|color:%233F33FF
```### Map with line
The following request creates a 500 pixels wide and 500 pixels high map. The zoom level is 8. A line will be drawn between a point at 48.2 (latitude), 11.2 (longitude) and another point at 47.5, 11. The line has a width of 4 pixels and the color #CD0000 (red).
```
http://127.0.0.1:5000/?w=500&h=500&z=8&line=coords:48.2,11.2;47.5,11|width:4|color:%23CD0000
```### Map with polygon
The following request creates a 400 pixels wide and 600 pixels high map. The zoom level is 5. A polygon will be drawn between the three points 48.2 (latitude), 11.2 (longitude), 47.5, 11 and 47.9, 12. The polygon is filled with the color #CD0000 (red) and its outline is #000000 (black).
```
http://127.0.0.1:5000/?w=400&h=600&z=5&polygon=coords:48.2,11.2;47.5,11;47.9,12;48.2,11.2|fcolor:%23CD0000|ocolor:%23000000
```### Map with icon
The following request creates a 400 pixels wide and 300 pixels high map. The zoom level is 9. A flag icon is set at 48.25 (latitude) and 11.22 (longitude). The offset of the icon is 15 pixels to the right and 10 pixels upwards.
```
http://127.0.0.1:5000/?w=400&h=300&z=9&icon=coords:48.25,11.22|offx:15|offy:10|name:flag
```### Using defaults
Some parameters get default values from the configuration file (see below). That's why this is a valid request:
```
http://127.0.0.1:5000/?marker=coords:48.25,11.22|diam:10|color:%233F33FF
```### Multiple markers, lines, polygons and/or icons
The application can handle multiple markers, lines, polygons and/or icons per map. The following request creates a map with a marker and a line.
```
http://127.0.0.1:5000/?marker=coords:48.25,11.22|diam:10|color:%233F33FF&line=coords:48.2,11.2;47.5,11|width:4|color:%23CD0000
```### Map with custom center
The center of a map can be altered by adding a custom center coordinate to the request.
```
http://127.0.0.1:5000/?w=400&h=300&z=9&marker=coords:48.25,11.22|diam:10|color:%233F33FF¢er=48,11.7
```Configuration
-------------
This application can be configured with the `config.py` file. Examples for configurable parameters are the maximum size of a map, the URL of the tile server or the maximum amount of points, nodes and vertices per request. See the file `config.py` for a complete list of all configurable parameters.License
-------
MIT