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

@open-pioneer/ogc-features

v0.4.1

Published

This package provides utilities to work with OGC API Features services.

Downloads

32

Readme

@open-pioneer/ogc-features

This package provides utilities to work with OGC API Features services.

Usage

Vector source

This vector source should be used together with a vector layer.

Inject the vector source factory by referencing "ogc-features.VectorSourceFactory":

// build.config.mjs
import { defineBuildConfig } from "@open-pioneer/build-support";

export default defineBuildConfig({
    services: {
        YourService: {
            // ...
            references: {
                vectorSourceFactory: "ogc-features.VectorSourceFactory"
            }
        }
    }
});

and use it inside a VectorLayer:

const vectorSourceFactory = ...; // injected
const vectorLayer = new VectorLayer({
    source: vectorSourceFactory.createVectorSource({
        baseUrl: "https://ogc-api.nrw.de/inspire-us-kindergarten/v1",
        collectionId: "governmentalservice",
        crs: "http://www.opengis.net/def/crs/EPSG/0/25832",

        /**
         * The maximum number of features to fetch within a single request.
         * Corresponds to the `limit` parameter in the URL.
         *
         * When the `offset` strategy is used for feature fetching, the limit
         * is used for the page size.
         *
         * Defaults to `5000`.
         */
        limit: 5000,

        /** The maximum number of concurrent requests. Defaults to `6`. */
        maxConcurrentRequests: 6,

        attributions:
            "<a href='https://www.govdata.de/dl-de/by-2-0'>Datenlizenz Deutschland - Namensnennung - Version 2.0</a>",

        additionalOptions: {} // (Optional)
    })
});

The optional limit configures the concurrent execution of requests by using the offset URL property for pagination. If the service returns a numberMatched property together with its results, it is used alongside the configured pageSize to calculate the optimal number of concurrent requests. The number of concurrent requests is never higher than maxConcurrentRequests.

Additional options of the VectorSource (see OpenLayers documentation) can be given by the property additionalOptions.

Search source

This search source is used to search in OGC API features.

Inject the search source factory by referencing "ogc-features.SearchSourceFactory":

// build.config.mjs
import { defineBuildConfig } from "@open-pioneer/build-support";

export default defineBuildConfig({
    services: {
        YourService: {
            // ...
            references: {
                ogcSearchSourceFactory: "ogc-features.SearchSourceFactory"
            }
        }
    }
});

and create a search search instance:

const ogcSearchSourceFactory = ...; // injected
const searchSource = ogcSearchSourceFactory.createSearchSource({
    label: this.intl.formatMessage({ id: "searchSources.lika" }),
    baseUrl: "https://ogc-api.nrw.de/lika/v1",
    collectionId: "flurstueck",
    searchProperty: "flurstid",
    labelProperty: "objid"
});

Use the callback function renderLabel to create a custom label for the result.

searchSourceFactory.createSearchSource({
    // ...
    renderLabel(feature) {
        const tntxt = feature?.properties?.tntxt;
        const id = feature?.id;
        if (typeof tntxt === "string") {
            return tntxt + " (" + id + ")";
        } else {
            return String(id);
        }
    }
    // ...
});

The label is generated by one of the following methods, weighted by order:

  1. renderLabel function
  2. labelProperty
  3. searchProperty

To overwrite the service URL, use the callback function rewriteUrl. This is useful, for example, to return only a specific attribute in the response, as in the following example:

searchSourceFactory.createSearchSource({
    // ...
    rewriteUrl(url) {
        url.searchParams.set("properties", "objid");
        return url;
    }
    // ...
});

License

Apache-2.0 (see LICENSE file)