diff --git a/docs/dev/api.md b/docs/dev/api.md index d3ccf8d..eae15c9 100644 --- a/docs/dev/api.md +++ b/docs/dev/api.md @@ -256,17 +256,135 @@ API errors are returned as JSON with a top-level `code` field and HTTP status `2 ### photo.getByBounds -Returns photos and clusters on the map by the passed zoom, GeoJSON object (Polygon or MultiPolygon) and optional year limit. The sequence of points in the array that forms the polygon must follow a counterclockwise path to sample objects within its boundaries (see [RFC7946 3.1.6](https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6)). The order of coordinates at points is `[lon, lat]`. From zoom 17 and up only photos are returned, for zoom level 16 and below both photos and clusters can be returned. +Returns public photo or painting data for a map area defined by a GeoJSON `Polygon` or `MultiPolygon`. The selection rule depends on `localWork`: + +`localWork` | Mode | Response | +--- | --- | --- | +`false` | server-side clustering | cluster cells selected by their grid position `g`; single-object cells are returned in `photos` and groups in `clusters` | +`true` | direct object lookup | objects whose coordinates are inside `geometry`, returned in `photos`; `clusters` is omitted | + +`localWork` is not selected automatically from `z` when `geometry` is used. Set it explicitly. The PastVu map uses server-side clustering through zoom level 16 and direct lookup from zoom level 17. + +GeoJSON positions use `[lon, lat]`. Close each polygon ring by repeating its first position at the end. The exterior ring must follow a counterclockwise path; see [RFC 7946, section 3.1.6](https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6). Parameter | Mandatory | Type | Default | Description | --- | --- | --- | --- | --- | -geometry | ✓ | GeoJSON (Polygon or MultiPolygon) | search area | -z | ✓ | int | | zoom level -isPainting | | bool | 0 | return only pictures in the response | -year | | int | | lower limit of the year of the photo | -year2 | | int | | upper limit of the year of the photo | -localWork | | bool | 0 | return array of `photos` (set 1 when using zoom value >= 17) | +geometry | ✓ | GeoJSON `Polygon` or `MultiPolygon` | | search area | +z | ✓ | int | | zoom level, starting with `1`; selects the server cluster grid in cluster mode and is echoed in the response | +isPainting | | bool | `false` | search paintings instead of photos | +year | | int | | lower bound for the object's `year` field; use together with `year2` | +year2 | | int | | upper bound for the object's `year` field; use together with `year` | +localWork | | bool | `false` | use direct object lookup instead of server-side clusters | +startAt | | int | | client request marker echoed unchanged in the response | + +The year filter matches the object's first year (`year`) only. It does not test whether the complete `year`–`year2` object date range overlaps the requested interval. For example, an object dated 1930–1940 is not returned for a 1936–1936 request. + +The filter is applied only when both values are numbers, `year` is not greater than `year2`, and both values are within the supported range: 1826–2000 for photos or -100–1980 for paintings. The selected interval must be shorter than the complete supported range. Otherwise, the year filter is ignored. + +#### Server-side clustering + +Use `localWork: false` to receive precomputed clusters for the requested `z`. The server selects a cluster when its grid position `g` is inside `geometry`; it does not test every object in that cluster against the polygon. Near the boundary, the response can therefore include objects outside the polygon or omit objects inside it. A selected cluster cell containing one object is returned in `photos`; a cell containing multiple objects is returned in `clusters`. **Query example:** -`https://api.pastvu.com/api2?method=photo.getByBounds¶ms={"z":11,"geometry":{"type":"Polygon","coordinates":[[[37.29034423828125,55.56902805913944],[37. 95501708984375,55.56902805913944],[37.95501708984375,55.92150795277898],[37.29034423828125,55.92150795277898],[37.29034423828125,55.56902805913944]]]}}` +`https://api.pastvu.com/api2?method=photo.getByBounds¶ms={"z":16,"geometry":{"type":"Polygon","coordinates":[[[-122.49,37.80],[-122.45,37.80],[-122.45,37.84],[-122.49,37.84],[-122.49,37.80]]]},"localWork":false}` + +**Response example (shortened):** + +```json +{ + "result": { + "z": 16, + "photos": [ + { + "cid": 1953913, + "file": "path/to/photo.jpg", + "title": "Golden Gate Bridge construction, view from Fort Baker", + "dir": "s", + "geo": [37.836174, -122.477004], + "year": 1936, + "year2": 1936 + } + ], + "clusters": [ + { + "geo": [37.832943, -122.479384], + "c": 2, + "p": { + "cid": 561915, + "file": "path/to/poster.jpg", + "title": "Bus near Golden Gate Bridge", + "dir": "s", + "geo": [-122.479678, 37.832869], + "year": 1978, + "year2": 1978 + } + } + ] + }, + "rid": "request-id" +} +``` + +#### Direct object lookup + +Use `localWork: true` to receive in `photos` every object whose coordinates are inside `geometry`. The server does not return `clusters`; the PastVu map clusters these objects in the browser. + +Direct lookup has no server-side result limit or pagination, and `z` does not reduce the number of matched objects. Keep `geometry` small enough for the client to receive and process the complete response. + +**Query example:** + +`https://api.pastvu.com/api2?method=photo.getByBounds¶ms={"z":17,"geometry":{"type":"Polygon","coordinates":[[[-122.49,37.80],[-122.45,37.80],[-122.45,37.84],[-122.49,37.84],[-122.49,37.80]]]},"year":1936,"year2":1936,"localWork":true,"startAt":1731931200000}` + +**Response example (shortened):** + +```json +{ + "result": { + "startAt": 1731931200000, + "z": 17, + "photos": [ + { + "cid": 1953913, + "file": "path/to/photo.jpg", + "title": "Golden Gate Bridge construction, view from Fort Baker", + "dir": "s", + "geo": [37.836174, -122.477004], + "year": 1936, + "year2": 1936 + } + ] + }, + "rid": "request-id" +} +``` + +**Key response fields:** + +Field | Type | Description | +--- | --- | --- | +`result.startAt` | int | request marker copied from the input; omitted when it was not passed | +`result.z` | int | requested zoom level | +`result.photos` | array | standalone objects in cluster mode or all matching objects in direct lookup mode | +`result.photos[].cid` | int | unique object number | +`result.photos[].file` | string | relative image path | +`result.photos[].dir` | string | shooting direction; omitted when it is not set | +`result.photos[].title` | string | object title | +`result.photos[].geo` | array [lat, lon] | object coordinates as latitude and longitude | +`result.photos[].year`, `result.photos[].year2` | int | first and last year of the object date range | +`result.clusters` | array | server-side clusters; omitted in direct lookup mode | +`result.clusters[].c` | int | number of objects in the cluster | +`result.clusters[].geo` | array [lat, lon] | cluster center coordinates | +`result.clusters[].p` | object | object used as the cluster poster | +`result.clusters[].p.geo` | array [lon, lat] | poster coordinates; unlike `photos[].geo` and cluster `geo`, longitude comes first | +`result.clusters[].g` | array [lon, lat] | cluster grid position; included when the year filter is applied | +`result.clusters[].y` | object | object counts grouped by year; included when the year filter is applied | +`rid` | string | request identifier used for diagnostics | + +**Errors:** + +Code | When returned | +--- | --- | +`BAD_PARAMS` | `geometry.type` is not `Polygon` or `MultiPolygon`, or `z` is not a number greater than or equal to `1` | + +API errors are returned as JSON with a top-level `code` field and HTTP status `200 OK`. Check `code` rather than relying on the HTTP status alone. diff --git a/i18n/ru/docusaurus-plugin-content-docs/current/dev/api.md b/i18n/ru/docusaurus-plugin-content-docs/current/dev/api.md index d4d2b99..1be98c9 100644 --- a/i18n/ru/docusaurus-plugin-content-docs/current/dev/api.md +++ b/i18n/ru/docusaurus-plugin-content-docs/current/dev/api.md @@ -256,17 +256,135 @@ skip | | int | 0 | количество пропускаемых результ ### photo.getByBounds -Возвращает фотографии и кластеры на карте по переданному зуму, GeoJSON объекту (Polygon или MultiPolygon) и опциональному ограничению по годам. Последовательность точек в массиве, формирующий полигон, должна следовать против часовой стрелки для выборки объектов внутри его границ (см. [RFC7946 3.1.6](https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6)). Порядок представления координат в точках - `[lon, lat]`. С 17 зума и более возвращаются только фотографии, до 16 включительно могут возвращаться как фото, так и кластеры. +Возвращает данные опубликованных фотографий или картин для области карты, заданной GeoJSON `Polygon` или `MultiPolygon`. Правило выборки зависит от `localWork`: + +`localWork` | Режим | Ответ | +--- | --- | --- | +`false` | кластеризация на сервере | ячейки кластеров, отобранные по положению `g`; ячейки с одним объектом возвращаются в `photos`, группы — в `clusters` | +`true` | непосредственный поиск объектов | объекты с координатами внутри `geometry` в массиве `photos`; поле `clusters` отсутствует | + +При использовании `geometry` режим `localWork` не выбирается автоматически по значению `z`. Указывайте его явно. Карта PastVu использует серверную кластеризацию до масштаба 16 включительно, а с масштаба 17 — непосредственный поиск. + +Координаты GeoJSON передаются в порядке `[lon, lat]`. Замкните каждый контур полигона, повторив первую точку в конце. Внешний контур должен идти против часовой стрелки; см. [раздел 3.1.6 RFC 7946](https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6). Параметр | Обязательный | Тип | По умолчанию | Описание | --- | --- | --- | --- | --- | geometry | ✓ | GeoJSON (Polygon или MultiPolygon) | | область поиска | -z | ✓ | int | | значение зума | -isPainting | | bool | 0 | вернуть в ответе только картины | -year | | int | | нижняя граница года снимка | -year2 | | int | | верхняя граница года снимка | -localWork | | bool | 0 | возвращать массив `photos` (следует установить 1 при значении зума >= 17) | +z | ✓ | int | | масштаб от `1`; выбирает сетку серверных кластеров в режиме кластеризации и возвращается в ответе | +isPainting | | bool | `false` | искать картины вместо фотографий | +year | | int | | нижняя граница поля `year` объекта; используется вместе с `year2` | +year2 | | int | | верхняя граница поля `year` объекта; используется вместе с `year` | +localWork | | bool | `false` | искать объекты непосредственно вместо использования серверных кластеров | +startAt | | int | | клиентская метка запроса, которая без изменений возвращается в ответе | + +Фильтр по годам проверяет только первый год датировки объекта (`year`). Он не проверяет пересечение полного диапазона `year`–`year2` объекта с запрошенным интервалом. Например, объект с датировкой 1930–1940 не попадёт в ответ на запрос за 1936–1936 годы. + +Фильтр применяется, только если обе границы являются числами, `year` не превышает `year2` и обе границы находятся в допустимом диапазоне: 1826–2000 для фотографий или -100–1980 для картин. Выбранный интервал должен быть короче полного допустимого диапазона. В остальных случаях фильтр по годам игнорируется. + +#### Кластеризация на сервере + +Установите `localWork: false`, чтобы получить рассчитанные заранее кластеры для масштаба `z`. Сервер выбирает кластер, если его положение в сетке `g` находится внутри `geometry`, и не проверяет координаты каждого объекта в кластере. Поэтому возле границы полигона в ответ могут попасть объекты за его пределами, а объекты внутри полигона могут быть пропущены. Выбранная ячейка кластера с одним объектом возвращается в `photos`, с несколькими объектами — в `clusters`. **Пример запроса:** -`https://api.pastvu.com/api2?method=photo.getByBounds¶ms={"z":11,"geometry":{"type":"Polygon","coordinates":[[[37.29034423828125,55.56902805913944],[37.95501708984375,55.56902805913944],[37.95501708984375,55.92150795277898],[37.29034423828125,55.92150795277898],[37.29034423828125,55.56902805913944]]]}}` +`https://api.pastvu.com/api2?method=photo.getByBounds¶ms={"z":16,"geometry":{"type":"Polygon","coordinates":[[[-122.49,37.80],[-122.45,37.80],[-122.45,37.84],[-122.49,37.84],[-122.49,37.80]]]},"localWork":false}` + +**Сокращённый пример ответа:** + +```json +{ + "result": { + "z": 16, + "photos": [ + { + "cid": 1953913, + "file": "path/to/photo.jpg", + "title": "Golden Gate Bridge construction, view from Fort Baker", + "dir": "s", + "geo": [37.836174, -122.477004], + "year": 1936, + "year2": 1936 + } + ], + "clusters": [ + { + "geo": [37.832943, -122.479384], + "c": 2, + "p": { + "cid": 561915, + "file": "path/to/poster.jpg", + "title": "Bus near Golden Gate Bridge", + "dir": "s", + "geo": [-122.479678, 37.832869], + "year": 1978, + "year2": 1978 + } + } + ] + }, + "rid": "request-id" +} +``` + +#### Непосредственный поиск объектов + +Установите `localWork: true`, чтобы получить в `photos` каждый объект с координатами внутри `geometry`. Сервер не возвращает `clusters`: карта PastVu группирует объекты в браузере. + +При непосредственном поиске сервер не ограничивает количество результатов и не поддерживает пагинацию, а значение `z` не уменьшает выборку. Задавайте `geometry` достаточно небольшой, чтобы клиент мог получить и обработать полный ответ. + +**Пример запроса:** + +`https://api.pastvu.com/api2?method=photo.getByBounds¶ms={"z":17,"geometry":{"type":"Polygon","coordinates":[[[-122.49,37.80],[-122.45,37.80],[-122.45,37.84],[-122.49,37.84],[-122.49,37.80]]]},"year":1936,"year2":1936,"localWork":true,"startAt":1731931200000}` + +**Сокращённый пример ответа:** + +```json +{ + "result": { + "startAt": 1731931200000, + "z": 17, + "photos": [ + { + "cid": 1953913, + "file": "path/to/photo.jpg", + "title": "Golden Gate Bridge construction, view from Fort Baker", + "dir": "s", + "geo": [37.836174, -122.477004], + "year": 1936, + "year2": 1936 + } + ] + }, + "rid": "request-id" +} +``` + +**Основные поля ответа:** + +Поле | Тип | Описание | +--- | --- | --- | +`result.startAt` | int | метка из запроса; отсутствует, если не была передана | +`result.z` | int | запрошенный масштаб | +`result.photos` | array | одиночные объекты в режиме кластеров или все найденные объекты при непосредственном поиске | +`result.photos[].cid` | int | уникальный номер объекта | +`result.photos[].file` | string | относительный путь к изображению | +`result.photos[].dir` | string | направление съёмки; отсутствует, если не задано | +`result.photos[].title` | string | название объекта | +`result.photos[].geo` | array [lat, lon] | координаты объекта: широта и долгота | +`result.photos[].year`, `result.photos[].year2` | int | первый и последний год датировки объекта | +`result.clusters` | array | серверные кластеры; отсутствует при непосредственном поиске | +`result.clusters[].c` | int | количество объектов в кластере | +`result.clusters[].geo` | array [lat, lon] | координаты центра кластера | +`result.clusters[].p` | object | объект, который используется как обложка кластера | +`result.clusters[].p.geo` | array [lon, lat] | координаты обложки; в отличие от `photos[].geo` и `geo` кластера, долгота идёт первой | +`result.clusters[].g` | array [lon, lat] | положение кластера в сетке; возвращается при фильтрации по годам | +`result.clusters[].y` | object | количество объектов с группировкой по годам; возвращается при фильтрации по годам | +`rid` | string | идентификатор запроса для диагностики | + +**Ошибки:** + +Код | Когда возвращается | +--- | --- | +`BAD_PARAMS` | значение `geometry.type` отличается от `Polygon` и `MultiPolygon` или `z` не является числом от `1` | + +Ошибки API возвращаются в JSON с полем `code` на верхнем уровне и HTTP-статусом `200 OK`. Проверяйте `code` в ответе, а не только HTTP-статус.