LyonDataViz / occupapp

Occupapp
https://occupapp.now.sh/
GNU General Public License v3.0
3 stars 2 forks source link

Share persistent link (include dots and image choice) #32

Open romsson opened 4 years ago

romsson commented 4 years ago

Create a url that contains positions and image choice. URL should be updated after each interaction so a page refresh re-loads exactly where the points were.

Eventually include/anticipate some more parameters (categories, etc.)

Eventually shorten the url (url limit is 2k chars)

Note (@severo): don't remember the uploaded pictures. See #52 for that feature.

severo commented 4 years ago

See https://twitter.com/ilyabo/status/1210112298234339328 for example

Their URLs: https://flowmap.blue/1icUMT7Q3V0DOPHBahXJlz7Mz_BYOgLv9InZUHX_5xIE?v=49.272478,5.910396,5.91&a=1&b=1&c=0&d=1&lt=0&col=Sunset&f=24

So:

severo commented 4 years ago

geojson.io allows the user to save the state to a gist (or to a new file in any of your GitHub repositories!):

http://geojson.io/#id=gist:severo/ea0b5a136625e915bf4ecbd828a11da7&map=6/-16.400/-63.550

(see created gist at https://gist.github.com/severo/ea0b5a136625e915bf4ecbd828a11da7 - API reference: https://developer.github.com/v3/gists/)

But obviously, you have to give some rights to the app (too much in the case of geojson.io!)

Capture d’écran de 2020-01-07 19-00-39

severo commented 4 years ago

https://blockbuilder.org/ does the same: it saves the code and data to gists, and requires the user to be authenticated to github and give some rights to the app (it's much less intrusive than geojson!)

Capture d’écran de 2020-01-07 19-15-53

The block: https://bl.ocks.org/severo/e85697db4fb9080ef685404aba785616/89a9faab8b5ab358aa342b441bb985b792b81d00 The gist: https://gist.github.com/severo/e85697db4fb9080ef685404aba785616

Beware: the GIST API doesn't allow to upload images nor any other binary data, just text!

Capture d’écran de 2020-01-07 19-19-55

severo commented 4 years ago

In order to save images, we might use the Imgur API. It allows 1.250 uploads per day from the application (for all the app users).

severo commented 4 years ago

The discussions:

severo commented 4 years ago

We will only share the "state parameters" in this issue. Data and media hosting are treated in #52.

severo commented 4 years ago

See the Vega specification editor. It allows to save a whole Vega specification in the URL, for example:

https://vega.github.io/editor/#/url/vega-lite/N4KABGBEAkDODGALApgWwIaQFxUQFzwAdYsB6UgN2QHN0A6agSz0QFcAjOxge1IRQyUa6ALQAbZskoBmOgCtY3AHaQANOCgATdHkw5gUVgCcx2LTvSkmLDnXiwKkAL7qIkDEYDWZ0BDd4AT0JkM0gJJRDXP0hCbkYlPDM8I1ZkDRcNSGT0JVgAM24jVDMAbV9ovEZUZABVJWZQ7QC1KDzGZDFNUMrqlsh0WEb0ZvTVMHK3dGpqI2E8EJwSjT9xyDaOrpxIeG5WBL6B0IwADwB9RF2jQbHIbkJQ9CNqE+dlsABdKLcZ3cJ2ZsWkCakHeo3Gb226DE8FYYh0C3MeFYqDoJ3Ol1gdl2+xuhy2Oz2iTBEyg8ChMLh8yGSJRaIuxkxPUiUDxUCZkGJEIA7vFNNwuaUSW47qEjDlvF9oqzIGKlN43k5PhDFEZEosDGt2p1QgScVBCppkEZGsgEMglJp4tRIGBFZLID9WH8AWASkDhiDOStNWJ5sattoaXRZZ4wABeCNgACMHIgLnB3rJ0Nh8KGAQAFIHkXQmgBKcORgAMYAA-GAAOxgHBNTM6bN5g6DLYGo2x21KtzmnaWpTW-QQ44+N5udbagMeyX+III25GHtQtTDtlVWr1NXmZqTqAq9dugCyyj6ABVUn0AOrILo3I9sPoAMSMjD6AGUdC+9p6VhlvS3-QmVq0WqbPqc6tluWTTqEACOrA5JUuiVFQbZxvaLpCoBGzdCui4AWykFbPMqCxGKpjgUydQNFs9JXMhtr2ng3DcL6jD3P2uGaph+LYokZH4VAMFwcwOiMEhCrpCATggEAA

From the editor:

Share

We pack the Vega or Vega-Lite specification and an encoded string in the URL.

We use LZ-based compression algorithm and preserve indentation, newlines, and other whitespace.

Number of charaters in the URL: 865

Code is at https://github.com/vega/editor/blob/master/src/components/header/share-modal/renderer.tsx#L28:

    const serializedSpec =
      LZString.compressToEncodedURIComponent(this.props.editorString) + (this.state.fullScreen ? '/view' : '');
    if (serializedSpec) {
      const url = `${document.location.href.split('#')[0]}#/url/${this.props.mode}/${serializedSpec}`;

Uses lz-string. Not sure if it's still maintained, but it's a lot more lightweight (4kB) than pako (786kB).

See a comparison at https://observablehq.com/@severo/hello-lz-string