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

maplibre-compass-pro

v0.3.0

Published

Professional compass for maplibre-based projects

Downloads

123

Readme

Maplibre compass pro npm npm downloads

Professional, good looking compass, suitable for use in all kinds of maplibre-based projects, inspired by Jack Sparrow's compass.

demo

LIVE DEMO

Main features:

  • old fashioned compass rose
  • predefined sizes (from 'xs' to 'xl')
  • typescript support
  • possibility to visualize pitch
  • possibility to display cardinal directions
  • ease integration with maplibre-gl

Integration with maplibre

import 'maplibre-gl/dist/maplibre-gl.css'
import 'maplibre-compass-pro/dist/style.css'
import maplibregl from 'maplibre-gl'
import { Compass } from 'maplibre-compass-pro'

const map = new maplibregl.Map({
	container: 'map',
	style: '/mapStyle.json',
	center: [14.5, 53.4],
	zoom: 11,
})

const compass = new Compass({ size: 'sm' })
map.addControl(compass, 'bottom-left')

Remember to import compass styles 🙏🙏🙏 Compass props:

type CompassProps = {
	size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' // default 'md'
	visualizePitch?: boolean // default false
	displayDirections?: boolean // default false (use cardinal directions instead of needle)
	onClick?: () => void // default map.resetNorthPitch
}

You can omit props object so that all defaults will be used.

Using compass API

It's possible to update compass size, or toggle between needle/cardinal directions using its API. See code snippet below:

const compass = new Compass({ size: 'sm' }) // set size 'sm' as initial value, needle is used as default
map.addControl(compass, 'bottom-left')

// change compass size
compass.changeSize('lg')

// display cardinal directions instead of needle
compass.toggle()
// back to needle in 3 seconds
setTimeout(() => {
	compass.toggle()
}, 3000)

Integration with React

If you're working in React environment consider using react-map-gl as maplibre wrapper, together with map-gl-compass-pro. As for now there are tiny differences between those 2 packages (in view only) - but they will be aligned soon. It's also possible to wrap maplibre-compass-pro with use-control hook.

import 'maplibre-compass-pro/dist/style.css'

import { Compass as CompassPro } from 'maplibre-compass-pro'
import { useControl } from 'react-map-gl'

export function Compass() {
	useControl(() => new CompassPro({ size: 'md', displayDirections: true }), {
		position: 'bottom-left',
	})
	return null
}

This component has to be a child of Map component.

Placement

Compass position is determined by second argument of addControl function. You can pick one of: top-left, top-right, bottom-left, and bottom-right. Default position is bottom-left. If you want to move the compass away from the corner please override maplibre class, like below:

.maplibregl-ctrl-bottom-left {
	left: 10px;
	bottom: 10px;
}