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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-geojson-regions-map

v0.0.4

Published

A Vue.js component for displaying GeoJSON features with a colour map and pan and zoom features.

Readme

Vue.js GeoJSON Regions Map

Vue.js GeoJSON Regions Map is a simple plugin providing a RegionsMap component. This component uses OpenLayers to load and display a given GeoJSON file where you can pan, zoom, and interact with the features in your GeoJSON file. Additionally, you can pass a colour map to allow setting the fill colour of each feature. This is useful for apps where you want to visualise regional data by colouring each region on a map according to a key.

To see its usage in a real project, you can see my project UK Regional Data Visualiser, which you can see in action here.

Installation

Install with npm:

npm install vue-geojson-regions-map --save

Usage

Register the plugin in your app's main.js (or main.ts if you are using TypeScript):

import App from "./App.vue";
import { createApp } from "vue";
import RegionsMap from "vue-geojson-regions-map";

const app = createApp(App);
app.use(RegionsMap);
app.mount("#app");

Let's say you have a sample.geojson file in your project's root directory with contents:

{
  "type": "FeatureCollection",
  "crs": { "type": "name", "properties": { "name": "EPSG:27700" } },
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [...]
      },
      "id": "one"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [...]
      },
      "id": "two"
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [...]
      },
      "id": "three"
    }
  ]
}

To display this GeoJSON without any region colouring:

<template>
  <RegionsMap geo-json-file-path="./sample.geojson" />
</template>

You can pass a colour map to the region-colours prop to colour each feature in your GeoJSON file. The mapping is from the id field of the feature to the desired colour of the region (currently, only the id field is supported). The colour is expressed as a string of the colour's hexadecimal value, e.g. "#FF0000". For example:

<script>
  export default {
    computed: {
      regionsColours() {
        // Map of each feature ID to what colour it should be.
        return new Map([
          ["one", "#FF0000"],
          ["two", "#008000"],
          ["three", "#0000FF"],
        ]);
      },
    },
  };
</script>

<template>
  <RegionsMap
    geo-json-file-path="./sample.geojson"
    :region-colours="regionColours"
  />
</template>

Mouse events example

The region-pointer-move and region-single-click events can be used with highlighted-region-id and selected-region-id to easily create an interactive display where features are highlighted upon pointer move, and are centred when clicked:

<script>
  export default {
    data() {
      return {
        highlightedRegionId: "",
        selectedRegionId: "",
      };
    },
    methods: {
      selectRegion(regionId: string) {
        this.selectedRegionId = regionId;
      },
      deselectRegion() {
        if (this.selectedRegionId) this.highlightedRegionId = "";
        this.selectedRegionId = "";
      },
      highlightRegion(regionId: string) {
        this.highlightedRegionId = regionId;
      },
      unhighlightRegion(regionId: string) {
        if (regionId === this.selectedRegionId) return;
        this.highlightedRegionId = "";
      },
    },
  };
</script>

<template>
  <RegionsMap
    geo-json-file-path="./sample.geojson"
    :highlighted-region-id="highlightedRegionId"
    :selected-region-id="selectedRegionId"
    @region-single-click="selectRegion"
    @region-pointer-move="highlightRegion"
  />
</template>

Props

| Name | Type | Default | Description | | ----------------------- | --------------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | geo-json-file-path | String | N/A (required) | The URL to the GeoJSON file which should be displayed. | | highlighted-region-id | String | "" | The feature ID which should be rendered as "highlighted", which adds a white translucent overlay and makes the borders thicker. Only one feature at a time can be highlighted. | | selected-region-id | String | "" | The feature ID which should be marked as the selected region. Selected features are styled the same way as highlighted ones. Only one feature can be selected at a time. When a feature is selected, the previously selected feature's highlight style is removed, and the newly selected feature is centred on the view. | | region-colours | Map<number \| string \| null, string> | new Map() | The colour map that is used to apply colours for each feature in the GeoJSON file. The mapping is from the id field of each feature to the desired colour in hexadecimal format, e.g. "FF0000" | | region-no-data-colour | String | "#BFBFBF" | The default colour to be used for regions which do not have a mapping specified in the passed region-colours. | | theme | String | "light" | The theme which determines the colour of the background for displaying the features. Valid options are "light" or "dark". | | extra-view-options | Object | Object (empty object) | Extra options to pass to the OpenLayers View object used by the component. Can also be used to override default options. This can be useful for setting custom extents, min/max zoom, etc. |

Events

Two events are emitted by RegionsMap: region-pointer-move when the pointer moves on top of a feature, and region-single-click when a feature is single clicked. Both events pass the target feature's id field as an argument. An example o their usage:

<script>
  export default {
    methods: {
      handleRegionPointerMove(featureId: string) {
        console.log(`Cursor hovering over feature {featureId}`);
      },
      handleRegionSingleClicked(featureId: string) {
        console.log(`Clicked feature {featureId}`);
      }
    },
  };
</script>

<template>
  <RegionsMap
    geo-json-file-path="./sample.geojson"
    @region-pointer-move="handleRegionSingleClicked"
    @region-single-click="handleRegionPointerMove"
  />
</template>