GithubHelp home page GithubHelp logo

Comments (6)

simonw avatar simonw commented on June 9, 2024

I think the way to do this is with custom columns which can be returned for the rows. Maybe something like this:

select
  photo_url || '?w=800&h=400&fit=crop' as popup_image,
  name as popup_title,
  substr(description, 0, 200) as popup_description,
  '/browse/museums/' || id as popup_link,
  latitude, longitude from museums
where id in (26, 27) order by id

https://www.niche-museums.com/browse?sql=select%0D%0A++photo_url+%7C%7C+%27%3Fw%3D800%26h%3D400%26fit%3Dcrop%27+as+popup_image%2C%0D%0A++name+as+popup_title%2C%0D%0A++substr%28description%2C+0%2C+200%29+as+popup_description%2C%0D%0A++%27%2Fbrowse%2Fmuseums%2F%27+%7C%7C+id+as+popup_link%2C%0D%0A++latitude%2C+longitude+from+museums%0D%0Awhere+id+in+%2826%2C+27%29+order+by+id

Or bundle it into JSON like this:

select json_object(
  'image', photo_url || '?w=800&h=400&fit=crop',
  'title', name,
  'description', substr(description, 0, 200),
  'link', '/browse/museums/' || id
  ) as popup,
  latitude, longitude from museums
where id in (26, 27) order by id

https://www.niche-museums.com/browse?sql=select+json_object%28%0D%0A++%27image%27%2C+photo_url+%7C%7C+%27%3Fw%3D800%26h%3D400%26fit%3Dcrop%27%2C%0D%0A++%27title%27%2C+name%2C%0D%0A++%27description%27%2C+substr%28description%2C+0%2C+200%29%2C%0D%0A++%27link%27%2C+%27%2Fbrowse%2Fmuseums%2F%27+%7C%7C+id%0D%0A++%29+as+popup%2C%0D%0A++latitude%2C+longitude+from+museums%0D%0Awhere+id+in+%2826%2C+27%29+order+by+id

from datasette-cluster-map.

simonw avatar simonw commented on June 9, 2024

The JSON method is more aesthetically pleasing to me, so I'll go with that.

from datasette-cluster-map.

simonw avatar simonw commented on June 9, 2024
{
    "image": "https://niche-museums.imgix.net/dodgems.heic?w=800&h=400&fit=crop",
    "title": "Dingles Fairground Heritage Centre",
    "description": "Home of the National Fairground Collection, Dingles has over 45,000 indoor square feet of  vintage fairground rides... and you can go on them! Highlights include the last complete surviving and opera",
    "link": "/browse/museums/26"
}

from datasette-cluster-map.

simonw avatar simonw commented on June 9, 2024

Demo is running here now: https://www.niche-museums.com/browse?sql=select+json_object(%0D%0A++%27image%27%2C+photo_url+||+%27%3Fw%3D800%26h%3D400%26fit%3Dcrop%27%2C%0D%0A++%27title%27%2C+name%2C%0D%0A++%27description%27%2C+substr(description%2C+0%2C+200)%2C%0D%0A++%27link%27%2C+%27%2Fbrowse%2Fmuseums%2F%27+||+id%0D%0A++)+as+popup%2C%0D%0A++latitude%2C+longitude+from+museums%0D%0Awhere+id+in+(26%2C+27)+order+by+id

from datasette-cluster-map.

simonw avatar simonw commented on June 9, 2024

Documentation: https://github.com/simonw/datasette-cluster-map/blob/c1329b6edd85c2ecbb098d5bb3b6c2c22b2493ba/README.md#custom-marker-popups

from datasette-cluster-map.

simonw avatar simonw commented on June 9, 2024

Another demo: https://bigfoot-data.glitch.me/data?sql=select%0D%0A++longitude%2C%0D%0A++latitude%2C%0D%0A++json_object%28%0D%0A++++%27description%27%2C%0D%0A++++substr%28%0D%0A++++++description%2C%0D%0A++++++23%2C%0D%0A++++++instr%28description%2C+%27http%3A%2F%2F%27%29+-+23%0D%0A++++%29%2C%0D%0A++++%27link%27%2C%0D%0A++++substr%28description%2C+instr%28description%2C+%27http%3A%2F%2F%27%29%29%0D%0A++%29+as+popup%0D%0Afrom%0D%0A++bigfoot%0D%0Aorder+by%0D%0A++rowid%0D%0Alimit%0D%0A++1001

From https://twitter.com/simonw/status/1263668857174020096

from datasette-cluster-map.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.