Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
34a6c9ac
Commit
34a6c9ac
authored
10 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
tile fixes so far
parent
04a86eaa
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/api/tiles.clj
+40
-37
40 additions, 37 deletions
src/metabase/api/tiles.clj
with
40 additions
and
37 deletions
src/metabase/api/tiles.clj
+
40
−
37
View file @
34a6c9ac
(
ns
metabase.api.tiles
(
:require
[
clojure.data.json
:as
json
]
(
:require
[
clojure.core.match
:refer
[
match
]]
[
clojure.data.json
:as
json
]
[
clojure.tools.logging
:as
log
]
[
compojure.core
:refer
[
GET
]]
[
metabase.api.common
:refer
:all
]
...
...
@@ -7,10 +8,10 @@
[
metabase.driver
:as
driver
]))
(
def
tile-size
256
)
(
def
pixel-origin
(
float
(
/
tile-size
2
)))
(
def
pixel-per-lon-degree
(
float
(
/
tile-size
360.0
)))
(
def
pixel-per-lon-radian
(
float
(
/
tile-size
(
*
2
java.lang.Math/PI
))))
(
def
^
:const
tile-size
256
)
(
def
^
:const
pixel-origin
(
float
(
/
tile-size
2
)))
(
def
^
:const
pixel-per-lon-degree
(
float
(
/
tile-size
360.0
)))
(
def
^
:const
pixel-per-lon-radian
(
float
(
/
tile-size
(
*
2
java.lang.Math/PI
))))
(
defn-
radians->degrees
[
rad
]
(
/
rad
(
float
(
/
java.lang.Math/PI
180
))))
...
...
@@ -18,13 +19,13 @@
(
defn-
tile-lat-lon
"Get the Latitude & Longitude of the upper left corner of a given tile"
[
x
y
zoom
]
(
let
[
num-tiles
(
bit-shift-left
1
zoom
)
corner-x
(
float
(
/
(
*
x
tile-size
)
num-tiles
))
corner-y
(
float
(
/
(
*
y
tile-size
)
num-tiles
))
lon
(
float
(
/
(
-
corner-x
pixel-origin
)
pixel-per-lon-degree
))
(
let
[
num-tiles
(
bit-shift-left
1
zoom
)
corner-x
(
float
(
/
(
*
x
tile-size
)
num-tiles
))
corner-y
(
float
(
/
(
*
y
tile-size
)
num-tiles
))
lon
(
float
(
/
(
-
corner-x
pixel-origin
)
pixel-per-lon-degree
))
lat-radians
(
/
(
-
corner-y
pixel-origin
)
(
*
pixel-per-lon-radian
-1
))
lat
(
radians->degrees
(
-
(
*
2
(
java.lang.Math/atan
(
java.lang.Math/exp
lat-radians
)))
(
/
java.lang.Math/PI
2
)))]
lat
(
radians->degrees
(
-
(
*
2
(
java.lang.Math/atan
(
java.lang.Math/exp
lat-radians
)))
(
/
java.lang.Math/PI
2
)))]
{
:lat
lat
:lon
lon
}))
...
...
@@ -36,44 +37,46 @@
{
bot-rt-lat
:lat
bot-rt-lon
:lon
}
(
tile-lat-lon
(
+
x
1
)
(
+
y
1
)
zoom
)
inside-filter
[
"INSIDE"
,
lat-field-id,
lon-field-id,
top-lt-lat,
top-lt-lon,
bot-rt-lat,
bot-rt-lon
]]
(
update-in
details
[
:filter
]
#
(
clojure.core.match/
match
%
nil
inside-filter
[
"AND"
&
_
]
(
conj
%
inside-filter
)
[
&
_
]
(
conj
[
"AND"
]
%
inside-filter
))))
)
#
(
match
%
[
"AND"
&
_
]
(
conj
%
inside-filter
)
[
(
_
:guard
string?
)
&
_
]
(
conj
[
"AND"
]
%
inside-filter
)
:else
inside-filter
))))
(
defn-
extract-points
"Takes in a dataset query result object and pulls out the Latitude/Longitude pairs into nested `java.util.ArrayLists`.
This is specific to the way we plan to feed data into `com.metabase.corvus.api.tiles.GoogleMapPinsOverlay`."
[{{
:keys
[
rows
cols
]}
:data
}]
(
if-not
(
>
(
count
rows
)
0
)
;; if we have no rows then return an empty list of points
(
java.util.ArrayList.
[])
;; otherwise we go over the data, pull out the lat/lon columns, and convert them to ArrayLists
(
let
[
find-col-idx
(
fn
[
special-type
]
(
->>
(
map-indexed
(
fn
[
idx
itm
]
(
when
(
=
special-type
(
:special_type
itm
))
idx
))
cols
)
(
filter
identity
)
(
first
)))
lat-col-idx
(
find-col-idx
"latitude"
)
lon-col-idx
(
find-col-idx
"longitude"
)]
(
->>
(
map
(
fn
[
row
]
(
java.util.ArrayList.
[(
nth
row
lat-col-idx
)
(
nth
row
lon-col-idx
)]))
rows
)
(
java.util.ArrayList.
)))))
(
try
(
if-not
(
>
(
count
rows
)
0
)
;; if we have no rows then return an empty list of points
(
java.util.ArrayList.
[])
;; otherwise we go over the data, pull out the lat/lon columns, and convert them to ArrayLists
(
let
[
find-col-idx
(
fn
[
special-type
]
(
->>
(
map-indexed
(
fn
[
idx
itm
]
(
when
(
=
special-type
(
:special_type
itm
))
idx
))
cols
)
(
filter
identity
)
first
))
lat-col-idx
(
find-col-idx
"latitude"
)
lon-col-idx
(
find-col-idx
"longitude"
)]
(
->>
(
map
(
fn
[
row
]
(
java.util.ArrayList.
[(
nth
row
lat-col-idx
)
(
nth
row
lon-col-idx
)]))
rows
)
(
java.util.ArrayList.
))))
(
catch
Throwable
e
(
log/debug
"CAUGHT EXCEPTION IN EXTRACT-POINTS (WHY?): "
e
))))
;; This endpoints provides an image with the appropriate pins rendered given a json query
;; We evaluate the query and find the set of lat/lon pairs which are relevant and then render the appropriate ones
;; It's expected that to render a full map view several calls will be made to this endpoint in parallel
(
defendpoint
GET
"/:zoom/:x/:y/:lat-field/:lon-field/:lat-col-idx/:lon-col-idx/"
"This endpoints provides an image with the appropriate pins rendered given a json query.
We evaluate the query and find the set of lat/lon pairs which are relevant and then render the appropriate ones.
It's expected that to render a full map view several calls will be made to this endpoint in parallel."
[
zoom
x
y
lat-field
lon-field
lat-col-idx
lon-col-idx
query
:as
request
]
{
zoom
String->Integer
x
String->Integer
y
String->Integer
lat-field
String->Integer
lon-field
String->Integer
{
zoom
String->Integer
x
String->Integer
y
String->Integer
lat-field
String->Integer
lon-field
String->Integer
lat-col-idx
String->Integer
lon-col-idx
String->Integer
query
String->Dict
}
;; TODO - tried to use `query String->Dict` above, but got errors with json parsing for some reason
query
String->Dict
}
(
let
[
updated-query
(
assoc
query
:query
(
query-with-inside-filter
(
:query
query
)
lat-field
lon-field
x
y
zoom
))
result
(
driver/dataset-query
updated-query
{
:executed_by
*current-user-id*
:synchronously
true
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment