@awhere/maps-maptalks

The awesome aWhere JavaScript API for Maptalks.

Usage no npm install needed!

<script type="module">
  import awhereMapsMaptalks from 'https://cdn.skypack.dev/@awhere/maps-maptalks';
</script>

README

@awhere/maps-maptalks

The awesome aWhere JavaScript API for Maptalks.

Installation

Install the package in your project directory with:

// with npm
npm install @awhere/maps-maptalks

// with yarn
yarn add @awhere/maps-maptalks

Example

<body>
    <div id="map"></div>
    <script>
        let credential;

        /* Create credential with Basic API Key */
        credential = new awhere.identity.APIKey({
            aWhereUrl: '<Your aWhere URL>',
            key: '<Your API Key>',
        });

        /* Create credential with OAuth 2.0 */
        // credential = new awhere.identity.OAuth({
        //     aWhereUrl: '<Your aWhere URL>',
        //     appId: '<Your App Id>',
        //     callbackUrl: '/oauth-callback.html',
        // });

        /* Create credential with Basic Authentication */
        // credential = new awhere.identity.BasicAuth({
        //     aWhereUrl: '<Your aWhere URL>',
        //     username: '<Your Username>',
        //     password: '<Your Password>',
        // });

        /* Create credential with Access Token */
        // credential = new awhere.identity.BearerToken({
        //     aWhereUrl: '<Your aWhere URL>',
        //     token: '<Your Access Token>',
        // });

        /* Register credential with identityManager */
        awhere.identity.identityManager.registers([credential]);

        /* Set default credential */
        awhere.identity.identityManager.setDefaultCredential(credential);

        /* Use the API */
        awhere.map.Map.fromId('map', '<Your Web Map ID>')
            .then(map => {
                if (!map) {
                    console.warn('map_id not found.');
                    return;
                }
                window.map = map;
                console.log(`"window.map" is ready`, map);
            })
            .catch(err => {
                console.warn('error', err);
            });
        console.log('Use the aWhere JavaScript API for Maptalks here', awhere);
    </script>
</body>