Skip to content

Commit

Permalink
Restructure and rename elements in the sidebar
Browse files Browse the repository at this point in the history
Add User Guide
Move Tutorials to be a child of User Guide
Rename Advanced to Styling
Add pmtiles styles section to user guide
Update <map-link type>, rel attribute docs
Point "GitHub" link to web-map-doc repo
Pare down tutorial stubs
Finalize review of translated styling tutorial
  • Loading branch information
prushfor authored and prushforth committed Aug 30, 2024
1 parent 3a2ff3d commit 1ac1ce8
Show file tree
Hide file tree
Showing 17 changed files with 708 additions and 33 deletions.
17 changes: 14 additions & 3 deletions docs/elements/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ maps. Most of the extensions center on proposed new values of the `rel` attribu
- provide links to alternate projections for a layer, via the `alternate` rel value, in conjunction with the `projection="..."` attribute. Such links are automatically followed by the polyfill when appropriate.
- provide a URL template that is processed and converted to a URL and fetched by the polyfill, each time the map requires new content to render, such as a tile, via the `tile`, `image`, `feature` and `query` rel values, in conjunction with the `tref="..."` attribute. Such links are automatically created and followed / imported when appropriate.
- include links to legend graphics for a layer. Currently such links are rendered as hyperlinks, not as graphics.
- provide links to CSS stylesheets via the `stylesheet` rel value, which are imported by the polyfill automatically.
- provide links to CSS and pmtiles stylesheets via the `stylesheet` rel value, which are imported by the polyfill automatically.
- provide links to layers at next native zoom level via `zoomin`, `zoomout` rel values. Such links are automatically followed by the polyfill when appropriate.

<!-- demo / example -->
Expand All @@ -41,7 +41,7 @@ defines several uses of existing and new `rel` keyword values.
| `zoomout` | The link `href` is followed automatically by the polyfill when the map is zoomed out by the user to a value less than the minimum value of the zoom range of the current layer. The referenced map layer resource replaces the current map layer. The polyfill does not represent this link as a user-visible affordance, it is followed automatically. If the remote resource does not contain a reciprocal `zoomin` link, the map state change is one-way i.e. the layer is permanently replaced. |
| `legend` | The `legend` link relation designates a link to metadata, typically an image, describing the symbology used by the current layer. Currently, the polyfill creates a hyperlink for the label of the layer in the layer control, which opens in a new browsing context. |
| `query` | The `query` link relation is used in combination with the `tref="..."` attribute to establish a URL template that composes a map query URL based on user map gestures such as click or touch. These URLs are fetched and the response presented on top of the map as a popup. Such queries can return text/html or text/mapml responses. In the latter case, the response may contain more than one feature, in which case a 'paged' popup is generated, allowing the user to cycle through the features' individual metadata. |
| `stylesheet` | The link imports a CSS stylesheet from the `href` value. |
| `stylesheet` | The link imports a CSS or [pmtiles](../../user-guide/creating-styles) stylesheet from the `href` value. |


