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

@mapbox-controls/image

v3.0.0

Published

Move, scale and rotate image on a map

Downloads

338

Readme

<< all controls

🏙️ @mapbox-controls/image

Control to move, scale, rotate image (raster layer) on top of a map. Very handy to represent information from the raster to geojson, for example, the contours of buildings.

npm i @mapbox-controls/image
import ImageControl from '@mapbox-controls/image';
import '@mapbox-controls/image/src/index.css';

const imageControl = new ImageControl();
map.addControl(imageControl, 'bottom-right');

Options

export type ControlOptions = {
    removeButton?: boolean;
};

Events

| event | description | | -------------- | -------------------------- | | image.select | selected new image | | image.deselect | image was deselected | | image.mode | transform mode was changed | | image.update | position was updated | | image.add | new image added | | image.remove | image removed |

Methods

Methods are useful for programmatic control (when option invisible is true):

  • addFile(file: File, coordinates?: [number, number][] | undefined): Promise<string>; - add new image by file. raster id is returned
  • addUrl(url: string, coordinates?: [number, number][] | undefined): Promise<string>; - add new image by url. raster id is returned
  • setLock: (id: string, isLocked: boolean) => void; - lock or unlock image. locked image can't be selected
  • removeRaster: () => void; - removes selected raster from the map

If image was added without coordinates parameter, the image is scaled down to be fully visible and placed at the center of the viewport.

Other methods may help to use this control without buttons, these methods are described in type definitions .d.ts.

Change paint properties

Paint properties can be changed dynamically. Below is an example how to control image opacity by slider (full implementation is available in preview).

map.on('image.select', ({ id }) => {
  const rasterLayerId = image.rasters[id].rasterLayer.id;
  const range = document.createElement('input');
  range.style.position = 'absolute';
  range.style.left = '50%';
  range.style.transform = 'translateX(-50%)';
  range.style.bottom = '16px';
  range.type = 'range';
  range.min = 0;
  range.step = 0.05;
  range.max = 1;
  range.value = map.getPaintProperty(rasterLayerId, 'raster-opacity');
  range.addEventListener('input', () => {
    map.setPaintProperty(rasterLayerId, 'raster-opacity', Number(range.value));
  });
  document.body.appendChild(range);
  map.once('image.deselect', () => {
    document.body.removeChild(range);
  });
});