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-gl-ogc-feature-collection

v0.0.3

Published

A small package for requesting geojson from an OGC Feature API endpoint to serve tiles in MapBox/MapLibre.

Downloads

402

Readme

mapbox-gl-ogc-feature-collection

A small package for requesting geojson from an OGC Feature API endpoint to serve tiles in MapBox/MapLibre.

Built with inspiration from mapbox-gl-arcgis-featureserver.

Demo

Check out the demo at this link. This demo pulls in large lakes OGC Feature API collection at https://demo.pygeoapi.io/stable. In the demo, we are using the collection lakes.

demo image

Basic Usage

import OGCFeatureCollection from 'mapbox-gl-ogc-feature-collection'

map.on('load', () => {
    const sourceId = 'collection-src'

    new OGCFeatureCollection(sourceId, map, {
        url: 'https://demo.pygeoapi.io/stable',
        collectionId: 'lakes',
        limit: 10000
    })

    map.addLayer({
        'id': 'lyr',
        'source': sourceId,
        'type': 'fill',
        'paint': {
            'fill-color': '#B42222',
            'fill-opacity': 0.7
        }
    })
})

API

This library exposes a single OGCFeatureCollection class

Constructor Options

| Option | Type | Description | --- | --- | --- | sourceId | String required | A string | | map | Object required | A mapbox-gl or maplibre-gl map instance. | | collectionOptions | Object required | A range of options which will be used to manage the collection. See below. | | geojsonSourceOptions | Object | A object which will be passed to the creation of the mapbox-gl geojson source |

Collection Options

| Option | Type | Default | Description | --- | --- | --- | --- | url | String required | | The base url of the OGC Feature API. https://demo.pygeoapi.io/covid-19.| | collectionId | String required | | The name of the collection. cases_country.| | limit | Number | 5000 | Number of features to return in each tile. | | properties | String | | List of properties to return for each feature. | | datetime | Date | | Date or date range to filter items. | | bbox | String | | Apply bbox to items to only show in certain area. -180,-90,180,90 | | useStaticZoomLevel | Boolean | false | Whether to only get tiles at a single zoom level. If true then set minZoom to the desired level. | | minZoom | Number | if useStaticZoom is true then 7, otherwise 2 | The zoom level to start requesting tiles. |

Methods

| Method | Description | ------- | ----------- | destroySource() | Important The destroySource() method removes the source from the map and associated event listeners for retrieving data which request data as the map is panned, so it's important to call this method if removing the layer from the map completely. | | disableRequests() | Important The disableRequests() method temporarily disables the associated event listeners for retrieving data which request data as the map is panned, you may want to call this if you toggle your layer off. | | enableRequests() | Important The enableRequests() method enables the associated event listeners for retrieving data which request data as the map is panned. By default this is called by the constructor. |

Example of disabling and enabling requests

It would be nice if disabling/enabling of requests happened automatically but unfortunately I haven't found a way to make that happen because of how sources and layers are managed in mapbox-gl.

import OGCFeatureCollection from 'mapbox-gl-ogc-feature-collection'

map.on('load', () => {
    const sourceId = 'collection-src'
    const lyrId = 'lyr'

    const service = new OGCFeatureCollection(sourceId, map, {
        url: 'https://demo.pygeoapi.io/stable',
        collectionId: 'lakes',
        limit: 10000
    })

    map.addLayer({
        'id': 'lyr',
        'source': sourceId,
        'type': 'fill',
        'paint': {
            'fill-color': '#B42222',
            'fill-opacity': 0.7
        }
    })
})
    
    
function hideFsLayer () {
    map.setLayoutProperty(lyrId, 'visibility', 'none')
    service.disableRequests()
}
function showFsLayer () {
    map.setLayoutProperty(lyrId, 'visibility', 'visible')
    service.enableRequests()
}
function removeFsCompletelyFromMap () {
    map.removeLayer(lyrId)
    service.destroySource()
}