---
Expand All @@ -53,7 +53,18 @@ The `type` attribute defines the expected
of the remote resource. Depending on the [`rel` value](#rel), the `type` may play a significant role in determining
the polyfill behaviour.

Common values of `type` include **text/html**, **text/mapml**, and **image/\***.
Supported values of `type` and function

| Value | Description |
|-------------- |-------------------------------------------------------- |
| `text/mapml` | Use in combination with `rel=tile` or `rel=features`, where `tref` refers to a MapML formated data source, often [GeoServer](https://docs.geoserver.org/latest/en/user/extensions/mapml/index.html) or other spatial content management system.|
| `text/mapml` | Use in combination with `rel=self`, `rel=style` and `rel="self style"`, where `href` refers to an alternate or current style of the current MapML document. Supported by [GeoServer](https://docs.geoserver.org/latest/en/user/extensions/mapml/installation.html#styles), but can be readily created in static (remote-only) MapML documents|
| `image/*` | Use in combination with `rel=image` and `rel=tile` to load full-viewport map images and image tiles, respectively, when `tref` refers to an image-based data source, such as any Web Map Service or Web Map Tile Service. See [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types) for a list of supported types.|
| `application/pmtiles` | Use in combination with `rel=tile`, where `tref` refers to [pmtiles format](https://docs.protomaps.com/pmtiles/) or map resources. * |
| `application/pmtiles+stylesheet` | Use in combination with `rel=stylesheet`, where `href` refers to a JavaScript module structured in a specific way. * |
| `application/vnd.mapbox-vector-tile` | Use in combination with `rel=tile`, where `tref` refers to a [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec)-format so-called "{z}{x}{y}" [Web Map Tile Service](https://docs.geoserver.org/latest/en/user/extensions/vectortiles/tutorial.html) or [API](https://protomaps.com/other). * |

\* see [Using mvt styles](../../user-guide/using-styles) for details on how to use these `type` values

---
### `title`
Expand Down
196 changes: 196 additions & 0 deletions docs/user-guide/creating-styles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
id: creating-styles
title: Creating custom mvt styles
slug: /user-guide/creating-styles
---

## What are mvt files

[Mapbox vector tiles (mvt)](https://github.com/mapbox/vector-tile-spec) files are a de facto standard encoding of map data optimized for rendering to HTML canvas element(s) via JavaScript and/or JSON-based encoded style information. Cascading Style Sheet rules do not apply, because mvt content is not exposed via browser APIs, so
style rules, while [sort-of declarative](https://glazkov.com/2024/01/16/declarative-vs-imperative/), are implemented in script.

## What are pmtiles files

[pmtiles](https://docs.protomaps.com/pmtiles/) is a map tile archive format that is intended to obviate (some of) the need for complex geospatial-specific servers and APIs for tile resources on the web, to enable people to create their own localized web map sites without having to host the whole world on their domain. The pmtiles archive format contains metadata that can be requested via http byte range requests, and subsequent requests for individual tiles are also sent as byte range requests.

The pmtiles map archive and mvt [formats](../elements/link#type) in the MapML polyfill are integrated via
[the protomaps-leaflet library](https://docs.protomaps.com/pmtiles/leaflet). Protomaps-leaflet is designed to support the (de facto standard) Web Mercator tile grid. This allows
the MapML polyfill to integrate support for pmtiles and mvt data sources for only the `OSMTILE` projection. `<layer->` and `<map-extent>` elements and the `<mapml-viewer>` will
not work (and will be permanently `disabled`) when used with `<mapml-viewer projection="ANYTHING"...>` or `<map-extent units="ANYTHING"...>` values apart from `OSMTILE`.

Before proceeding below, you should read the [protomaps-leaflet](https://docs.protomaps.com/pmtiles/leaflet#custom-vector-data) documentation on custom styling.
Another useful source of information for styling includes [the source code examples](https://github.com/protomaps/protomaps-leaflet/tree/main/examples).

Working examples of `<mapml-viewer>` usage of themes and styles are [available on-line](https://maps4html.org/experiments/vector-tiles/pmtiles/), with available [source code](https://github.com/Maps4HTML/experiments/tree/main/vector-tiles/pmtiles).

## How to create a stylesheet module

A pmtiles stylesheet used in the MapML polyfill is a JavaScript module source file which exports a
single symbol, which **must be** named `pmtilesRules`:

```javascript
const pmtilesRules = new Map();
...
pmtilesRules.set(
'https://maps4html.org/experiments/vector-tiles/pmtiles/spearfish.pmtiles?theme=light',
{ theme: { theme: 'light' } }
);
...
export { pmtilesRules };
```
:::tip

Pre-defined themes that you can use include: `light`, `dark`, `white`, `grayscale` and `black`. You should include the theme name in the URL template as a parameter (even though it is not required by the pmtiles or mvt resource), so that the URL template can be made unique and distinct from other pmtilesRules keys' use of the same pmtiles or mvt resource.

:::

The `pmtilesRules` export must be a [JavaScript Map-type object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), structured as follows:

- must have a unique URL template string key that will be used on the web to identify a set of rules
- has an object value that has a `theme` or a `rules` property
- `theme` property must be an object literal, itself with a `theme` property with a string theme name value: `{theme:{theme:'grayscale'}}`
- `rules` property must be an object literal, with `PAINT_RULES: [...]` and/or a `LABEL_RULES: [...]` array-valued properties
- `PAINT_RULES` and `LABEL_RULES` are arrays of objects that have required `dataLayer` and `symbolizer` properties
- `PAINT_RULES` and `LABEL_RULES` can have optional properties e.g. `filter`, `minzoom`, `maxzoom`
- `dataLayer` is a string property that is the name of a layer encoded in the mvt data
- `symbolizer` is property of `Symbolizer`-type value

An example custom pmtiles stylesheet module for a localhost GeoServer 'spearfish' Layer Group (set up with a mvt tile cache) is as follows:

```javascript
class SpearfishSymbolizer {
constructor(options) {
this.color = options.color;
this.shape = options.shape;
}
draw(context, geom, z, feature) {
let pt = geom[0][0];
context.fillStyle = this.color;
context.strokeStyle = this.color;
context.beginPath();
if (this.shape === 'circle') {
context.arc(pt.x, pt.y, 3, 0, 2 * Math.PI);
} else {
context.rect(pt.x - 2, pt.y - 2, 4, 4);
}
context.stroke();
context.fill();
}
}
const pmtilesRules = new Map();
pmtilesRules.set(
'http://localhost:8080/geoserver/gwc/service/wmts/rest/spearfish/OSMTILE/{z}/{y}/{x}?format=application/vnd.mapbox-vector-tile',
{
rules: {
PAINT_RULES: [
{
dataLayer: 'streams',
symbolizer: new M.protomapsL.LineSymbolizer({ color: 'steelblue', width: 2 })
},
{
dataLayer: 'roads',
symbolizer: new M.protomapsL.LineSymbolizer({ color: 'maroon', width: 2 })
},
{
dataLayer: 'restricted',
symbolizer: new M.protomapsL.PolygonSymbolizer({
fill: 'red',
opacity: 0.5
})
},
{
dataLayer: 'restricted',
symbolizer: new M.protomapsL.LineSymbolizer({ color: 'red', width: 2 })
},
{
dataLayer: 'archsites',
symbolizer: new SpearfishSymbolizer({
color: 'red',
shape: 'square'
})
},
{
dataLayer: 'bugsites',
symbolizer: new SpearfishSymbolizer({
color: 'black',
shape: 'circle'
})
}
],
LABEL_RULES: [
{
dataLayer: 'archsites',
symbolizer: new M.protomapsL.CenteredTextSymbolizer({
labelProps: ['str1'],
fill:'white',
width:2,
stroke:'black',
font:"600 16px sans-serif"
}),
// note that filter is a property of a rule, not an option to a symbolizer
filter: (z,f) => { return f.props['str1'].trim().toLowerCase() !== 'no name'; }
}
]
}
}
);
export { pmtilesRules };
```

## Available imported symbols from protomaps-leaflet

The following imports from protomaps-leaflet are available on the `M.protomapsL` global variable e.g. `M.protomapsL.CenteredSymbolizer`, for use by your stylesheets:

```javascript
/*
CenteredSymbolizer,
CenteredTextSymbolizer,
CircleSymbolizer,
FlexSymbolizer,
Font,
GeomType,
GroupSymbolizer,
IconSymbolizer,
Index,
Justify,
Labeler,
Labelers,
LineLabelPlacement,
LineLabelSymbolizer,
LineSymbolizer,
OffsetSymbolizer,
OffsetTextSymbolizer,
Padding,
PmtilesSource,
PolygonSymbolizer,
Sheet,
ShieldSymbolizer,
Static,
TextPlacements,
TextSymbolizer,
TileCache,
View,
ZxySource,
arr,
covering,
createPattern,
exp,
getZoom,
isCcw,
isInRing,
labelRules,
leafletLayer,
linear,
paint,
paintRules,
pointInPolygon,
pointMinDistToLines,
pointMinDistToPoints,
sourcesToViews,
step,
toIndex,
transformGeom,
wrap
*/
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: getting-started
title: MapML Introduction
slug: /tutorials/getting-started
slug: /user-guide/getting-started
---

To make a web map, all you need is a little bit of knowledge of HTML, some of which you can find here. You will find that HTML is a language that fills a bigger role for you as your knowledge of it grows. There are many excellent free resources available on the web for learning HTML in all its richness. We will try to give you what you need to get started with maps here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: mapml-files
title: Working with MapML Files
slug: /tutorials/mapml-files
slug: /user-guide/mapml-files
---

:::info
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: modifying-map
title: Modifying the Map
slug: /tutorials/modifying-map
slug: /user-guide/modifying-map
---

:::info
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
id: quick-start
title: MapML Quick Start Guide
slug: /tutorials/quick-start
slug: /user-guide/quick-start
---

Learn how to quickly create your first map.
Expand Down
Loading

0 comments on commit 1ac1ce8

Please sign in to comment.