Embedding a map widget in the DrRacket REPL

已查看 132 次
跳至第一个未读帖子

Alex Harsanyi

未读,
2019年9月4日 05:41:552019/9/4
收件人 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

未读,
2019年9月4日 07:20:492019/9/4
收件人 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

未读,
2019年9月4日 07:50:192019/9/4
收件人 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

未读,
2019年9月5日 10:14:152019/9/5
收件人 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

未读,
2019年9月5日 23:59:562019/9/5
收件人 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

未读,
2019年9月6日 01:42:012019/9/6
收件人 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

未读,
2019年9月6日 04:57:362019/9/6
收件人 Racket Users
That is awesome - 

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

Kind regards

Stephen

Robby Findler

未读,
2019年9月6日 07:54:212019/9/6
收件人 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

未读,
2019年9月6日 08:28:052019/9/6
收件人 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

未读,
2019年9月6日 08:35:212019/9/6
收件人 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

未读,
2019年9月6日 08:37:592019/9/6
收件人 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

未读,
2019年9月6日 20:13:282019/9/6
收件人 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

未读,
2019年9月6日 21:00:202019/9/6
收件人 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

未读,
2019年9月8日 03:34:352019/9/8
收件人 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

未读,
2019年9月8日 03:46:542019/9/8
收件人 Alex Harsanyi、Racket Users
回复全部
回复作者
转发
0 个新帖子