Skip to content

Commit

Permalink
update readme and example for nextzen
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed Oct 7, 2018
1 parent 6b58841 commit 4bbf3d4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
sudo: false
go:
- 1.10.x
- 1.11.x

install:
- go get -v github.com/paulmach/osmzen
Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The goal is for there to be no functional differences for zooms 14+. The YAML de
unchanged, there a just a few minor changes to the post processor filtering in `queries.yaml`. See
the [github diff](https://github.com/tilezen/vector-datasource/compare/master...paulmach:master).

The port is based off of [v1.4.3ish](https://github.com/tilezen/vector-datasource/releases/tag/v1.4.3)
The port is based off of [v1.5.0ish](https://github.com/tilezen/vector-datasource/releases/tag/v1.5.0)
version of the vector-datasource. The [fork](https://github.com/paulmach/vector-datasource) or the
[github diff](https://github.com/paulmach/vector-datasource/compare/master...tilezen:master) between
it and upstream/master are kept at the intended "reference".
Expand Down Expand Up @@ -66,13 +66,23 @@ Usage
2. Process some OSM data:

data := osm.OSM{}
layers, err := config.Process(data, geo.Bound(-180, 180, -90, 90), zoom)
layers, err := config.Process(
data,
orb.Bound{Min: orb.Point{-180, -90}, Max: orb.Point{180, 90}},
zoom,
)

// layers is defined as `map[string]*geojson.FeatureCollection`

Layers can also be processed individually:

featureCollection, err := config.Layers["buildings"].Process(data, zoom)
featureCollection, err := config.Layers["buildings"].Process(
data,
orb.Bound{Min: orb.Point{-180, -90}, Max: orb.Point{180, 90}},
zoom,
)

The bound is necessary for clipping. Typically set to the bound of the requested tile.

The result is a GeoJSON feature collection with `kind`, `kind_detail` etc. properties that
are understood by [Mapzen house styles](https://mapzen.com/products/maps/).
Expand Down Expand Up @@ -123,7 +133,7 @@ Implementation details
----------------------

At a high level [tilezen/vector-datasource](https://github.com/tilezen/vector-datasource) filters and
process's its data using the following steps:
processes its data using the following steps:

1. find relevant elements for a layer using the SQL queries defined in `data/{layer_name}.jinja`,
2. filter the elements using filter *conditions* defined in `yaml/{layer_name}.yaml`,
Expand Down Expand Up @@ -191,8 +201,7 @@ While loading the config the **transforms** are matched to functions of the form
Transforms can only change a feature, they can't remove a feature if it's "bad" for any reason, like
too small for the zoom. Transforms also don't know about other features so they can't be used to
remove duplicates or merge features, like parts of the same road. However, transforms can be used to
do things like fix one-way direction, add the correct highway shield text, abbreviate road names,
etc.
do things like fix one-way direction, abbreviate road names, etc.

The **post processes** are compiled to check the parameters and data files. They are mapped to an
object implementing the `postprocess.Function` interface defined as:
Expand Down
64 changes: 29 additions & 35 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<title>osmzen example</title>

<link rel="stylesheet" href="https://mapzen.com/js/mapzen.css">
<link rel="stylesheet" href="https://www.nextzen.org/js/nextzen.css">
<style>
body {
margin: 0px;
Expand All @@ -25,44 +25,38 @@
<body>
<div id="map"></div>

<script src="https://mapzen.com/tangram/0.14/tangram.min.js"></script>
<script src="https://mapzen.com/js/mapzen.min.js"></script>
<script src="https://www.nextzen.org/tangram/0.15/tangram.min.js"></script>
<script src="https://www.nextzen.org/js/nextzen.min.js"></script>
<script>
var mapzenApiKey = 'mapzen-fozgx4f';
var map = L.map('map'),
layer = Tangram.leafletLayer({
// scene: L.Mapzen.BasemapStyles.BubbleWrap,
// scene: L.Mapzen.BasemapStyles.BubbleWrapMoreLabels,
// scene: L.Mapzen.BasemapStyles.Cinnabar,
scene: L.Mapzen.BasemapStyles.CinnabarMoreLabels,
// scene: L.Mapzen.BasemapStyles.Walkabout,
// scene: L.Mapzen.BasemapStyles.WalkaboutMoreLabels,

attribution: '<a href="https://mapzen.com/" target="_blank">Mapzen</a> | &copy; OSM contributors',
minZoom: 15,
maxZoom: 18,
});

layer.scene.subscribe({
load: function (e) {
var mapzen = e.config.sources.mapzen;
mapzen.url_params.api_key = mapzenApiKey;

mapzen.type = 'GeoJSON';
mapzen.url = window.location.origin + '/tiles/{z}/{x}/{y}.json'

mapzen.max_zoom = 15;
mapzen.max_zoom = 16;
mapzen.min_display_zoom = 15;
mapzen.max_display_zoom = 18;
var map = L.Nextzen.map('map',
{
minZoom: 15,
maxZoom: 18,
attribution: '<a href="https://github.com/tangrams" target="_blank">Tangram</a> | <a href="http://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a> | <a href="https://www.nextzen.org/" target="_blank">Nextzen</a>',
tangramOptions: {
scene: {
import: [
'https://www.nextzen.org/carto/bubble-wrap-style/9/bubble-wrap-style.zip',
'https://www.nextzen.org/carto/bubble-wrap-style/9/themes/label-10.zip'
],
sources: {
mapzen: {
type: 'GeoJSON',
url: window.location.origin + '/tiles/{z}/{x}/{y}.json',
tile_size: 256,
min_zoom: 15,
max_zoom: 16,
min_display_zoom: 15,
max_display_zoom: 18
}
}
}
}
}
});

);

layer.addTo(map);
map.setView([37.82502, -122.25466], 17);

L.Mapzen.hash({ map: map });
L.Nextzen.hash({ map: map });
</script>
</body>
</html>
10 changes: 5 additions & 5 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"encoding/json"
"io/ioutil"
"log"
Expand Down Expand Up @@ -48,8 +47,9 @@ func main() {
// get the osm data for that bound
data, err := osmapi.Map(r.Context(), bound)
if err != nil {
if err == context.Canceled {
w.WriteHeader(500)
if err := r.Context().Err(); err != nil {
// what if not "context canceled"?
http.Error(w, err.Error(), 500)
return
}

Expand All @@ -58,9 +58,9 @@ func main() {

// Process the data into mapzen vector tiles format
layers, err := config.Process(
data, // osm data
data, // osm data
geo.BoundPad(tile.Bound(), 100), // clip the geometries to this bound, add 100 meters of padding.
tile.Z, // zoom, used to leave out things when zoomed out. Doesn't do much in this context.
tile.Z, // zoom, used to leave out things when zoomed out. Doesn't do much in this context.
)
if err != nil {
w.Write([]byte(err.Error()))
Expand Down

0 comments on commit 4bbf3d4

Please sign in to comment.