Skip to content

Instantly share code, notes, and snippets.

View rayrayzayzay's full-sized avatar

Rachel Zack rayrayzayzay

View GitHub Profile
CREATE INDEX ON cities USING GIST (geom);
host your_database felt_user felt_ip_range md5
CREATE TABLE cities (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
geom GEOMETRY(Point, 4326)
);
CREATE USER felt_user WITH PASSWORD 'your_secure_password';
GRANT CONNECT ON DATABASE your_database TO felt_user;
GRANT USAGE ON SCHEMA public TO felt_user;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO felt_user;
-- Grant select permission on future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO felt_user;
CREATE EXTENSION postgis;
let mode: "idle" | "dragging" = "idle"
const dragHandler: InteractionHandler = {
onDragStart(gesture, app) {
if (intersection(gesture.elementsUnderCursor, app.selectedElements).size) {
mode = "dragging";
}
},
onPointerMove(gesture) {
// ignore pointer-moves when we haven't started dragging
if (isScreenshot) return;
if (!isEditor) return;
if (isOnMap(event)) return;
if (sidebarState.displayedItem !== "comments") return;
if (hasDragged.check(event)) return;
if (currentTool !== "NONE") return;
if (isPanning) return;
if (isZooming) return;
if (event.shiftKey) return;
<MapPosition>
<DragBox>
<SVGPolygon
path={pathFromCoordinates(
element.coords,
viewport
)} />
</DragBox>
<SelectionFrame
polygon={selectionFramePolygon(element.coords, viewport)} />
const cache = new WeakMap<ElementCoords, Path2D>()
function getCachedPath(element) {
const fromCache = cache.get(element.coords)
if (fromCache) return fromCache;
const path = calculatePath(element.coords);
cache.set(element.coords, path);
return path;
}
function getFullRouteGeometry(coords, viewport) {
const roundedZoom = Math.round(viewport.zoom)
const fromCache = cache.get(roundedZoom).get(coords)
if (fromCache) return clipToViewport(fromCache, viewport);
const simplified = simplify(coords, 1 / roundedZoom)
cache.get(roundedZoom).set(coords, simplified);
return clipToViewport(simplified, viewport);
}