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-osmwaysnap

v0.4.1

Published

OpenLayers Interaction Extension for Snapping Ways from OSM using Overpass API

Downloads

8

Readme

OpenLayers OSMWaySnap

OpenLayers extension for drawing line string with snapping to way elements from OpenStreetMap using OverpassAPI.

Instructions

npm install ol-osmwaysnap

Create an instance of class OSMWaySnap and add it to map. (Default snapping to OSM roads)

import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { OSMWaySnap } from 'ol-osmwaysnap';

const targetLayer = new VectorLayer<VectorSource<Feature<LineString>>>({
  source: new VectorSource<Feature<LineString>>()
});
map.addLayer(targetLayer);

// Default: Snap to roads (OSM highway)
const interaction = new OSMWaySnap({
  source: targetLayer.getSource(),
  maximumResolution: 5,
  fetchBufferSize: 250,
  overpassEndpointURL: 'https://...' // Choose one instance from https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances
});
map.addInteraction(interaction);

Or specify a custom OverpassQL for different way elements, for example to railways.

// Snap to railways
const interaction = new OSMWaySnap({
  source: targetLayer.getSource(),
  maximumResolution: 5,
  fetchBufferSize: 250,
  overpassQuery: '(way["railway"];>;);',
  overpassEndpointURL: 'https://...' // Choose one instance from https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances
});
map.addInteraction(interaction);

Or use a custom vector source (not OSM) for snapping.

const interaction = new OSMWaySnap({
  source: targetLayer.getSource(),
  waySource: someVectorSource,
  maximumResolution: 5,
  fetchBufferSize: 250
});
map.addInteraction(interaction);

Constructor Options

  • autoFocus?: boolean - True to automatically fit map view to next candidantes. (default: true)
  • focusPadding?: number - Used with autoFocus, specify number to add padding to view fitting. (default: 50 !PROJECTION SENSITIVE!)
  • sketchStyle?: StyleLike - Style of sketch features (default is predefined, overwrite if necessary)
  • source: VectorSource<Feature<LineString>> - Target source of edition
  • waySource?: VectorSource<Feature<LineString>> - Ways source for snapping (default to a new instance of OSMOverpassWaySource)
  • createAndAddWayLayer?: boolean - Create a new way layer from way source (if provided) and add to map (default: true)
  • wrapX?: boolean - WrapX
  • allowCreate?: boolean - Whether to allow creating a new feature (default: true)
  • allowEdit?: boolean - Whether allow geometry edition to start when clicking on an existing feature, the option can be later configured in allowEdit property of OSMWaySnap class (default: true)

If waySource is not provided, OSMOverpass will be used as source for snapping, so the constructor options for OSMWaySnap will be extended to include thoses options from OSMOverpassSourceBase.

Events

All event objects dispatched have property feature being the active feature of the interaction.

Event types:

  • waysnapstart: when the interaction starts on a feature whether creation or edition.
  • waysnapstartcreate: when the interaction has created a new feature.
  • waysnapstartedit: when the interaction has started edition an existing feature.
  • waysnapupdate: when the interaction has updated the active feature.
  • waysnapend: when interaction has finished.

Examples

Examples in HTML using CDN

Using as module

import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import VectorLayer from 'ol/layer/Vector';
import OSM from 'ol/source/OSM';
import VectorSource from 'ol/source/Vector';
import Feature from 'ol/Feature';
import LineString from 'ol/geom/LineString'; 
import OSMWaySnap from 'ol-osmwaysnap';

const basemap = new TileLayer({ source: new OSM() });
const targetLayer = new VectorLayer<VectorSource<Feature<LineString>>>({
  source: new VectorSource()
});

const view = new View({
  center: [11018989, 2130015],
  zoom: 16
});
const map = new Map({
  target: 'map',
  layers: [basemap, targetLayer],
  view
});

const interaction = new OSMWaySnap({
  source: targetLayer.getSource(),
  maximumResolution: 5,
  fetchBufferSize: 250,
  overpassEndpointURL: 'https://...' // Choose one instance from https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances
});
map.addInteraction(interaction);