npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mapcat/mapview-init

v0.0.9

Published

The @mapcat/mapview-init javascript library is used to obtain MAPCAT Visualization API.

Downloads

26

Readme

@mapcat/mapview-init

The @mapcat/mapview-init javascript library is used to obtain MAPCAT raster tile url and vector tile style sheet, that you can use for your Leaflet, OpenLayers and Tangram projects. You can find the prebuilt version of the javascript library under ./dist folder.

Build dependencies

  • node (min v6.9.5)
  • npm (min 4.3.0)
  • yarn (min 1.3.2)

Build

  • Clone or download zip file from MAPCATcom/mapcat-mapview-init repository
    git clone https://github.com/MAPCATcom/mapcat-mapview-init.git
  • Go to the cloned (or unzipped) project main folder
    cd mapcat-mapview-init
  • Install Node.js dependencies
    yarn or yarn install
  • To build release version
    yarn build-min
  • To build debug version
    yarn build-dev

If the build was successful you can find under ./dist folder the recently built release (mapcatview-min.js) or debug (mapcatview-dev.js) version of library.

Usage

Create your HTML skeleton and link mapcat-mapview-init library before your own custom script file.
<script src="mapcatview-min.js"></script>

In your script file:

To initialize Mapcat mapview use one of the following functions

  • for raster tiles:

mapcatview.initRasterView(callback, apiKey, layerOptions, rasterOptions);

  • for vector tiles:

mapcatview.initVectorView(callback, apiKey, layerOptions, vectorOptions);

Example

mapcatview.initRasterView(function(error, response) {

    //your code

}, '< Your MAPCAT Visualization API key >');

mapcatview.initVectorView(function(error, response) {

    //your code

}, '< Your MAPCAT Visualization API key >');

Functions parameters

callback (error, response): function (required) - Callback function

It gets called when the map initialization request returns from our server. The first parameter holds the error message (null means no error), the second parameter in case of initRasterView function call is the response data holding your templated map view url (string). In case of using initVectorView the response data holds the vector tile style sheet (object).

apiKey: string (required) - Your MAPCAT Visualization API key

layerOptions: object (optional) - Options to show cycle roads, routes layers

Layers are used to toggle specific subsets of data rendered on the raster and vector tiles. Customizable: cycle roads and routes. Default: cycle road and route layers are off.

Example
{
    cycle: {
        road: true,
        route: false
    }
}

vectorOptions: object (optional) - Options to change style sheet format

Customizable: vector style sheet format returned, possible values: "mapbox", "openlayers", "tangram". This defaults to: "mapbox".

Example
{
    styleSheet: "mapbox"
}

rasterOptions: object (optional) - Options to set label language and raster tile scale

Parameter lang is the ISO 639-1 language code representation of the desired language, it defaults to "en". To disable label rendering set lang to null or "".
Parameter scale must be 1 or 2. By default, it is 1, meaning that the required raster tile size is 256 × 256 pixel. If you want to get tiles for retina displays (512 × 512 pixel tiles), you can use value 2.

Example
{
    lang: "hu",
    scale: 1
}

Example with Leaflet JS

In your HTML page <head> include Leaflet CSS file

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />

Put a div element in <body> section to your map

<div id="map" style="width: 400px; height: 300px;"></div>

Include Leaflet JavaScript, mapcat-mapview-init.js and your own script file in this order

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="mapcatview-min.js"></script>
<script src="script.js"></script>

In your script file initialize your map

var layerOptions = {
    cycle: {
        road: true,
        route: true
    }
};

var rasterOptions = {
    lang: 'en',
    scale: 1
};

mapcatview.initRasterView(function(error, response) {
    if (error) {
        
        // error handling

        console.log(error);
        return;
    }

    var tileUrl = response;

    var map = L.map('map', {
        zoomControl: false,
        center: L.latLng(47.4979, 19.0402),
        zoom: 13,
        minZoom: 0,
        maxZoom: 18
    });

    L.tileLayer(tileUrl, {
        attribution: 'Imagery &copy; 2017 <a href="https://mapcat.com">MAPCAT</a>, Map data &copy; <a href="http://osm.org/copyright">OpenStreetMap</a contributors',
        maxZoom: 18
    }).addTo(map);

    // your code

}, '< Your MAPCAT Visualization API key >', layerOptions, rasterOptions);

Example with Mapbox GL JS

In your HTML page <head> include Mapbox GL CSS file

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mapbox-gl/0.43.0/mapbox-gl.css" />

Put a div element in <body> section to your map

<div id="map" style="width: 400px; height: 300px;"></div>

Include Mapbox GL JS JavaScript, mapcat-mapview-init.js and your own script file in this order

<script src="https://cdnjs.cloudflare.com/ajax/libs/mapbox-gl/0.43.0/mapbox-gl.js"></script>
<script src="mapcatview-min.js"></script>
<script src="script.js"></script>

In your script file initialize your map

var layerOptions = {
    cycle: {
        road: true,
        route: true
    }
};

var vectorOptions = {
    styleSheet: "mapbox"
};

mapcatview.initVectorView(function(error, response) {
    if (error) {

        // error handling

        console.log(error);
        return;
    }

    var styleSheet = response;

    var map = new mapboxgl.Map({
        container: 'map',
        style: styleSheet,
        center: [0, 51.5],
        zoom: 13
    });

    // your code

}, '< Your MAPCAT Visualization API key >', layerOptions, vectorOptions);

Substitute < Your MAPCAT Visualization API key > with your Visualization API key.

Read MAPCAT for Developers for more information and examples.

Licence

MIT Licence