-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support serving Style Map Package maps #881
Conversation
057f5ef
to
94c825d
Compare
|
Status | Count |
---|---|
74 | |
9 |
Click to toggle table visibility
Name | Status | Previous | Current |
---|---|---|---|
@fastify/static |
7.0.3 | 7.0.4 | |
@mapbox/jsonlint-lines-primitives |
- | 2.0.2 | |
@mapbox/sphericalmercator |
- | 1.2.0 | |
@mapbox/unitbezier |
- | 0.0.1 | |
@maplibre/maplibre-gl-style-spec |
- | 20.3.1 | |
@placemarkio/check-geojson |
- | 0.1.12 | |
@turf/bbox |
- | 7.1.0 | |
@turf/helpers |
- | 7.1.0 | |
@turf/meta |
- | 7.1.0 | |
@types/geojson |
- | 7946.0.14 | |
ansi-diff |
- | 1.2.0 | |
ansi-split |
- | 1.0.1 | |
archiver-utils |
- | 5.0.2 | |
archiver |
- | 7.0.1 | |
arr-union |
- | 3.1.0 | |
assign-symbols |
- | 1.0.0 | |
async |
- | 3.2.6 | |
buffer-peek-stream |
- | 1.1.0 | |
bundle-name |
- | 4.1.0 | |
bytewise-core |
- | 1.2.3 | |
bytewise |
- | 1.1.0 | |
cli-spinners |
- | 2.9.2 | |
clone |
- | 1.0.4 | |
compress-commons |
- | 6.0.2 | |
core-util-is |
- | 1.0.3 | |
crc-32 |
- | 1.2.2 | |
crc32-stream |
- | 6.0.0 | |
default-browser-id |
- | 5.0.0 | |
default-browser |
- | 5.2.1 | |
defaults |
- | 1.0.4 | |
define-lazy-prop |
- | 3.0.0 | |
extend-shallow |
- | 2.0.1 | |
fastify |
4.26.2 | 4.28.1 | |
filter-obj |
- | 6.1.0 | |
get-east-asian-width |
- | 1.2.0 | |
get-value |
- | 2.0.6 | |
into-stream |
- | 8.0.1 | |
is-docker |
- | 3.0.0 | |
is-extendable |
- | 0.1.1 | |
is-inside-container |
- | 1.0.0 | |
is-interactive |
- | 2.0.0 | |
is-plain-object |
- | 2.0.4 | |
is-unicode-supported |
- | 2.1.0 | |
is-wsl |
- | 3.1.0 | |
isobject |
- | 3.0.1 | |
json-stringify-pretty-compact |
- | 4.0.0 | |
ky |
- | 1.7.2 | |
lazystream |
- | 1.0.1 | |
log-symbols |
- | 7.0.0 | |
mimic-function |
- | 5.0.1 | |
minimist |
1.2.7 | 1.2.8 | |
normalize-path |
- | 3.0.0 | |
open |
- | 10.1.0 | |
ora |
- | 8.1.0 | |
package-json-from-dist |
- | 1.0.1 | |
parse-ms |
- | 4.0.0 | |
pino-abstract-transport |
1.1.0 | 1.2.0 | |
pino-std-serializers |
6.2.2 | 7.0.0 | |
pino |
8.20.0 | 9.4.0 | |
pretty-bytes |
- | 6.1.1 | |
pretty-ms |
- | 9.1.0 | |
process-nextick-args |
- | 2.0.1 | |
quickselect |
- | 2.0.0 | |
readdir-glob |
- | 1.1.3 | |
run-applescript |
- | 7.0.0 | |
rw |
- | 1.3.3 | |
safe-stable-stringify |
2.4.3 | 2.5.0 | |
set-value |
- | 2.0.1 | |
sonic-boom |
3.8.1 | 4.1.0 | |
sort-asc |
- | 0.2.0 | |
sort-desc |
- | 0.2.0 | |
sort-object |
- | 3.0.3 | |
split-string |
- | 3.1.0 | |
stdin-discarder |
- | 0.2.2 | |
styled-map-package |
- | 1.0.1 | |
thread-stream |
2.4.1 | 3.1.0 | |
tinyqueue |
- | 3.0.0 | |
typewise-core |
- | 1.2.0 | |
typewise |
- | 1.0.3 | |
union-value |
- | 1.0.1 | |
wcwidth |
- | 1.0.1 | |
yoctocolors |
- | 2.1.1 | |
zip-stream |
- | 6.0.1 |
// @ts-expect-error Need to publish types for module | ||
import { Reader } from 'styled-map-package' | ||
|
||
/** @import {FastifyPluginAsync} from 'fastify' */ | ||
// @ts-expect-error Need to publish types for module | ||
/** @import {Resource} from 'styled-map-package/reader' */ | ||
// @ts-expect-error Need to publish types for module | ||
/** @import {SMPStyle} from 'styled-map-package/types' */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that these ignores are allowing tests to run without immediately failing
// 1. Attempt to use the styled map package | ||
{ | ||
const style = await fastify.comapeoSmp.getStyle().catch(() => { | ||
fastify.log.warn('Cannot read styled map package archive') | ||
return null | ||
}) | ||
|
||
if (style) { | ||
return style | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the assumption that we want to give highest precedence to an SMP if possible
One thing that this PR doesn't fully address is this requirement listed in the issue:
Not really sure what the best way to expose this information will be.
Maybe all of this is out of scope for this PR. In which case I can either:
|
|
Status | Count |
---|---|
74 | |
9 |
Click to toggle table visibility
Name | Status | Previous | Current |
---|---|---|---|
@fastify/static |
7.0.3 | 7.0.4 | |
@mapbox/jsonlint-lines-primitives |
- | 2.0.2 | |
@mapbox/sphericalmercator |
- | 1.2.0 | |
@mapbox/unitbezier |
- | 0.0.1 | |
@maplibre/maplibre-gl-style-spec |
- | 20.3.1 | |
@placemarkio/check-geojson |
- | 0.1.12 | |
@turf/bbox |
- | 7.1.0 | |
@turf/helpers |
- | 7.1.0 | |
@turf/meta |
- | 7.1.0 | |
@types/geojson |
- | 7946.0.14 | |
ansi-diff |
- | 1.2.0 | |
ansi-split |
- | 1.0.1 | |
archiver-utils |
- | 5.0.2 | |
archiver |
- | 7.0.1 | |
arr-union |
- | 3.1.0 | |
assign-symbols |
- | 1.0.0 | |
async |
- | 3.2.6 | |
buffer-peek-stream |
- | 1.1.0 | |
bundle-name |
- | 4.1.0 | |
bytewise-core |
- | 1.2.3 | |
bytewise |
- | 1.1.0 | |
cli-spinners |
- | 2.9.2 | |
clone |
- | 1.0.4 | |
compress-commons |
- | 6.0.2 | |
core-util-is |
- | 1.0.3 | |
crc-32 |
- | 1.2.2 | |
crc32-stream |
- | 6.0.0 | |
default-browser-id |
- | 5.0.0 | |
default-browser |
- | 5.2.1 | |
defaults |
- | 1.0.4 | |
define-lazy-prop |
- | 3.0.0 | |
extend-shallow |
- | 2.0.1 | |
fastify |
4.26.2 | 4.28.1 | |
filter-obj |
- | 6.1.0 | |
get-east-asian-width |
- | 1.2.0 | |
get-value |
- | 2.0.6 | |
into-stream |
- | 8.0.1 | |
is-docker |
- | 3.0.0 | |
is-extendable |
- | 0.1.1 | |
is-inside-container |
- | 1.0.0 | |
is-interactive |
- | 2.0.0 | |
is-plain-object |
- | 2.0.4 | |
is-unicode-supported |
- | 2.1.0 | |
is-wsl |
- | 3.1.0 | |
isobject |
- | 3.0.1 | |
json-stringify-pretty-compact |
- | 4.0.0 | |
ky |
- | 1.7.2 | |
lazystream |
- | 1.0.1 | |
log-symbols |
- | 7.0.0 | |
mimic-function |
- | 5.0.1 | |
minimist |
1.2.7 | 1.2.8 | |
normalize-path |
- | 3.0.0 | |
open |
- | 10.1.0 | |
ora |
- | 8.1.0 | |
package-json-from-dist |
- | 1.0.1 | |
parse-ms |
- | 4.0.0 | |
pino-abstract-transport |
1.1.0 | 1.2.0 | |
pino-std-serializers |
6.2.2 | 7.0.0 | |
pino |
8.20.0 | 9.4.0 | |
pretty-bytes |
- | 6.1.1 | |
pretty-ms |
- | 9.1.0 | |
process-nextick-args |
- | 2.0.1 | |
quickselect |
- | 2.0.0 | |
readdir-glob |
- | 1.1.3 | |
run-applescript |
- | 7.0.0 | |
rw |
- | 1.3.3 | |
safe-stable-stringify |
2.4.3 | 2.5.0 | |
set-value |
- | 2.0.1 | |
sonic-boom |
3.8.1 | 4.1.0 | |
sort-asc |
- | 0.2.0 | |
sort-desc |
- | 0.2.0 | |
sort-object |
- | 3.0.3 | |
split-string |
- | 3.1.0 | |
stdin-discarder |
- | 0.2.2 | |
styled-map-package |
- | 1.0.1 | |
thread-stream |
2.4.1 | 3.1.0 | |
tinyqueue |
- | 3.0.0 | |
typewise-core |
- | 1.2.0 | |
typewise |
- | 1.0.3 | |
union-value |
- | 1.0.1 | |
wcwidth |
- | 1.0.1 | |
yoctocolors |
- | 2.1.1 | |
zip-stream |
- | 6.0.1 |
|
Status | Count |
---|---|
74 | |
9 |
Click to toggle table visibility
Name | Status | Previous | Current |
---|---|---|---|
@fastify/static |
7.0.3 | 7.0.4 | |
@mapbox/jsonlint-lines-primitives |
- | 2.0.2 | |
@mapbox/sphericalmercator |
- | 1.2.0 | |
@mapbox/unitbezier |
- | 0.0.1 | |
@maplibre/maplibre-gl-style-spec |
- | 20.3.1 | |
@placemarkio/check-geojson |
- | 0.1.12 | |
@turf/bbox |
- | 7.1.0 | |
@turf/helpers |
- | 7.1.0 | |
@turf/meta |
- | 7.1.0 | |
@types/geojson |
- | 7946.0.14 | |
ansi-diff |
- | 1.2.0 | |
ansi-split |
- | 1.0.1 | |
archiver-utils |
- | 5.0.2 | |
archiver |
- | 7.0.1 | |
arr-union |
- | 3.1.0 | |
assign-symbols |
- | 1.0.0 | |
async |
- | 3.2.6 | |
buffer-peek-stream |
- | 1.1.0 | |
bundle-name |
- | 4.1.0 | |
bytewise-core |
- | 1.2.3 | |
bytewise |
- | 1.1.0 | |
cli-spinners |
- | 2.9.2 | |
clone |
- | 1.0.4 | |
compress-commons |
- | 6.0.2 | |
core-util-is |
- | 1.0.3 | |
crc-32 |
- | 1.2.2 | |
crc32-stream |
- | 6.0.0 | |
default-browser-id |
- | 5.0.0 | |
default-browser |
- | 5.2.1 | |
defaults |
- | 1.0.4 | |
define-lazy-prop |
- | 3.0.0 | |
extend-shallow |
- | 2.0.1 | |
fastify |
4.26.2 | 4.28.1 | |
filter-obj |
- | 6.1.0 | |
get-east-asian-width |
- | 1.2.0 | |
get-value |
- | 2.0.6 | |
into-stream |
- | 8.0.1 | |
is-docker |
- | 3.0.0 | |
is-extendable |
- | 0.1.1 | |
is-inside-container |
- | 1.0.0 | |
is-interactive |
- | 2.0.0 | |
is-plain-object |
- | 2.0.4 | |
is-unicode-supported |
- | 2.1.0 | |
is-wsl |
- | 3.1.0 | |
isobject |
- | 3.0.1 | |
json-stringify-pretty-compact |
- | 4.0.0 | |
ky |
- | 1.7.2 | |
lazystream |
- | 1.0.1 | |
log-symbols |
- | 7.0.0 | |
mimic-function |
- | 5.0.1 | |
minimist |
1.2.7 | 1.2.8 | |
normalize-path |
- | 3.0.0 | |
open |
- | 10.1.0 | |
ora |
- | 8.1.0 | |
package-json-from-dist |
- | 1.0.1 | |
parse-ms |
- | 4.0.0 | |
pino-abstract-transport |
1.1.0 | 1.2.0 | |
pino-std-serializers |
6.2.2 | 7.0.0 | |
pino |
8.20.0 | 9.4.0 | |
pretty-bytes |
- | 6.1.1 | |
pretty-ms |
- | 9.1.0 | |
process-nextick-args |
- | 2.0.1 | |
quickselect |
- | 2.0.0 | |
readdir-glob |
- | 1.1.3 | |
run-applescript |
- | 7.0.0 | |
rw |
- | 1.3.3 | |
safe-stable-stringify |
2.4.3 | 2.5.0 | |
set-value |
- | 2.0.1 | |
sonic-boom |
3.8.1 | 4.1.0 | |
sort-asc |
- | 0.2.0 | |
sort-desc |
- | 0.2.0 | |
sort-object |
- | 3.0.3 | |
split-string |
- | 3.1.0 | |
stdin-discarder |
- | 0.2.2 | |
styled-map-package |
- | 1.0.1 | |
thread-stream |
2.4.1 | 3.1.0 | |
tinyqueue |
- | 3.0.0 | |
typewise-core |
- | 1.2.0 | |
typewise |
- | 1.0.3 | |
union-value |
- | 1.0.1 | |
wcwidth |
- | 1.0.1 | |
yoctocolors |
- | 2.1.1 | |
zip-stream |
- | 6.0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a read through this today. This is the first time I am reading the code from the maps plugin, so some comments are not directly related to this PR, but we may want to consider them when implementing this. I'll try my best to separate the two, but some decisions in the current implementation mean that we need to do a lot more work here, so it may be worth while fixing those now rather than doing extra work.
PR specific comments
I do recommend using the styled-map-package
server plugin. With the latest fixes I think it should do everything needed in a self-contained way, and if it doesn't we should fix that upstream.
For the client requirements of date added, storage used, and name, I think we should add a route outside the plugin. We don't need access to the Reader
instance for it, we can do something like:
fastify.get('/smp/info', async (req, reply) => {
const stats = await fs.stat(smpFilepath)
const style = await fetch('/smp/style.json').json()
return {
created: stats.ctime,
size: stats.size
name: style.name || path.parse(smpFilepath).name
}
})
fastify.register(smpPlugin)
For selecting a style to server based on availability we have a few options:
- Either use decorator methods or fetch upstream to load style.json into memory, then return that.
- No decorator methods, and proxy everything (local or remote) either with our own
fetch
or with@fastify/reply-from
. HEAD
requests then302
redirects.
My preference is (3) because I think it's the simplest (pseudo-code):
fastify.get('style.json', async (req, reply) => {
const res = await fetch({ method: 'HEAD', url: styleUrl }).catch(noop)
if (res && res.status === 200) reply.status(302).setHeader('location', styleUrl)
})
Architecture opinions
- I think we should just drop
static-maps
right now. We haven't released anything that supports this, and we haven't communicated any support for it, and keeping it just adds maintenance burden and the need to handle backwards compatibility. - I think we're making things hard for ourselves by exposing each of the "sub-plugins" outside of this module - we're leaking our implementation details. I think the maps plugin should be a single plugin. Otherwise we don't control the order the sub-plugins are registered, and we need to reach into internals by decorating everything.
- Why not register the maps plugin in Mapeo Manager rather than export it as a separate thing?
- Rather than trying to decorate the plugin with the
getStyleJsonUrl()
method, maybe move that intoMapeoManager
like with the blob and icon servers (easy to do if registering internally) - I think it's worth using styled map package for the fallback map too, to simplify things, see https://github.com/digidem/comapeo-fallback-smp
There may well be very valid reasons for not choosing to do things this way. I'm happy to jump on a quick call about it, rather than you needing to write down a justification for everything here.
@gmaclennan thanks for the feedback! i think it all makes sense and I honestly don't have any strong arguments against the suggestions regarding architecture. At the time I initially worked on the maps plugin, I wasn't aware of the options for style selection that you've outlined, which is how i ended up with this weird setup 😄 fully agree that I would just re-use the smp fastify plugin from upstream, i just didn't want to be blocked on the issues I originally encountered (since you were focusing on other things). Those have been addressed at this point (once published) so I'll need to update the PR with that. As for updating the general implementation of the maps plugin, would you suggest I do that in a separate PR that this PR stacks on top of? feels like trying to do that work after updating and merging this one would be annoying vs the other way around |
Closing this PR in favor of a completely new one that will significantly simplify how the maps plugin works, based on the suggestions provided above |
Closes #827
Still blocked on the following:
Need to add a couple of more tests I think.DONEI didn't upload the fixture that I was using for the tests since I wasn't sure if we had a particular approach for it just yet. I've been using an SMP generated from the command listed hereAdded a fixture as describedTypes are not published with
styled-map-package
, as that's blocked on fix: include type definitions when publishing styled-map-package#21Implementation notes:
I made the decision to avoid using the fastify plugin implementation that comes with
styled-map-package
due to the following reasons:Reader
instance because it doesn't expose the internal one that it creates at all. not the worst thing but figured that given the other issue, I might as well address this issue by re-working the plugin.open to input about the name of the decorator and the plugin that this PR introduces. I currently call it
comapeoSmp
andcomapeo-styled-map-package
, respectfully.not entirely too happy about the plugin implementation i have right now, which is kind of related to my thinking that maybe i'm holding fastify wrong a bit. open to feedback on cleaner approaches.