|
| 1 | +--- |
| 2 | +id: mapml-viewer |
| 3 | +title: <mapml-viewer> |
| 4 | +slug: /maps/mapml-viewer |
| 5 | +--- |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +The `<mapml-viewer>` element is the main element you can use to put a custom Web map on your page. To create a (really) simple Web map, you might use it like this: |
| 10 | + |
| 11 | +```html |
| 12 | +<!DOCTYPE html> |
| 13 | +<html lang="en"> |
| 14 | + <head> |
| 15 | + <meta charset="utf-8" /> |
| 16 | + <title>A Simple Web Map[tm]</title> |
| 17 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 18 | + <script type="module" src="web-map/mapml-viewer.js"></script> |
| 19 | + </head> |
| 20 | + <body> |
| 21 | + <mapml-viewer projection="OSMTILE" zoom="0" lat="0.0" lon="0.0" controls> |
| 22 | + <layer- label="OpenStreetMap" src="https://geogratis.gc.ca/mapml/en/osmtile/osm/" checked></layer-> |
| 23 | + </mapml-viewer> |
| 24 | + </body> |
| 25 | +</html> |
| 26 | +``` |
| 27 | +Note that for the above example to run properly on your own site, you need to get a built copy of the `<mapml-viewer>` project in your site's folder. In the example, the `<mapml-viewer>` files are copied into the folder named "web-map" in your site root folder. Your own site's path to these files will depend on how you structure your folders. |
| 28 | + |
| 29 | +`<mapml-viewer>` is an "[autonomous custom element](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)" in HTML. You can distinguish a custom element of any category from a "native" HTML element by the "-" anywhere in the element name. Autonomous custom elements are supported by all modern browsers, but don't work in old browsers (e.g. Internet Explorer and old Edge). |
| 30 | + |
| 31 | +The `<mapml-viewer>` element has several attributes to control the presentation and initial location of the map. |
| 32 | + |
| 33 | +### Attributes |
| 34 | + |
| 35 | + |
| 36 | +`projection` - an enumerated attribute. Case-sensitive values are: "`OSMTILE`", "`WGS84`", "`CBMTILE`" and "`APSTILE`". |
| 37 | + |
| 38 | + - `OSMTILE` corresponds to the widely-used "Web Mercator" projected coordinate reference system, implying a "tile pyramid" zoom range from 0 to 23 (minimum tile size ~2.4m). |
| 39 | + |
| 40 | + - `WGS84` provides an implementation of the "pseudo plate carée" projected coordinate reference system, wherein the easting and northing axis units are decimal degrees (not meters). In `WGS84`, zoom level 0 contains two tiles that each cover a hemisphere of Earth's surface. `WGS84` is defined with 21 zoom levels (0 to 20). |
| 41 | + |
| 42 | + - `CBMTILE` is the de facto standard grid layout for the Canadian Geospatial Data Infrastructure (CGDI), defined by Natural Resources Canada, and is based on the Lambert Conformal Conic projection (EPSG:3978). Zoom levels are based on a numeric map scale denominator (e.g. 10000 corresponding to a map scale of 1:10,000), with a particular pixel resolution selected, and as a result, successive zoom levels' tiles do not nest exactly (as they do in `OSMTILE`, `WGS84` and `APSTILE`). |
| 43 | + |
| 44 | + - `APSTILE` is based on the Alaska Polar Stereographic (EPSG:5936) projected coordinate reference system, and has 20 zoom levels (0 to 19). |
| 45 | + |
| 46 | + - other projections are possible, using the "[Custom Projections](https://github.com/Maps4HTML/Web-Map-Custom-Element/blob/8723e4d8bad8e3629bc9dca7a6fe81d724e8418f/demo/CustomProjection.html#L1-L158)" API |
| 47 | + |
| 48 | +`zoom` - a non-negative integer. The value establishes the initial zoom level of the map. For a small scale view of the world, use a lower value. Use larger values for larger scales (smaller area maps). The maximum value depends on the particular `projection` and data source. Many map data sources have limited zoom levels available. |
| 49 | + |
| 50 | +`lat` - a real number latitude. The value establishes the initital latitide of the of the center of the map. Latitudes on Earth range from -90.0 (south) to 90.0 (north). Many projections are not able to display all latitudes, and most projections have a limited range of locations where distortion is controlled or limited. In particular, OSMTILE (Web Mercator) can only display content between the latitude range -84 to 84. |
| 51 | + |
| 52 | +`lon` - a real number longitude. The value establishes the initital longitude of the of the center of the map.Longitudes on Earth range from -180.0 (west) to 180.0 (east). Similar comments related to distortion apply to those for latitude. Be careful, this attribute is named "lon" NOT "long", and if you use "long" your map won't work properly. |
| 53 | + |
| 54 | +`controls` - a "boolean" attribute. Turns map controls on (if present) or off (if omitted). In HTML "boolean" attributes don't have values of "true" or "false" per se - they have the implied value of "true" if the attribute exists, and an implied value of "false" if the attribute is not present. Sometimes the default map controls may not be useful for your map, so you may turn them off and design your own. |
| 55 | + |
| 56 | +`controlslist` - an enumerated attribute, possible values are: "`nofullscreen`", "`nolayer`", "`noreload`" and "`nozoom`". Occasionally, you may not want your users to have access to a particular control, so you may prune the set of controls automatically presented (when you have used the `controls` boolean attribute). |
0 commit comments