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

ol-displaced-points

v0.4.0

Published

Displaced Points methodology works to visualize all features of a point layer, even if they have the same location. The map takes the points falling in a given Distance tolerance from each other (cluster) and places them around their barycenter.

Downloads

312

Readme

Displaced Points

Displaced Points methodology works to visualize all features of a point layer, even if they have the same location. To do this, the map takes the points falling in a given Distance tolerance from each other (cluster) and places them around their barycenter following different Placement methods:

  • Ring: Places all the features on a circle whose radius depends on the number of features to display.
  • Concentric Rings: Uses a set of concentric circles to show the features.
  • Spiral: Creates a spiral with the features farthest from the center of the group in each turn.
  • Grid: Generates a regular grid with a point symbol at each intersection.

Note: Displaced Points methodology does not alter feature geometry, meaning that points are not moved from their position. Changes are only visual, for rendering purpose. Each barycenter is themselves a cluster with an attribute features that contain the original features.

Install

npm

npm i ol-displaced-points

Usage

The DisplacedPoints class extends of cluster class from OpenLayers. Review examples Vector Layer and Clustered Features of OpenLayers to get context or review our use example on CodeSandbox.

<!DOCTYPE html>
<html>
  <head>
    <title>Displaced Points</title>
    <meta charset="UTF-8" />
    <style>
      .map {
        width: 100%;
        height: 400px;
      }
    </style>
  </head>

  <body>
    <div id="map" class="map" />

    <script src="src/index.js" type="module"></script>
  </body>
</html>
import Map from "ol/Map";
import TileLayer from "ol/layer/Tile";
import OSM from "ol/source/OSM";
import VectorLayer from "ol/layer/Vector";
import View from "ol/View";
import VectorSource from "ol/source/Vector";
import GeoJSON from "ol/format/GeoJSON";

import DisplacedPoints from "ol-displaced-points";

const sourceDisplacedPoints = new DisplacedPoints({
  source: new VectorSource({
    url: "./features.geojson",
    format: new GeoJSON(),
  }),
  distance: 80,
  minDistance: 40,
});

new Map({
  layers: [
    new TileLayer({ source: new OSM() }),
    new VectorLayer({
      source: sourceDisplacedPoints,
    }),
  ],
  target: "map",
  view: new View({
    center: [-101.012614352653245, 20.905432044070093],
    zoom: 3,
    projection: "EPSG:4326",
  }),
});

México Basic

Style options

...
import { Circle, Fill, Stroke, Style } from "ol/style";

const radiusCenter = 5;
const radiusPoints = 5;
const sourceDisplacedPoints = new DisplacedPoints({
  source: new VectorSource({
    url: "./features.geojson",
    format: new GeoJSON(),
  }),
  distance: 80,
  minDistance: 40,
  radiusCenterPoint: radiusCenter,
  radiusDisplacedPoints: radiusPoints,
});


function styleCircle(radius, stroke, fill = "#0000") {
  return new Style({
    image: new Circle({
      radius: radius,
      stroke: new Stroke({
        color: stroke,
        with: 1,
      }),
      fill: new Fill({
        color: fill,
      }),
    }),
  });
}

function styleDisplacedPoints(f) {
  if (f.get("ring")) {
    return styleCircle(f.get("ring").radius);
  }

  if (f.get("features")) {
    return styleCircle(radiusCenter, "white", "red");
  }

  return styleCircle(radiusPoints, "white", `#${f.get("cvegeo")}a`);
}

México Colors

Placement methods

new DisplacedPoints({
  ...
  placementMethod: "ring | concentric-rings | spiral | grid"
});

Ring

placementMethod: "ring"; // default

México Ring

Concentric Rings

placementMethod: "concentric-rings";

México Concentric Rings

Spiral

placementMethod: "spiral";

México Spiral

Grid

placementMethod: "grid";

México Grid

Delimit cluster

If you need delimit the clusters based on some category, use the column name with which you want to delimit on the parameter delimiterField.

new DisplacedPoints({
  ...
  delimiterField: "<field name>"
});

(distance between points)

coming soon...

References