Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactmap",
"version": "1.2.12",
"version": "1.2.13",
"description": "React based frontend map.",
"main": "ReactMap.mjs",
"author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>",
Expand Down Expand Up @@ -60,6 +60,7 @@
"@material-ui/styles": "^4.11.4",
"@sentry/react": "^6.19.7",
"@sentry/tracing": "^6.19.7",
"@turf/boolean-overlap": "^6.5.0",
"@turf/boolean-point-in-polygon": "^6.5.0",
"@turf/center": "^6.3.0",
"@turf/destination": "^6.5.0",
Expand Down Expand Up @@ -114,4 +115,4 @@
"suncalc": "^1.8.0",
"zustand": "^4.0.0-rc.1"
}
}
}
2 changes: 1 addition & 1 deletion server/src/models/ScanCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = class ScanCell extends Model {
.from(isMad ? 'trs_s2cells' : 's2cell')
return results.map((cell) => ({
...cell,
polygon: getPolyVector(cell.id, 'polygon'),
polygon: getPolyVector(cell.id, 'polygon').poly,
}))
}
}
49 changes: 44 additions & 5 deletions server/src/models/Weather.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { Model, ref, raw } = require('objection')
const { polygon, point } = require('@turf/helpers')
const { default: pointInPolygon } = require('@turf/boolean-point-in-polygon')
const { default: booleanOverlap } = require('@turf/boolean-overlap')

const getPolyVector = require('../services/functions/getPolyVector')
const config = require('../services/config')
const areas = require('../services/areas')

const {
api: { weatherCellLimit },
} = require('../services/config')
Expand All @@ -9,7 +16,7 @@ module.exports = class Weather extends Model {
return 'weather'
}

static async getAll(_perms, _args, { isMad }) {
static async getAll(perms, args, { isMad }) {
const query = this.query().select([
'*',
ref(isMad ? 's2_cell_id' : 'id')
Expand All @@ -27,9 +34,41 @@ module.exports = class Weather extends Model {
query.where('updated', '>=', ms)
}
const results = await query
return results.map((cell) => ({
...cell,
polygon: getPolyVector(cell.id, true),
}))

const cleanUserAreas = args.filters.onlyAreas.filter((area) =>
areas.names.includes(area),
)
const merged = perms.areaRestrictions.length
? perms.areaRestrictions.filter(
(area) => !cleanUserAreas.length || cleanUserAreas.includes(area),
)
: cleanUserAreas

return results
.map((cell) => {
const { poly, revPoly } = getPolyVector(cell.id, true)
const geojson = polygon([revPoly])
const hasOverlap =
!merged.length ||
merged.some(
(area) =>
pointInPolygon(
point(config.scanAreasObj[area].geometry.coordinates[0][0]),
geojson,
) ||
pointInPolygon(
point([cell.longitude, cell.latitude]),
config.scanAreasObj[area],
) ||
booleanOverlap(geojson, config.scanAreasObj[area]),
)
return (
hasOverlap && {
...cell,
polygon: poly,
}
)
})
.filter(Boolean)
}
}
5 changes: 5 additions & 0 deletions server/src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ config.scanAreasMenu = Object.fromEntries(
return [domain, Object.values(parents)]
}),
)
config.scanAreasObj = Object.fromEntries(
Object.values(config.scanAreas)
.flatMap((areas) => areas.features)
.map((feature) => [feature.properties.name, feature]),
)

config.api.pvp.leagueObj = Object.fromEntries(
config.api.pvp.leagues.map((league) => [league.name, league.cp]),
Expand Down
4 changes: 2 additions & 2 deletions server/src/services/functions/getPlacementCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ module.exports = function getPlacementCells(bounds, pokestops, gyms) {
const coveringCells = regionCoverer.getCoveringCells(region)
for (let i = 0; i < coveringCells.length; i += 1) {
const cell = coveringCells[i]
const polygon = getPolyVector(cell.id)
const { poly } = getPolyVector(cell.id)
const cellId = BigInt(cell.id).toString()
indexedCells[cellId] = {
id: cellId,
level: 17,
blocked: false,
polygon,
polygon: poly,
}
}
for (let i = 0; i < allCoords.length; i += 1) {
Expand Down
11 changes: 7 additions & 4 deletions server/src/services/functions/getPolyVector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ const { S2LatLng, S2Cell, S2CellId, S2Point } = require('nodes2ts')

module.exports = function getPolyVector(s2cellId, polyline) {
const s2cell = new S2Cell(new S2CellId(BigInt(s2cellId).toString()))
const polygon = []
const poly = []
const revPoly = []
for (let i = 0; i <= 3; i += 1) {
const coordinate = s2cell.getVertex(i)
const point = new S2Point(coordinate.x, coordinate.y, coordinate.z)
const latLng = S2LatLng.fromPoint(point)
polygon.push([latLng.latDegrees, latLng.lngDegrees])
poly.push([latLng.latDegrees, latLng.lngDegrees])
revPoly.push([latLng.lngDegrees, latLng.latDegrees])
}
if (polyline) {
polygon.push(polygon[0])
poly.push(poly[0])
revPoly.push(revPoly[0])
}

return polygon
return { poly, revPoly }
}
4 changes: 2 additions & 2 deletions server/src/services/functions/getTypeCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ module.exports = function getTypeCells(bounds, pokestops, gyms) {
const coveringCells = regionCoverer.getCoveringCells(region)
for (let i = 0; i < coveringCells.length; i += 1) {
const cell = coveringCells[i]
const polygon = getPolyVector(cell.id)
const { poly } = getPolyVector(cell.id)
const cellId = BigInt(cell.id).toString()
indexedCells[cellId] = {
id: cellId,
level: 14,
count: 0,
count_pokestops: 0,
count_gyms: 0,
polygon,
polygon: poly,
}
}
for (let i = 0; i < gyms.length; i += 1) {
Expand Down
2 changes: 2 additions & 0 deletions src/services/queries/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export const getAllPortals = gql`
$minLon: Float!
$maxLat: Float!
$maxLon: Float!
$filters: JSON
) {
portals(
minLat: $minLat
minLon: $minLon
maxLat: $maxLat
maxLon: $maxLon
filters: $filters
) {
id
lat
Expand Down
2 changes: 2 additions & 0 deletions src/services/queries/scanCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const getAllScanCells = gql`
$maxLat: Float!
$maxLon: Float!
$zoom: Int!
$filters: JSON
) {
scanCells(
minLat: $minLat
minLon: $minLon
maxLat: $maxLat
maxLon: $maxLon
zoom: $zoom
filters: $filters
) {
id
center_lat
Expand Down
Loading