Embedding a map widget in the DrRacket REPL

132 views
Skip to first unread message

Alex Harsanyi

unread,
Sep 4, 2019, 5:41:55 AM9/4/19
to Racket Users

As part of another project, I had to update my map-widget to act as a snip% so it can be inserted into a pasteboard%.   An unintended side benefit of this work is that maps can now be embedded in the DrRacket REPL -- this in itself is not very useful, but it does make for a cool demo, so I thought I would record a video of it and share it here:  https://youtu.be/MrS0FG-X8DI

Here is a screenshot too:

map-snip-demo.PNG



For those who want to try it out, you can install the map-widget package, than type the following in the REPL:

    (require map-widget)
    (new map-snip%)

Note that map tile download is not very fast, but the code does cache all downloaded data locally, this means that once tiles are downloaded, subsequent runs which show the same area will be fast.  In the linked video you don't see any tiles being loaded, as I did a practice run before recording it and all map data was locally available, making it load instantly -- you can do that too if you run the code a second time.

And in case you want to have a look at the code itself, it is here: https://github.com/alex-hhh/map-widget

Enjoy,
Alex.

Sage Gerard

unread,
Sep 4, 2019, 7:20:49 AM9/4/19
to alexha...@gmail.com, racket...@googlegroups.com
How cool is that! DrRacket's flexibility is pretty amazing



-------- Original Message --------
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/fdc50657-4125-4c2f-b0a9-03bc701fe869%40googlegroups.com.

Stephen De Gabrielle

unread,
Sep 4, 2019, 7:50:19 AM9/4/19
to Sage Gerard, alexha...@gmail.com, racket...@googlegroups.com
Dr Racket is amazing. Need to a demo of this and plot side by side. 

DrRacket is so close to being an electronic lab notebook it’s almost painful....

Stephen

--
----

Laurent

unread,
Sep 5, 2019, 10:14:15 AM9/5/19
to Stephen De Gabrielle, Sage Gerard, Alex Harsanyi, racket-users@googlegroups.com List
This is utterly cool!

If I may, I suggest to rebind up and down to page up and page down (or even the converse, as "down" means to me "go downwards towards Earth"), use the arrows to navigate NESW, and bind mouse scrolls to zooming too.

A package containing a database of the positions of the major cities and countries would be nice too :)

Alex Harsanyi

unread,
Sep 5, 2019, 11:59:56 PM9/5/19
to Racket Users


On Wednesday, September 4, 2019 at 7:50:19 PM UTC+8, Stephen De Gabrielle wrote:
Dr Racket is amazing. Need to a demo of this and plot side by side. 

I can do better than just put a plot and a map widget side by side: https://youtu.be/R2KU0ZvIJws

Alex.
 

DrRacket is so close to being an electronic lab notebook it’s almost painful....

Stephen
On Wed, 4 Sep 2019 at 12:20, Sage Gerard <sa...@sagegerard.com> wrote:
How cool is that! DrRacket's flexibility is pretty amazing



-------- Original Message --------
On Sep 4, 2019, 5:41 AM, Alex Harsanyi < alexha...@gmail.com> wrote:


As part of another project, I had to update my map-widget to act as a snip% so it can be inserted into a pasteboard%.   An unintended side benefit of this work is that maps can now be embedded in the DrRacket REPL -- this in itself is not very useful, but it does make for a cool demo, so I thought I would record a video of it and share it here:  https://youtu.be/MrS0FG-X8DI

Here is a screenshot too:

map-snip-demo.PNG



For those who want to try it out, you can install the map-widget package, than type the following in the REPL:

    (require map-widget)
    (new map-snip%)

Note that map tile download is not very fast, but the code does cache all downloaded data locally, this means that once tiles are downloaded, subsequent runs which show the same area will be fast.  In the linked video you don't see any tiles being loaded, as I did a practice run before recording it and all map data was locally available, making it load instantly -- you can do that too if you run the code a second time.

And in case you want to have a look at the code itself, it is here: https://github.com/alex-hhh/map-widget

Enjoy,
Alex.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/fdc50657-4125-4c2f-b0a9-03bc701fe869%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.
--
----

Alex Harsanyi

unread,
Sep 6, 2019, 1:42:01 AM9/6/19
to Racket Users


On Thursday, September 5, 2019 at 10:14:15 PM UTC+8, Laurent wrote:
This is utterly cool!

If I may, I suggest to rebind up and down to page up and page down (or even the converse, as "down" means to me "go downwards towards Earth"), use the arrows to navigate NESW, and bind mouse scrolls to zooming too.

The map-snip% already uses the mouse wheel for zooming, but DrRacket binds those events to scroll the REPL window up and down, so the snip never receives these events -- this is the reason why I added the "up" and "down" keys.   The REPL example is just a side benefit of using snips for the map object, but for my own use, I put the map-snip% in a pasteboard% which I fully control, so the keyboard navigation is not an issue.  Perhaps I'll add some keymap% bindings for more general control of the map snip, so that users can bind whatever keys they prefer...
 

A package containing a database of the positions of the major cities and countries would be nice too :)


A general facility able to resolve location names to GPS coordinates would be a lot of work, and I don't have time for such a thing.  Sorry.

Alex.

 
On Wed, Sep 4, 2019 at 12:50 PM Stephen De Gabrielle <spdega...@gmail.com> wrote:
Dr Racket is amazing. Need to a demo of this and plot side by side. 

DrRacket is so close to being an electronic lab notebook it’s almost painful....

Stephen
On Wed, 4 Sep 2019 at 12:20, Sage Gerard <sa...@sagegerard.com> wrote:
How cool is that! DrRacket's flexibility is pretty amazing



