mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-21 23:53:08 +01:00
🐁 showing lat/lon under cursor, center on click
This commit is contained in:
parent
cf757772f2
commit
d2c0c993cb
@ -14,8 +14,8 @@
|
||||
"bin": {
|
||||
"mapscii": "./bin/mapscii.sh"
|
||||
},
|
||||
"engines" : {
|
||||
"node" : ">=4.5.0"
|
||||
"engines": {
|
||||
"node": ">=4.5.0"
|
||||
},
|
||||
"keywords": [
|
||||
"map",
|
||||
|
@ -98,24 +98,41 @@ module.exports = class Mapscii
|
||||
|
||||
@renderer.setSize @width, @height
|
||||
|
||||
_updateMousePosition: (event) ->
|
||||
projected =
|
||||
x: (event.x-.5)*2
|
||||
y: (event.y-.5)*4
|
||||
|
||||
size = utils.tilesizeAtZoom @zoom
|
||||
[dx, dy] = [projected.x-@width/2, projected.y-@height/2]
|
||||
|
||||
z = Math.min config.tileRange, Math.max 0, Math.floor @zoom
|
||||
center = utils.ll2tile @center.lon, @center.lat, z
|
||||
|
||||
@mousePosition = utils.tile2ll center.x+(dx/size), center.y+(dy/size), z
|
||||
|
||||
_onClick: (event) ->
|
||||
@_updateMousePosition event
|
||||
|
||||
if @mouseDragging and event.button is "left"
|
||||
# TODO lat/lng based drag&drop
|
||||
# @view[0] -= (@mouseDragging.x-@mousePosition.x)<<1
|
||||
# @view[1] -= (@mouseDragging.y-@mousePosition.y)<<2
|
||||
@_draw()
|
||||
|
||||
@mouseDragging = false
|
||||
else
|
||||
@setCenter @mousePosition.lat, @mousePosition.lon
|
||||
|
||||
@_draw()
|
||||
|
||||
_onMouseScroll: (event) ->
|
||||
@_updateMousePosition event
|
||||
# TODO: handle .x/y for directed zoom
|
||||
@zoomBy config.zoomStep * if event.button is "up" then -1 else 1
|
||||
@_draw()
|
||||
|
||||
_onMouseMove: (event) ->
|
||||
projected =
|
||||
x: event.x * 2
|
||||
y: event.y * 4
|
||||
@_updateMousePosition event
|
||||
|
||||
# start dragging
|
||||
if event.button is "left"
|
||||
@ -124,14 +141,12 @@ module.exports = class Mapscii
|
||||
# @view[0] -= (@mouseDragging.x-event.x)<<1
|
||||
# @view[1] -= (@mouseDragging.y-event.y)<<2
|
||||
|
||||
if not @renderer.isDrawing and @renderer.lastDrawAt < Date.now()-100
|
||||
@_draw()
|
||||
@mouseDragging = x: event.x, y: event.y
|
||||
# if not @renderer.isDrawing and @renderer.lastDrawAt < Date.now()-100
|
||||
# @_draw()
|
||||
# @mouseDragging = x: event.x, y: event.y
|
||||
else
|
||||
@mouseDragging = x: event.x, y: event.y
|
||||
|
||||
# update internal mouse tracker
|
||||
@mousePosition = projected
|
||||
@notify @_getFooter()
|
||||
|
||||
_onKey: (key) ->
|
||||
@ -182,7 +197,7 @@ module.exports = class Mapscii
|
||||
|
||||
"center: #{utils.digits @center.lat, 3}, #{utils.digits @center.lon, 3} "+
|
||||
"zoom: #{utils.digits @zoom, 2} "+
|
||||
"mouse: #{@mousePosition.x-@width/2} #{@mousePosition.y-@height/2} "
|
||||
"mouse: #{utils.digits @mousePosition.lat, 3}, #{utils.digits @mousePosition.lon, 3} "
|
||||
|
||||
notify: (text) ->
|
||||
@_write "\r\x1B[K"+text unless config.headless
|
||||
|
Loading…
Reference in New Issue
Block a user