A versatile and lightweight toolkit for building a simple web map.
This project is maintained by qqnluaq
For the following examples, the reader should assume the following:
demo |-- index.html |-- map-config.json |-- victoria.json |-- kamloops.json |-- wms-layer.json |-- wms-layer-attributes.json |-- wms-layer-query.json |-- smk.js '-- images '-- (SMK images)
index.html
(take careful note of the comment in the code):<html>
<head>
<title></title>
<!-- ------------------------------------------------
The examples specify the SMK <script> element
that is to be inserted here.
------------------------------------------------- -->
<style>
#smk-map-frame {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 0;
}
</style>
</head>
<body id="smk-map-frame"></body>
</html>
map-config.json
{
"smkId": "test-app",
"smkRevision": 1,
"name": "Test App",
"createdBy": "vivid",
"published": false,
"viewer": {
"type": "leaflet",
"baseMap": "Streets"
},
"tools": [
{
"type": "markup",
"enabled": false
},
{
"type": "baseMaps",
"enabled": true
}
]
}
victoria.json
{
"viewer": {
"location": {
"extent": [ -124.0750, 48.3087, -123.2273, 48.7519 ]
}
}
}
kamloops.json
{
"viewer": {
"location": {
"extent": null,
"center": [ -120.38298432016748, 50.677415757969214 ],
"zoom": 11
}
}
}
wms-layer.json
{
"layers": [
{
"id": "whse-tantalis-ta-crown-leases-svw",
"type": "wms",
"serviceUrl": "https://openmaps.gov.bc.ca/geo/pub/wms",
"title": "Lease Applications - Tantalis - Colour Filled",
"layerName": "WHSE_TANTALIS.TA_CROWN_LEASES_SVW",
"styleName": "Lease-Applications-Tantalis-Colour-Filled",
"isVisible": true
}
]
}
wms-layer-attributes.json
{
"layers": [
{
"id": "whse-tantalis-ta-crown-leases-svw",
"titleAttribute": "INTRID_SID",
"geometryAttribute": "SHAPE",
"attributes": [
{ "id": "intrid-sid", "name": "INTRID_SID", "title": "Intrid Sid" },
{ "id": "disposition-transaction-sid", "name": "DISPOSITION_TRANSACTION_SID", "title": "Disposition Transaction Sid" },
{ "id": "tenure-stage", "name": "TENURE_STAGE", "title": "Tenure Stage" },
{ "id": "tenure-status", "name": "TENURE_STATUS", "title": "Tenure Status" },
{ "id": "tenure-type", "name": "TENURE_TYPE", "title": "Tenure Type" },
{ "id": "tenure-subtype", "name": "TENURE_SUBTYPE", "title": "Tenure Subtype" },
{ "id": "tenure-purpose", "name": "TENURE_PURPOSE", "title": "Tenure Purpose" },
{ "id": "tenure-subpurpose", "name": "TENURE_SUBPURPOSE", "title": "Tenure Subpurpose" },
{ "id": "crown-lands-file", "name": "CROWN_LANDS_FILE", "title": "Crown Lands File" },
{ "id": "tenure-document", "name": "TENURE_DOCUMENT", "title": "Tenure Document" },
{ "id": "tenure-expiry", "name": "TENURE_EXPIRY", "title": "Tenure Expiry" },
{ "id": "tenure-location", "name": "TENURE_LOCATION", "title": "Tenure Location" },
{ "id": "tenure-legal-description", "name": "TENURE_LEGAL_DESCRIPTION", "title": "Tenure Legal Description" },
{ "id": "tenure-area-derivation", "name": "TENURE_AREA_DERIVATION", "title": "Tenure Area Derivation" },
{ "id": "tenure-area-in-hectares", "name": "TENURE_AREA_IN_HECTARES", "title": "Tenure Area In Hectares" },
{ "id": "responsible-business-unit", "name": "RESPONSIBLE_BUSINESS_UNIT", "title": "Responsible Business Unit" },
{ "id": "code-chr-stage", "name": "CODE_CHR_STAGE", "title": "Code Chr Stage" }
]
}
]
}
wms-layer-query.json
{
"viewer": {
"activeTool": "query--whse-tantalis-ta-crown-leases-svw--query1",
},
"tools": [
{
"type": "query",
"instance": "whse-tantalis-ta-crown-leases-svw--query1",
"onActivate": "execute",
}
],
"layers": [
{
"id": "whse-tantalis-ta-crown-leases-svw",
"queries": [
{
"id": "query1",
"title": "Tenure Status",
"description": "Find features for a given Tenure Status",
"parameters": [
{
"id": "param1",
"type": "constant",
"value": "ACCEPTED"
}
],
"predicate": {
"operator": "and",
"arguments": [
{
"operator": "equals",
"arguments": [
{
"operand": "attribute",
"name": "TENURE_STATUS"
},
{
"operand": "parameter",
"id": "param1"
}
]
}
]
}
}
]
}
]
}
smk.js
The production version of the SMK library.
smk.jsThe examples will provide a setup that gives the <script>
element and the parameters for URL that is being requested.
The URL parameters (if any) are presented in a list for ease of reading, and the URL
is linked to the properly formatted URL.
The complete request is formatted as a standard URL (though without any spaces around ? and &):
[host and path] ? [argument1] & [argument2] & … & [argumentN]
If multiple setups are provided for an example, it is asserted that they all have exactly the same effect.
Using default configuration.
<script src="smk.js"></script>
The <script>
element doesn’t specify a map configuration file, so the default configuration it used.
Loading configuration from a URL.
<script src="smk.js"></script>
smk-show-tool=baseMaps
smk-hide-tool=markup
smk-config={"name":"Test App","viewer":{"baseMap":"Streets"}}
<script src="smk.js"
smk-config="show-tool=baseMaps|hide-tool=markup|{"name":"Test App","viewer":{"baseMap":"Streets"}}"
></script>
<script src="smk.js"
smk-config="map-config.json"
></script>
<script src="smk.js"></script>
smk-config=map-config.json
Loading a layer.
<script src="smk.js"
smk-config="map-config.json|wms-layer.json|show-tool=layers"
></script>
<script src="smk.js"
smk-config="map-config.json|show-tool=layers"
></script>
smk-config=wms-layer.json
<script src="smk.js"
smk-config="map-config.json"
></script>
smk-config=wms-layer.json
layer=https://openmaps.gov.bc.ca/geo/pub/wms,WHSE_TANTALIS.TA_CROWN_LEASES_SVW,Lease-Applications-Tantalis-Colour-Filled,Lease Applications - Tantalis - Colour Filled
Setting location of map.
<script src="smk.js"
smk-config="victoria.json"
></script>
<script src="smk.js"></script>
smk-config=victoria.json
<script src="smk.js"
smk-config="ll=-123.65114,48.53077|z=10"
></script>
<script src="smk.js"></script>
smk-z=10
smk-ll=-123.65114,48.53077
<script src="smk.js"></script>
smk-center=-123.65114,48.53077,10
<script src="smk.js"></script>
smk-extent=-124.0750,48.3087,-123.2273,48.7519
Changing URL parameter prefix.
The default URL parameter prefix is smk-
, but this can be changed.
You may want the parameters processed by SMK to be prefixed with foo-
for example.
The URL parameters can be processed before or after other configuration specified in the smk-config
attribute.
<script src="smk.js"
smk-config="victoria.json|?foo-"
></script>
smk-config=kamloops.json
<script src="smk.js"
smk-config="?foo-|victoria.json"
></script>
foo-config=kamloops.json
<script src="smk.js"
smk-config="kamloops.json|?foo-"
></script>
foo-config=victoria.json
<script src="smk.js"
smk-config="?"
></script>
config=victoria.json
The order of configuration sources in smk-config
attribute is important.
URL parameters that don’t match the prefix are ignored.
The URL parameter prefix can be empty.
Enabling tools.
<script src="smk.js"
smk-config="show-tool=all"
></script>
<script src="smk.js"></script>
smk-show-tool=all
<script src="smk.js"
smk-config="?smk-|show-tool=about,baseMaps,coordinate,identify,layers"
></script>
smk-show-tool=pan,scale,select,zoom
smk-show-tool=measure,menu,minimap
The all
tool stands for all tools.
The order of tools that tools are enabled doesn’t control their position.
Configuring tools.
<script src="smk.js"
smk-config="show-tool=scale|{"tools":[{"type":"scale","showFactor":false}]}"
></script>
<script src="smk.js"
smk-config="show-tool=scale|?smk-"
></script>
smk-config={"tools":[{"type":"scale","showFactor":false}]}
<script src="smk.js"></script>
smk-show-tool=scale
smk-config={"tools":[{"type":"scale","showFactor":false}]}
Running an ad-hoc query.
<script src="smk.js"></script>
smk-config=wms-layer.json
smk-config=wms-layer-attributes.json
smk-query=whse-tantalis-ta-crown-leases-svw,and,TENURE_STATUS="ACCEPTED"
<script src="smk.js"></script>
smk-config=wms-layer.json
smk-config=wms-layer-attributes.json
smk-config=wms-layer-query.json
The ad-hoc URL parameter query definitions only allow a subset of possible query structures. The ad-hoc URL parameter query also controls the tool active at startup, and uses a special configuration to execute query immediately. For this query, the conjunction could be ‘and’ or ‘or’, as there is only one predicate.