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

@inflect/map

v1.1.1

Published

Put a map of your PoPs on your website in 5 minutes, courtesy of [Inflect](https://inflect.com).

Downloads

325

Readme

@inflect/map

Put a map of your PoPs on your website in 5 minutes, courtesy of Inflect.

Interactive demo and code examples

⚛️ Use React? We do too! Check out our React wrapper for this package.

Under the hood, @inflect/map uses Mapbox GL JS, and is compatible with browsers that support WebGL.

Installation

yarn add @inflect/map

or right before the closing </body> tag:

<script src="https://unpkg.com/@inflect/map@1/dist/main.js"></script>

Usage

Once you've installed this package, create an instance of InflectMap and initialize it with your token and an existing HTML element's id. Make sure that your script or bundle has loaded first so that InflectMap is in scope.

var map = new InflectMap();
map.init({
  id: 'inflect-map', // The id of an HTML element
  token: 'a1B2c3D4e5F6g7H8i9J0', // Obtained on your team page at inflect.com
});

Required properties

Property | Description --------- | ----------- id | String. Required. Default value: inflect-map.The id of the HTML container the map should be inserted into. token | String. Required. No default value.Your map token obtained at inflect.com. See Creating a map token for more information.

Basic properties

Like the required properties, these optional properties can be passed into the init instance method.

Property | Description --------- | ----------- autoCamera | Boolean. Optional. Default value: true.When true, the map viewport will automatically move to fit the bounds of the source data. cameraDuration | Number. Optional. Default value: 1000.The number of milliseconds it takes to move the map viewport automatically. When autoCamera is false, this property has no effect. dotBorderColor | String. Optional. Default value: #fff.The border color of the circular map markers. The value can be represented by any valid CSS color representation (hex value, rgb, rgba, named color, etc). dotBorderWidth | Number. Optional. Default value: 1.The stroke width of the map markers' border, in pixels. dotColor | String. Optional. Default value: #6a7685.The main color of the circular map markers. The value can be represented by any valid CSS color representation (hex value, rgb, rgba, named color, etc). dotRadius | Number. Optional. Default value: 6.The radius of the map markers, in pixels. hash | Boolean. Optional. Default value: false.If true, coordinates and zoom will be appended as the document location's hash, so when navigating through history (or refreshing the page), the map viewport will be retained. This is most useful when autoCamera is set to false, and when there is only one instance of the map on the page. height | String. Optional. Default value: inherit.The CSS value of the HTML container's height. By default, it takes up the same height as its container. If specifying a pixel height, be sure to include the suffix, e.g. 500px. lat | Number. Optional. Default value: 16.875.The latitude of the center coordinate of the map. By default, the map is oriented to be aesthetically centered. lng | Number. Optional. Default value: 28.30438.The longitude of the center coordinate of the map. By default, the map is oriented to be aesthetically centered. maxZoom | Number. Optional. Default value: 24.A number within the range of 0 (zoomed out) to 24 (zoomed in) that sets the maximum allowed level a user can zoom in. minZoom | Number. Optional. Default value: 0.A number within the range of 0 (zoomed out) to 24 (zoomed in) that sets the minimum allowed level a user can zoom out. scrollZoom | Boolean. Optional. Default value: true.When true, allows the mousewheel to zoom in and out of the map. Disabling this can be useful to prevent the map from hijacking a page's scroll behavior. static | Boolean. Optional. Default value: false.When true, prevents pan and zoom events. theme | String. Optional. Default value: light.The map theme. The value can be one of the following: dark, day, light, night, satellite. See Themes for examples. width | String. Optional. Default value: inherit.The CSS value of the HTML container's width. By default, it takes up the 100% of its container. If specifying a pixel width, be sure to include the suffix, e.g. 500px. zoom | Number. Optional. Default value: 0.A number within the range of 0 (zoomed out) to 24 (zoomed in) that sets the current zoom level.

Advanced properties

Property | Description --------- | ----------- onClick | Function. Optional. Default value: none.An event handler that fires when the map is clicked. If any dots are underneath the mouse cursor on click, they will be passed into this function. This function should take an array of GeoJSON features as a parameter. onHover | Function. Optional. Default value: none.An event handler that fires when the mouse cursor moves over the map. If any dots are underneath the mouse cursor on click, they will be passed into this function. This function should take an array of GeoJSON features as a parameter. onLoad | Function. Optional. Default value: none.An event handler that fires when the map has finished loading. onMoveEnd | Function. Optional. Default value: none.An event handler that fires when the map finishes a pan or a zoom. The map event object will be passed into this function.

Creating a map token

  1. Create an account on inflect.com, or log in if you already have an account. If your company has already created a team, ask one of your teammates to invite you to join the team.
  2. On your team page, click the "Team maps" tab.
  3. Click "Create a new map".
  4. Select the data point(s) you'd like to embed on your site, and click "Create map".
  5. Use the resulting 24-character alphanumeric string as your token when you init the map.

Styling

Themes

Below are values you can pass to the theme property.

light (default)

Light theme

dark

Dark theme

day

Day theme

night

Night theme

satellite

Satellite theme

Popup

You can override the default styling of the map popup by targeting the .inflect-map-popup class in CSS.

Updating values

Calling map.set() with any properties will update the map.

This is useful if you want to cycle between a couple map tokens — calling map.set({ token: newMapToken }) will load the new set of data and animate to its bounding box automatically.

Potential gotchas

CSP Directives

As a mitigation for Cross-Site Scripting and other types of web security vulnerabilities, you may use a Content Security Policy (CSP) to specify security policies for your website. If you do, Inflect Map requires the following CSP directives:

worker-src blob: ;
child-src blob: ;
img-src data: blob: ;
connect-src https://*.tiles.mapbox.com https://api.mapbox.com

Server-side rendering

The dependencies of this package prevent it from being rendered server-side in node environments. As a workaround, import the package dynamically, or prevent the importing of the package in your build phase. If you have any troubles, please open an issue.

iframe

We also host a page that you can embed via iframe. While we highly recommend installing the package instead, you can choose to embed an iframe version on your website if you so please. Just be aware of the following caveats of using an iframe:

  • You cannot dynamically set properties without reloading the entire iframe
  • You cannot specify custom CSS for the map popup
  • Advanced properties are not supported

Required and basic properties listed in Usage are available to the iframe as query parameters. Since the values are read from the URL path, you must URL-encode special characters (for example, when passing in a hex color value, you must convert # into its URL-encoded representation %23, in order to avoid the value being interpreted as a document fragment).

<iframe src="https://embed.inflect.com/map/1/?token=YOUR_TOKEN_HERE" width="100%" height="500" frameborder="0"></iframe>