Offender Map API · v1.0.0

MapLibre

A complete MapLibre GL map to copy and paste. Also fits Mapbox GL.

Livehttps://api.offendersearch.appSandboxhttps://sandbox.offendersearch.app

What this page builds

A complete map with MapLibre GL JS: one HTML page and one script. The same code fits Mapbox GL JS: load that library instead, replace maplibregl with mapboxgl, and set your access token and style.

  • Loads the view when the map first appears, and again each time it stops moving.
  • Waits a quarter of a second after the last move, cancels the request it no longer needs, and sends If-None-Match so an unchanged view is free.
  • Draws clusters with their counts. A click on a cluster fits the map to its bbox at its expansionZoom.
  • Draws pins from zoom 13, and name labels from zoom 15. It reads mode and label from the response, so it holds no zoom numbers of its own.
  • Opens a list from the groups route for a pin that stands for several people, and for an approximate-area pin.
  • Opens a record panel from the records route when a pin or a list row is clicked.
  • Shows the notice sentence on the map.
The sample runs in test mode: the request carries sandbox=true, so it works before the plan is on and is never billed. To show real data, remove the line marked TEST MODE in map.js.

Run it

  1. Save the two files below as index.html and map.js in one folder.
  2. Create a map browser key in the dashboard and add http://localhost:8000 to its allowed sites. Put the key in KEY at the top of map.js. See Access & keys.
  3. Serve the folder: python3 -m http.server 8000. Open http://localhost:8000.
  4. Zoom in on the clusters. Pins appear, then names. Click a pin with a number on it for the list, and a pin for the record.

index.html

index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Map — MapLibre</title>
<link rel="stylesheet"
  href="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css">
<style>
  html, body { margin: 0; height: 100%; }
  body { font: 14px/1.4 system-ui, sans-serif; }
  #map { position: absolute; inset: 0 320px 0 0; }
  #panel {
    position: absolute; top: 0; right: 0; bottom: 0; width: 320px;
    box-sizing: border-box; padding: 16px; overflow: auto;
    border-left: 1px solid #d0d5dd; background: #fff;
  }
  #notice {
    position: absolute; left: 12px; bottom: 32px; z-index: 1000;
    margin: 0; padding: 6px 10px; border-radius: 6px;
    background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  }
  .dot {
    display: grid; place-items: center; box-sizing: border-box;

map.js

map.js
// ── Settings ───────────────────────────────────────────────
// Calling from the browser: a map browser key (os_map_pk_…)
// whose allowed sites include this page.
// Calling through your own server: set API to '' and KEY to ''.
const API = 'https://api.offendersearch.app';
const KEY = 'os_map_pk_your_key';

// ── MapLibre ───────────────────────────────────────────────
const map = new maplibregl.Map({
  container: 'map',
  style: 'https://tiles.openfreemap.org/styles/liberty',
  center: [-82.9988, 39.9612],  // test mode has people here
  zoom: 10,
});
let placed = [];

function currentView() {
  const b = map.getBounds();
  return {
    west: b.getWest(), south: b.getSouth(),
    east: b.getEast(), north: b.getNorth(),
    zoom: map.getZoom(),
  };
}

How it works

The first part of map.js is the only part that knows about MapLibre. Everything from “Load” down is plain JavaScript and is the same in all three library examples.

FunctionWhat it does with MapLibre
currentView()Reads the box from map.getBounds() and the zoom from map.getZoom().
place()Adds a maplibregl.Marker with the element, and listens for its click.
clearMarkers()Removes every marker placed for the last view.
zoomTo()map.easeTo() to a centre and a zoom.
Startload and moveend both call viewChanged().
FunctionWhat it does
viewChanged()Called on every move end. Restarts a short timer so a drag or a zoom makes one request, not twenty.
loadView()Cancels the previous request, sends the box and the zoom, and remembers each answer with its ETag. A 304 redraws the remembered answer.
draw(view)Clears the map, then draws clusters, markers and areas, the count line and the notice.
drawCluster(c)A circle with count. On click it moves to the middle of bbox at expansionZoom, which loads the next view.
drawPin(m)A pin. With a groupId it is a many-people pin and opens the list. With a label it shows the name.
drawArea(a)A dashed circle for people known only to a ZIP, city or county. It opens the list.
openGroup()One page of the groups route. “Show more” loads the next page.
openRecord()The records route. Fills the panel with the name, address, offense, notice and photo.

Going live

  • Turn the Map API on. See Turn it on.
  • Remove the sandbox line marked TEST MODE.
  • Use a browser key whose allowed sites include your site, or point API at your own server and clear KEY. See Access & keys.
  • The base map style in the sample is a public one. Use your own style in production.
  • For thousands of points, draw from a GeoJSON source and layers instead of HTML markers. Request format=geojson and pass the answer to source.setData().
  • A click on a pin opens the record at once, which is one record open. If you would rather show a small popup first, use the label, housingStatus and hasPhoto already on a named pin, and call the records route from a “View record” button.

Product overview