SMK Usage Guide

A versatile and lightweight toolkit for building a simple web map.

This project is maintained by qqnluaq

SMK / Initialization

Initializing the Configuration Sources

This value controls the sources of configuration that are used to setup the map. These configuration sources are each ultimately resolved into an object that is interpreted by the SMK configuration schema.

The resolved configuration objects are merged together, and the final merged object is used to setup the map (merging rules).

The default value for the source directives is [ '?smk-' ], which tells SMK to look at the URL of the host page for any parameters that start with smk-. If this behaviour is undesirable, then the configuration source should be changed.

smk-config Attribute

Not required, default is “?smk-

Used by the SMK <script> element. It contains a list of source directives, separated by “|” The sources are loaded left to right, with the configuration from later sources overriding configuration from earlier sources. A source directive cannot contain “|”, and there is no escaping mechanism.

Example showing all types of directives:

<script src="smk/dist/smk.js"
    smk-container-sel="#smk-map-frame"
    smk-config="smk-config.json | {"viewer":{"baseMap":"Streets"}} | ?smk- | zoom=7"
></script>

config Option

Not required, default is “[ '?smk-' ]

Used by SMK.INIT. The value is an array of source directives. The sources are loaded left to right, with the configuration from later sources overriding configuration from earlier sources.

Example showing all types of directives:

SMK.INIT( {
    containerSel: '#smk-map-frame',
    config: [
        'smk-config.json',
        { viewer: { baseMap: 'Streets' } },
        '?smk-',
        'zoom=7'
    ]
} )

Source Directives

A source directive is one of the following:

URL Directive

A valid URL that is assumed to point a file containing a JSON-encoded SMK configuration object.

JSON Directive

SMK configuration as a literal JSON string. No newlines should be in the JSON, unless they are escaped inside quoted strings.

This is only useful in the smk-config Attribute, and the JSON blob must be encoded by encodeURIComponent.

Object Directive

SMK configuration as a Javascript object literal.

This is only useful in the config Option.

Parameter Directive

A sequence that start with ?. It may be followed by any character string, like ?smk-, or ?foo, or ?##. The characters following the ? are the Prefix. A ? with nothing following, means that the Prefix is an empty string.

When this directive is encountered, the URL of the current document is parsed, and the parameter section is extracted. The parameter section is parsed according to the usual rules (split by & into items, and split each item by = into [key, value] pairs). Then if a parameter key starts with the Prefix, the rest of the parameter key is considered to be an alias directive along with the parameter value.

A Prefix that is an empty string matches any parameter key.

Alias Directive

A string consisting of an NAME=ARGUMENTS. These are aliases for a blob of SMK configuration. The aliases always resolve to some chunk of SMK config.

The NAME is one of:

config Alias

viewer Alias

extent Alias

center Alias

ll Alias

z Alias

query Alias

layer Alias

active-tool Alias

show-tool Alias

hide-tool Alias

show-layer Alias

hide-layer Alias