-------- Original Message --------
On Sep 4, 2019, 5:41 AM, Alex Harsanyi < alexha...@gmail.com> wrote:


As part of another project, I had to update my map-widget to act as a snip% so it can be inserted into a pasteboard%.   An unintended side benefit of this work is that maps can now be embedded in the DrRacket REPL -- this in itself is not very useful, but it does make for a cool demo, so I thought I would record a video of it and share it here:  https://youtu.be/MrS0FG-X8DI

Here is a screenshot too:

map-snip-demo.PNG



For those who want to try it out, you can install the map-widget package, than type the following in the REPL:

    (require map-widget)
    (new map-snip%)

Note that map tile download is not very fast, but the code does cache all downloaded data locally, this means that once tiles are downloaded, subsequent runs which show the same area will be fast.  In the linked video you don't see any tiles being loaded, as I did a practice run before recording it and all map data was locally available, making it load instantly -- you can do that too if you run the code a second time.

And in case you want to have a look at the code itself, it is here: https://github.com/alex-hhh/map-widget

Enjoy,
Alex.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/fdc50657-4125-4c2f-b0a9-03bc701fe869%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.
--
----

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.

Stephen De Gabrielle

unread,
Sep 6, 2019, 4:57:36 AM9/6/19
to Racket Users
That is awesome - 

How you make your videos? - I like the annotations.

Kind regards

Stephen

Robby Findler

unread,
Sep 6, 2019, 7:54:21 AM9/6/19
to Alex Harsanyi, Racket Users
Wow, thank you!

Robby

To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/c23a6d78-1a59-4a77-9d0d-bcbcef1c27a9%40googlegroups.com.

Hendrik Boom

unread,
Sep 6, 2019, 8:28:05 AM9/6/19
to Racket Users
On Thu, Sep 05, 2019 at 10:42:01PM -0700, Alex Harsanyi wrote:
...
>
> >
> > A package containing a database of the positions of the major cities and
> > countries would be nice too :)
> >
>
>
> A general facility able to resolve location names to GPS coordinates would
> be a lot of work, and I don't have time for such a thing. Sorry.

There must be a GPS database of cities available somewhere already.

-- hendrik

Sage Gerard

unread,
Sep 6, 2019, 8:35:21 AM9/6/19
to hen...@topoi.pooq.com, racket...@googlegroups.com
Would geonames help?
http://www.geonames.org/


-------- Original Message --------

--


You received this message because you are subscribed to the Google Groups "Racket Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20190906122801.w5yhwfbzkods2fqr%40topoi.pooq.com.

Laurent

unread,
Sep 6, 2019, 8:37:59 AM9/6/19
to Sage Gerard, Hendrik Boom, racket-users@googlegroups.com List
There's a small free database here too:

I started writing a simple query system for it this morning (csv->rktd, then just list of assoc operations). 

Alex Harsanyi

unread,
Sep 6, 2019, 8:13:28 PM9/6/19
to Racket Users

That database is simple enough to use directly, not sure if it needs a separate package:

#lang racket
(require data-frame)

;; The worldcities.csv file has all values quoted, so df-read/csv reads them
;; all as strings.  Convert a series to numbers.
(define (->numeric df series)
 
(df-add-derived df series (list series) (lambda (v) (string->number (car v)))))
 
(define df (df-read/csv "worldcities.csv"))

 
;; Convert numeric series to numbers
(for ([series '("lat" "lng" "population")])
  (->numeric df series))

(define ((is-city? name) v)
  (equal? (vector-ref v 0) name))

(df-select* df "city" "country" "lat" "lng" #:filter (is-city? "Perth"))

;; The above call produces:

;; '
#(#("Perth" "Australia" -31.955 115.84)
;;    #("Perth" "United Kingdom" 56.4003 -3.47))



Alex.

On Friday, September 6, 2019 at 8:37:59 PM UTC+8, Laurent wrote:
There's a small free database here too:

I started writing a simple query system for it this morning (csv->rktd, then just list of assoc operations). 

On Fri, Sep 6, 2019 at 1:35 PM Sage Gerard <sa...@sagegerard.com> wrote:
Would geonames help?
http://www.geonames.org/


-------- Original Message --------
On Sep 6, 2019, 8:28 AM, Hendrik Boom < hen...@topoi.pooq.com> wrote:

On Thu, Sep 05, 2019 at 10:42:01PM -0700, Alex Harsanyi wrote:
...
>
> >
> > A package containing a database of the positions of the major cities and
> > countries would be nice too :)
> >
>
>
> A general facility able to resolve location names to GPS coordinates would
> be a lot of work, and I don't have time for such a thing. Sorry.

There must be a GPS database of cities available somewhere already.

-- hendrik

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.

Alex Harsanyi

unread,
Sep 6, 2019, 9:00:20 PM9/6/19
to Racket Users
In fact, I updated the data frame package to be able to read the CSV file directly, without having to process it, so the example now becomes:

#lang racket
(require data-frame)

(define df (df-read/csv "worldcities.csv" #:quoted-numbers? #t))


(define ((is-city? name) v)
 
(equal? (vector-ref v 0) name))

(df-select* df "city" "country" "lat" "lng" #:filter (is-city? "Perth"))

;; Produces:


;; '#(#("Perth" "Australia" -31.955 115.84)
;;      #("Perth" "United Kingdom" 56.4003 -3.47))

Alex.

Laurent

unread,
Sep 8, 2019, 3:34:35 AM9/8/19
to Alex Harsanyi, Racket Users
Nice :)


To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/d4353473-061d-4651-aedc-425351833968%40googlegroups.com.

Laurent

unread,
Sep 8, 2019, 3:46:54 AM9/8/19
to Alex Harsanyi, Racket Users
Reply all
Reply to author
Forward
0 new messages