Skip to content

giscloud/giscloud-js-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@giscloud/js-api

The GIS Cloud JavaScript API — interactive map viewer for embedding GIS Cloud maps in web pages.

Mirrors the slim core bundle that production serves at https://api.giscloud.com/1/api.js, packaged as a static asset so it can be loaded from any CDN (unpkg, jsDelivr, esm.sh) without depending on the GIS Cloud edge servers being reachable.

Install

From a CDN (no install needed)

<script src="https://unpkg.com/@giscloud/js-api@1/api.js"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/@giscloud/js-api@1/api.js"></script>

Via npm

npm install @giscloud/js-api

Then bundle or include the file at node_modules/@giscloud/js-api/api.js.

Quick start

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>html,body,#map{margin:0;height:100%;width:100%}</style>
  <script src="https://unpkg.com/@giscloud/js-api@1/api.js"></script>
</head>
<body>
  <div id="map"></div>
  <script>
    // Uncomment and set your key if the target map is private. The example map id
    // below is publicly shared, so no key is needed.
    // giscloud.apiKey('YOUR_API_KEY');

    giscloud.ready(function () {
      new giscloud.Viewer('map', 1245864);   // 1245864 = a public demo map; swap for your own
    });
  </script>
</body>
</html>

A complete working version is at examples/basic.html.

Authentication

The viewer makes authenticated calls to api.giscloud.com for layers, features, tiles, etc. Three ways to provide credentials:

  1. API key (simplest, embeds the key in the page). giscloud.apiKey is a getter/setter function:
    giscloud.apiKey('YOUR_API_KEY');   // set
    var k = giscloud.apiKey();         // read back
  2. Session cookie — your visitor is already signed in to giscloud.com in the same browser.
  3. Public-share — the map is shared publicly with no auth requirement.

Treat any HTML containing an embedded API key as a credential. Do not publish it to untrusted contexts (public gists, screenshots, etc.) — anyone with the key can act on your account.

Custom configuration

By default the bundle points at GIS Cloud production (api.giscloud.com, auth.giscloud.com, tiles.giscloud.com, assets.giscloud.com). To point at a different deployment (self-hosted, staging, dev), set window.giscloud_config before loading the script:

<script>
  window.giscloud_config = {
    restHost: function () { return 'https://api.example.com'; },
    apiHost:  function () { return 'https://api.example.com'; },
    authHost: function () { return 'https://auth.example.com'; },
    liveSite: function () { return 'https://api.example.com/'; },
    tileSite: function () { return 'https://tiles.example.com/'; },
    assetsSite: function () { return 'https://assets.example.com/'; },
    tileImageProxySite: function () { return 'https://proxy.example.com/{url}'; },
    leafletScript: function () { return 'leaflet.js'; },
    nch: '1',
    https: true
  };
</script>
<script src="https://unpkg.com/@giscloud/js-api@1/api.js"></script>

The bundled config block is guarded by if (!self.giscloud_config) { … }, so your override wins.

API surface

The full reference lives at docs.giscloud.com/js. The most common entry points:

Initialisation

  • giscloud.ready(callback) — run code after all modules have initialised.
  • giscloud.apiKey('your-key') / giscloud.apiKey() — set / get the API key.
  • new giscloud.Viewer(containerId, mapId, options) — instantiate an interactive map viewer in a <div>.

REST namespaces

Namespace Common methods
giscloud.maps list(), byId(mapId), create(data), update(mapId, data), remove(mapId)
giscloud.layers byMapId(mapId), byId(layerId), create(data), update(layerId, data), remove(layerId), reset()
giscloud.features byLayer(layerId), byId(layerId, featureId), create(layerId, data), update(), remove(layerId, featureId)
giscloud.tables list(), byName(name), create(schema), query(name, query), remove(name)
giscloud.forms byId(id), create(name, definition), update(id, name, def), remove(id)
giscloud.users current(), list(), byId(id), create(data), update(id, data)

All methods return promise-like objects with .done() / .fail() / .then(), and most also accept a trailing callback argument.

Model classes

  • giscloud.Map, giscloud.Layer, giscloud.Feature — REST-backed entities.
  • giscloud.Bounds(left, bottom, right, top) — geographic extent.
  • giscloud.LonLat(lon, lat) — coordinate point.

Geometry

Located under giscloud.geometry.*: Point(x,y,z), Line(points), Polygon(rings), Multipoint, Multiline, Multipolygon, GeometryCollection. All support .toOGC() (returns WKT).

Updating

To publish a new version of this package:

  1. Refresh the bundle:
    ./update.sh           # fetches https://api.giscloud.com/1/api.js into api.js
  2. Bump version in package.json.
  3. npm publishpublishConfig.access in package.json is already set to public, so no flag is needed.

unpkg / jsDelivr / esm.sh pick up new versions automatically within a few minutes.

License

Proprietary — © GIS Cloud Ltd. See https://www.giscloud.com/terms for terms of use. The bundle is provided for use with GIS Cloud accounts. Redistribution is permitted insofar as it is necessary for CDN mirroring (npm, unpkg, jsDelivr, esm.sh); modifications or use outside the GIS Cloud platform are not licensed without written permission.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages