Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]

# map-style
# @mapwhit/style-loader

Module to process and cache map style
Module to process and cache map style.

## Install

```sh
$ npm install --save map-style
$ npm install --save @mapwhit/style-loader
```

## Usage

Load map style JSON and convert to an object that handles loading of all artifacts (sprites, sources, tiles, etc.) defined in the style.

```js
var mapStyle = require('map-style');
import { styleLoader } from '../lib/style-loader.js';

mapStyle('Rainbow');
const style = await styleLoader('https://example.com/style.json', 'network-only');
```

## License

MIT © [Natalia Kowalczyk](https://melitele.me)

[npm-image]: https://img.shields.io/npm/v/@mapwhit/map-style
[npm-url]: https://npmjs.org/package/@mapwhit/map-style
[npm-image]: https://img.shields.io/npm/v/@mapwhit/style-loader
[npm-url]: https://npmjs.org/package/@mapwhit/style-loader

[build-url]: https://github.com/mapwhit/map-style/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/mapwhit/map-style/check.yaml?branch=main
[build-url]: https://github.com/mapwhit/style-loader/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/mapwhit/style-loader/check.yaml?branch=main

[deps-image]: https://img.shields.io/librariesio/release/npm/@mapwhit/map-style
[deps-url]: https://libraries.io/npm/@mapwhit%2Fmap-style
[deps-image]: https://img.shields.io/librariesio/release/npm/@mapwhit/style-loader
[deps-url]: https://libraries.io/npm/@mapwhit%2Fstyle-loader
2 changes: 1 addition & 1 deletion lib/map-style.js → lib/style-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import loader from './loader.js';
import { init as initSources, reset as resetSources } from './sources.js';
import { loadSprite, selectSprite } from './sprite.js';

export async function mapStyle(url, cacheStrategy, options = {}) {
export async function styleLoader(url, cacheStrategy, options = {}) {
const load = loader(cacheStrategy, options.cacheStore);
const style = await load(
{
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@mapwhit/map-style",
"name": "@mapwhit/style-loader",
"version": "2.0.1",
"type": "module",
"exports": "./lib/map-style.js",
"exports": "./lib/style-loader.js",
"description": "Module to process and cache map style",
"author": {
"name": "Natalia Kowalczyk",
Expand All @@ -11,11 +11,11 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/mapwhit/map-style.git"
"url": "git+https://github.com/mapwhit/style-loader.git"
},
"license": "MIT",
"keywords": [
"map-style"
"style-loader"
],
"dependencies": {
"@mapwhit/style-expressions": "^1.2.0",
Expand Down
10 changes: 5 additions & 5 deletions test/map-style.js → test/style-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import { MockAgent, setGlobalDispatcher } from 'undici';
import { initCacheStore } from '../lib/loader.js';
import { mapStyle } from '../lib/map-style.js';
import { styleLoader } from '../lib/style-loader.js';
import styleJson from './fixtures/style.json' with { type: 'json' };

test('map-style', async () => {
test('style-loader', async () => {
const agent = new MockAgent();
setGlobalDispatcher(agent);
agent
Expand All @@ -16,12 +16,12 @@ test('map-style', async () => {
})
.reply(200, styleJson);

const style = await mapStyle('https://example.com/style.json', 'network-only');
const style = await styleLoader('https://example.com/style.json', 'network-only');
assert.ok(style);
assert.equal(Object.keys(style.sources).length, 3);
});

test('map-style with caching', (_, done) => {
test('style-loader with caching', (_, done) => {
initCacheStore({
update: (_, style, type) => {
setTimeout(() => {
Expand All @@ -42,7 +42,7 @@ test('map-style with caching', (_, done) => {
})
.reply(200, styleJson);

mapStyle('https://example.com/style.json', 'network-first-then-cache').then(style => {
styleLoader('https://example.com/style.json', 'network-first-then-cache').then(style => {
assert.ok(style);
});
});