-
Notifications
You must be signed in to change notification settings - Fork 3
SMK Client API Examples
For the following examples, the reader should assume the following:
-
There is a site at https://example.com/demo, this will be the base for the URLs used below.
-
There is a file
index.html
hosted at URL above.
The comment marks where the examples insert the SMK<script>
element.
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- SMK <script> element -->
<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>
- There is a file
map-config.json
in same folder asindex.html
.
{
"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
}
]
}
- There is a file
victoria.json
in same folder asindex.html
.
{
"viewer": {
"location": {
"extent": [ -124.0750, 48.3087, -123.2273, 48.7519 ]
},
}
}
- There is a file
kamloops.json
in same folder asindex.html
.
{
"viewer": {
"location": {
"extent": null,
"center": [ -120.38298432016748, 50.677415757969214 ],
"zoom": 11
}
}
}
- There is a file
wms-layer.json
in same folder asindex.html
.
{
"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
}
]
}
- There is a file
wms-layer-attributes.json
in same folder asindex.html
.
{
"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" }
]
}
]
}
- There is a file
wms-layer-query.json
in same folder asindex.html
.
{
"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"
}
]
}
]
}
}
]
}
]
}
The 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.
If multiple setups are provided for an example, it is asserted that they all have exactly the same effect.
An example with a <script>
element, followed by the URL to be invoked:
<script src="smk.js"
smk-config="show-tool=baseMaps"
></script>
smk-show-tool=baseMaps
Using default configuration.
<script src="smk.js"></script>
- The map fills browser window.
- The window/tab has title 'SMK Default Map'.
- These tools are available: directions, location, markup, and search.
- Map is centered over BC, showing whole province.
- The base map is 'Topographic'.
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
- The map fills browser window.
- The window/tab has title 'Test App'.
- These tools are available: directions, location, search, and baseMaps.
- Map is centered over BC, showing whole province.
- The base map is 'Streets'.
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
- The map fills browser window.
- The window/tab has title 'Test App'.
- These tools are available: directions, location, search, markup, and layers.
- Map is centered over BC, showing whole province.
- The base map is 'Streets'.
- The layer list shows one layer: 'Lease Applications - Tantalis - Colour Filled', and it is visible.
- The map shows little green spots for the 'Lease Applications - Tantalis - Colour Filled' layer.
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
- The map fills browser window.
- The window/tab has title 'SMK Default Map'.
- These tools are available: directions, location, search, and markup.
- Map is centered over southern Vancouver Island.
- The base map is 'Topographic'.
Changing URL parameter prefix.
<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 map fills browser window.
- The window/tab has title 'SMK Default Map'.
- These tools are available: directions, location, search, and markup.
- Map is centered over southern Vancouver Island.
- The base map is 'Topographic'.
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 map fills browser window.
- The window/tab has title 'SMK Default Map'.
- These tools are available: about, baseMaps, coordinate, directions, identify, layers, location, markup, measure, menu, minimap, pan, scale, search, select, and zoom.
- The base map is 'Topographic'.
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}]}
- The map fills browser window.
- The window/tab has title 'SMK Default Map'.
- These tools are available: directions, location, scale, search, and markup.
- The scale display doesn't show the scale factor.
- The base map is 'Topographic'.
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 map fills browser window.
- The window/tab has title 'SMK Default Map'.
- These tools are available: directions, location, scale, search, query, and markup.
- The base map is 'Topographic'.
- The query tool is activated when the map loads.
- The query is executed immediately.
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.