@geolonia/maps-core 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -159,6 +159,9 @@ const map = new GeoloniaMap({
159
159
  geojson: 'https://example.com/data.geojson',
160
160
  cluster: true,
161
161
  clusterColor: '#ff0000',
162
+ choropleth: 'value', // Color polygons by a property (see below)
163
+ heatmap: 'weight', // Draw points as a heatmap (see below)
164
+ circle: { size: 'weight', color: 'category' }, // Size and color points (see below)
162
165
  simpleVector: 'my-tileset', // Vector tile URL or tileset ID
163
166
  '3d': false,
164
167
  errorMessage: undefined, // Message shown when the map fails to initialize
@@ -183,6 +186,57 @@ new GeoloniaMap({ container: '#map', errorMessage: 'Sorry, the map is unavailabl
183
186
  new GeoloniaMap({ container: '#map', errorMessage: false });
184
187
  ```
185
188
 
189
+ #### `choropleth`, `heatmap` and `circle`
190
+
191
+ Style the `geojson` data by the values of its properties, without writing MapLibre expressions.
192
+
193
+ ```typescript
194
+ // Color polygons by `value`. The range defaults to the min and max of the data.
195
+ new GeoloniaMap({ container: '#map', geojson, choropleth: 'value' });
196
+ new GeoloniaMap({
197
+ container: '#map',
198
+ geojson,
199
+ choropleth: { property: 'value', colors: ['#FFF2CC', '#B3261E'], range: [0, 100] },
200
+ });
201
+
202
+ // Draw points as a heatmap. `true` weights every point equally.
203
+ new GeoloniaMap({ container: '#map', geojson, heatmap: 'weight' });
204
+
205
+ // Size points by `weight` and color them by `category`.
206
+ // Numeric values get a color ramp, other values one color per category.
207
+ new GeoloniaMap({ container: '#map', geojson, circle: { size: 'weight', color: 'category' } });
208
+ ```
209
+
210
+ - These options take precedence over simplestyle properties such as `fill` and `marker-color`. Features without a numeric value fall back to the simplestyle look.
211
+ - `heatmap` and `circle` turn clustering off. `heatmap` also hides the point markers. `circle` draws every point as a circle, including points with `marker-symbol`, and hides the icons and titles.
212
+ - The range and categories are computed again when the GeoJSON is loaded from a URL or replaced with `updateData()`.
213
+ - `colors` is optional. The defaults are Geolonia's orange ramp and a categorical palette.
214
+ - With `choropleth`, polygons without a `fill-opacity` property are drawn at 0.7 opacity instead of 1, so that the base map shows through.
215
+ - With `circle.color`, a property is treated as numeric only when every value is a number. Numeric strings such as `"12"` count as categories. Objects and arrays are not colored.
216
+
217
+ #### `transformRequest`
218
+
219
+ Works like MapLibre's `transformRequest`, and is also called for the requests that maps-core rewrites itself: Geolonia sources (`api.geolonia.com` and the Geolonia tile hosts) and Geolonia sprites. For those, the function receives the URL after maps-core has added `key` and `sessionId`, so the parameters are kept as long as you build on the URL you are given.
220
+
221
+ - Return a `RequestParameters` object to use it as is.
222
+ - Return `undefined` to keep the request maps-core built.
223
+ - A `Promise` may be returned. If it resolves to `undefined`, the request maps-core built is used.
224
+
225
+ ```typescript
226
+ new GeoloniaMap({
227
+ container: '#map',
228
+ transformRequest: (url, resourceType) => {
229
+ // Load another tileset from the Geolonia tile server
230
+ if (resourceType === 'Source' && url.includes('tileserver.geolonia.com/oneself/')) {
231
+ return { url: url.replace('/oneself/', '/my-tileset/') };
232
+ }
233
+ return undefined;
234
+ },
235
+ });
236
+ ```
237
+
238
+ Replacing the function later with `map.setTransformRequest()` also removes the maps-core rewriting, including `key` and `sessionId`.
239
+
186
240
  ### `GeoloniaMarker`
187
241
 
188
242
  Extends `maplibregl.Marker` with Geolonia's default marker style.
@@ -203,6 +257,7 @@ GeoJSON visualization based on [simplestyle-spec](https://github.com/mapbox/simp
203
257
  import { SimpleStyle } from '@geolonia/maps-core';
204
258
 
205
259
  const ss = new SimpleStyle(geojson, { cluster: true });
260
+ // Also accepts `choropleth`, `heatmap` and `circle` (see GeoloniaMap options)
206
261
  ss.addTo(map).fitBounds();
207
262
  ```
208
263
 
@@ -230,6 +285,7 @@ keyring.setStage('v1');
230
285
  npm install
231
286
  npm run build # ESM + DTS
232
287
  npm run test # Vitest unit tests
288
+ npm run build:umd # UMD bundle (dist/umd/), required by e2e/umd.spec.ts
233
289
  npm run e2e # Playwright E2E tests
234
290
  npm run lint # Biome
235
291
  npm run dev # Vite dev server (example/)
@@ -1,5 +1,5 @@
1
1
  import * as maplibregl from 'maplibre-gl';
2
- import { IControl, ControlPosition, Map, MapOptions, ExpiryData, StyleSpecification, StyleSwapOptions, StyleOptions, GetResourceResponse, MarkerOptions } from 'maplibre-gl';
2
+ import { IControl, ControlPosition, Map, MapOptions, RequestTransformFunction, ExpiryData, StyleSpecification, StyleSwapOptions, StyleOptions, GetResourceResponse, MarkerOptions } from 'maplibre-gl';
3
3
 
4
4
  /**
5
5
  * Shadow DOM を用いたカスタム帰属表示コントロールの実装です。
@@ -162,7 +162,8 @@ type GeoloniaMapOptions = MapOptions & {
162
162
  apiKey?: string;
163
163
  /**
164
164
  * API のステージ(`'dev'` / `'v1'` など)。API エンドポイントの選択に使う。
165
- * @defaultValue `'dev'`
165
+ * 省略時は共有キーリングの現在のステージを使う。別の地図が `stage` を指定してキーリングを変更済みの場合は、その値になる。
166
+ * @defaultValue `'v1'`(キーリングの初期値)
166
167
  */
167
168
  stage?: string;
168
169
  /**
@@ -171,6 +172,18 @@ type GeoloniaMapOptions = MapOptions & {
171
172
  * @defaultValue `'geolonia/basic-v2'`
172
173
  */
173
174
  style?: string;
175
+ /**
176
+ * リクエストを送る直前に URL やヘッダーを書き換える関数。MapLibre の `transformRequest` と同じ形。
177
+ *
178
+ * Geolonia のソース(`api.geolonia.com` と Geolonia のタイルホスト)とスプライトのリクエストでは、
179
+ * maps-core が `key` や `sessionId` を付けた後の URL が渡される。
180
+ * `undefined` を返すと maps-core の変換結果がそのまま使われる。
181
+ * Promise を返してもよい。解決値が `undefined` のときも maps-core の変換結果が使われる。
182
+ *
183
+ * `map.setTransformRequest()` で差し替えると maps-core の変換も外れる。後から変えるときは、
184
+ * maps-core が付ける `key` や `sessionId` を自分で付ける必要がある。
185
+ */
186
+ transformRequest?: RequestTransformFunction | null;
174
187
  /**
175
188
  * ラベルの言語。`'ja'` / `'en'` / `'auto'`(ブラウザ言語に従う)。
176
189
  * `'auto'` または未指定のときは `getLang()` の結果(`'ja'` または `'en'`)になる。
@@ -204,6 +217,7 @@ type GeoloniaMapOptions = MapOptions & {
204
217
  /**
205
218
  * ズームと回転のコントロール。`true` / `false`、または表示位置
206
219
  * (`'top-right'`、`'bottom-left'` など)を指定する。
220
+ * コンパスは地図の傾きも表し、クリックすると向きと傾きの両方を戻す。
207
221
  * @defaultValue `true`
208
222
  */
209
223
  navigationControl?: boolean | ControlPosition;
@@ -242,6 +256,25 @@ type GeoloniaMapOptions = MapOptions & {
242
256
  * @defaultValue `'#ff0000'`
243
257
  */
244
258
  clusterColor?: string;
259
+ /**
260
+ * `geojson` のポリゴンを、プロパティの値で塗り分ける(コロプレス)。
261
+ * プロパティ名の文字列、または {@link ChoroplethOptions} を指定する。
262
+ * 地物の simplestyle の `fill` より優先する。地物に `fill-opacity` がないときの不透明度は、
263
+ * 背景の地図が透けるよう 1 ではなく 0.7 にする。
264
+ */
265
+ choropleth?: string | ChoroplethOptions;
266
+ /**
267
+ * `geojson` のポイントをヒートマップで描く。`true` で重みなし、
268
+ * プロパティ名の文字列でその値を重みにする。{@link HeatmapOptions} も指定できる。
269
+ * 指定するとクラスタリングとポイントのマーカーは表示しない。
270
+ */
271
+ heatmap?: boolean | string | HeatmapOptions;
272
+ /**
273
+ * `geojson` のポイントの円の大きさと色を、プロパティの値で変える。
274
+ * 指定するとクラスタリングは行わず、`marker-symbol` を持つポイントも円で描く(アイコンとタイトルは表示しない)。
275
+ * 地物の simplestyle の `marker-color` より優先する。
276
+ */
277
+ circle?: CircleOptions;
245
278
  /** SimpleStyle Vector で表示するベクトルタイルの URL または論理名。 */
246
279
  simpleVector?: string;
247
280
  /**
@@ -257,6 +290,47 @@ type GeoloniaMapOptions = MapOptions & {
257
290
  */
258
291
  errorMessage?: string | false;
259
292
  };
293
+ /**
294
+ * {@link GeoloniaMapOptions.choropleth} の詳細な指定。
295
+ */
296
+ type ChoroplethOptions = {
297
+ /** 塗り分けに使うプロパティ名。値が数値の地物だけを塗り分ける。 */
298
+ property: string;
299
+ /**
300
+ * 値の小さい側から大きい側へ並べた色。値の範囲に等間隔で割り当て、間は補間する。
301
+ * @defaultValue `['#FFF2CC', '#FFAB40', '#EA5C0D', '#B3261E']`
302
+ */
303
+ colors?: string[];
304
+ /** 色を割り当てる値の範囲 `[最小, 最大]`。省略するとデータの最小値と最大値を使う。 */
305
+ range?: [number, number];
306
+ };
307
+ /**
308
+ * {@link GeoloniaMapOptions.heatmap} の詳細な指定。
309
+ */
310
+ type HeatmapOptions = {
311
+ /** 重みに使うプロパティ名。データの最小値を 0、最大値を 1 として扱う。省略するとすべて同じ重み。 */
312
+ weight?: string;
313
+ /**
314
+ * 密度の低い側から高い側へ並べた色。密度 0 は透明になる。
315
+ * @defaultValue `['#FABF3D', '#FFAB40', '#EA5C0D', '#B3261E']`
316
+ */
317
+ colors?: string[];
318
+ };
319
+ /**
320
+ * {@link GeoloniaMapOptions.circle} の指定。
321
+ */
322
+ type CircleOptions = {
323
+ /** 円の大きさに使うプロパティ名。データの範囲を半径 3 から 11 ピクセルに対応させる。 */
324
+ size?: string;
325
+ /**
326
+ * 円の色に使うプロパティ名。値がすべて数値なら連続した色に、
327
+ * そうでなければ値ごとに別の色にする。`"12"` のような数字の文字列もカテゴリとして扱う。
328
+ * オブジェクトや配列の値は色分けしない。
329
+ */
330
+ color?: string;
331
+ /** `color` に使う色。数値なら小さい側から大きい側へ、カテゴリなら出現順に割り当てる。 */
332
+ colors?: string[];
333
+ };
260
334
 
261
335
  type GetImageCallback = (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null) => void;
262
336
  /**
@@ -647,6 +721,7 @@ declare class SimpleStyle {
647
721
  private geojson;
648
722
  private map;
649
723
  private options;
724
+ private heatmap;
650
725
  private _eventHandlers;
651
726
  /**
652
727
  * SimpleStyle を作成します。
@@ -728,9 +803,26 @@ declare class SimpleStyle {
728
803
  * `marker-size`(`small`、`large`、その他)に応じて円の半径やラベルのオフセットを変え、
729
804
  * `marker-color`、`stroke`、`title`、`text-color` などの simplestyle プロパティを反映します。
730
805
  * あわせて円レイヤーとシンボルレイヤーの双方に {@link SimpleStyle.setPopup | setPopup} でポップアップを設定します。
806
+ * `circle` オプションを指定したときは、`marker-symbol` の有無にかかわらずすべてのポイントを円で描き、
807
+ * シンボルレイヤーは追加しません。
731
808
  * 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
732
809
  */
733
810
  setPointGeometries(): void;
811
+ /**
812
+ * ポイントのヒートマップレイヤーを設定します。
813
+ *
814
+ * `heatmap` オプションを指定したときに、ポイントのマーカーとクラスターの代わりに使います。
815
+ * 重みは {@link SimpleStyle.applyDataDrivenPaint | applyDataDrivenPaint} がデータに合わせて設定します。
816
+ * 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
817
+ */
818
+ setHeatmap(): void;
819
+ /**
820
+ * `choropleth`、`heatmap`、`circle` オプションの式を、現在のデータに合わせて設定します。
821
+ *
822
+ * 値の範囲やカテゴリはデータから求めるため、{@link SimpleStyle.addTo | addTo} と
823
+ * {@link SimpleStyle.updateData | updateData} のたびに呼び出します。
824
+ */
825
+ applyDataDrivenPaint(): void;
734
826
  /**
735
827
  * 指定したレイヤーにクリックでポップアップを表示するイベントハンドラーを設定します。
736
828
  *
@@ -877,4 +969,5 @@ declare class SimpleStyleVector {
877
969
 
878
970
  declare const VERSION: string;
879
971
 
880
- export { CustomAttributionControl, DEFAULT_STAGE, GeoloniaControl, GeoloniaMap, type GeoloniaMapOptions, GeoloniaMarker, SimpleStyle, SimpleStyleVector, VERSION as coreVersion, getLang, getStyle, isGeoloniaTilesHost, keyring };
972
+ export { CustomAttributionControl, DEFAULT_STAGE, GeoloniaControl, GeoloniaMap, GeoloniaMarker, SimpleStyle, SimpleStyleVector, VERSION as coreVersion, getLang, getStyle, isGeoloniaTilesHost, keyring };
973
+ export type { ChoroplethOptions, CircleOptions, GeoloniaMapOptions, HeatmapOptions };
package/dist/npm/index.js CHANGED
@@ -538,6 +538,134 @@ import bbox from "@turf/bbox";
538
538
  import turfCenter from "@turf/center";
539
539
  import * as maplibregl3 from "maplibre-gl";
540
540
 
541
+ // src/lib/data-driven.ts
542
+ var SEQUENTIAL_COLORS = ["#FFF2CC", "#FFAB40", "#EA5C0D", "#B3261E"];
543
+ var HEATMAP_COLORS = ["#FABF3D", "#FFAB40", "#EA5C0D", "#B3261E"];
544
+ var CATEGORICAL_COLORS = [
545
+ "#EA5C0D",
546
+ "#2B6CB0",
547
+ "#FABF3D",
548
+ "#5B8C2A",
549
+ "#9A5B1E",
550
+ "#7A4FA0",
551
+ "#E8402F",
552
+ "#6B7280"
553
+ ];
554
+ var CIRCLE_RADIUS_RANGE = [3, 11];
555
+ function colorsOr(colors, defaults) {
556
+ return colors?.length ? colors : defaults;
557
+ }
558
+ function normalizeChoropleth(option) {
559
+ if (!option) return void 0;
560
+ return typeof option === "string" ? { property: option } : option;
561
+ }
562
+ function normalizeHeatmap(option) {
563
+ if (!option) return void 0;
564
+ if (option === true) return {};
565
+ return typeof option === "string" ? { weight: option } : option;
566
+ }
567
+ function numericRange(features, property) {
568
+ let min = Number.POSITIVE_INFINITY;
569
+ let max = Number.NEGATIVE_INFINITY;
570
+ for (const f of features) {
571
+ const v = f.properties?.[property];
572
+ if (typeof v !== "number" || !Number.isFinite(v)) continue;
573
+ if (v < min) min = v;
574
+ if (v > max) max = v;
575
+ }
576
+ return min <= max ? [min, max] : void 0;
577
+ }
578
+ function interpolate(property, range, outputs) {
579
+ const [min, max] = range;
580
+ if (!(min < max) || outputs.length < 2) return outputs[outputs.length - 1];
581
+ const stops = outputs.flatMap((out, i) => [
582
+ min + (max - min) * i / (outputs.length - 1),
583
+ out
584
+ ]);
585
+ return [
586
+ "interpolate",
587
+ ["linear"],
588
+ ["get", property],
589
+ ...stops
590
+ ];
591
+ }
592
+ function whenNumber(property, expr, fallback) {
593
+ return [
594
+ "case",
595
+ ["==", ["typeof", ["get", property]], "number"],
596
+ expr,
597
+ fallback
598
+ ];
599
+ }
600
+ function sequentialColor(property, features, colors, fallback, range) {
601
+ const r = range ?? numericRange(features, property);
602
+ if (!r) return fallback;
603
+ return whenNumber(property, interpolate(property, r, colors), fallback);
604
+ }
605
+ function choroplethColor(option, features, fallback) {
606
+ return sequentialColor(
607
+ option.property,
608
+ features,
609
+ colorsOr(option.colors, SEQUENTIAL_COLORS),
610
+ fallback,
611
+ option.range
612
+ );
613
+ }
614
+ function heatmapWeight(option, features) {
615
+ if (!option.weight) return 1;
616
+ const range = numericRange(features, option.weight);
617
+ if (!range || !(range[0] < range[1])) return 1;
618
+ return whenNumber(
619
+ option.weight,
620
+ interpolate(option.weight, range, [0, 1]),
621
+ 0
622
+ );
623
+ }
624
+ function heatmapColor(option) {
625
+ const colors = colorsOr(option.colors, HEATMAP_COLORS);
626
+ const stops = colors.flatMap((c, i) => [(i + 1) / colors.length, c]);
627
+ return [
628
+ "interpolate",
629
+ ["linear"],
630
+ ["heatmap-density"],
631
+ 0,
632
+ "rgba(0, 0, 0, 0)",
633
+ ...stops
634
+ ];
635
+ }
636
+ function circleRadius(option, features, fallback) {
637
+ if (!option.size) return fallback;
638
+ const range = numericRange(features, option.size);
639
+ if (!range) return fallback;
640
+ return whenNumber(
641
+ option.size,
642
+ interpolate(option.size, range, CIRCLE_RADIUS_RANGE),
643
+ fallback
644
+ );
645
+ }
646
+ function circleColor(option, features, fallback) {
647
+ const property = option.color;
648
+ if (!property) return fallback;
649
+ const values = features.map((f) => f.properties?.[property]).filter((v) => ["string", "number", "boolean"].includes(typeof v));
650
+ if (values.length === 0) return fallback;
651
+ if (values.every((v) => typeof v === "number")) {
652
+ return sequentialColor(
653
+ property,
654
+ features,
655
+ colorsOr(option.colors, SEQUENTIAL_COLORS),
656
+ fallback
657
+ );
658
+ }
659
+ const colors = colorsOr(option.colors, CATEGORICAL_COLORS);
660
+ const categories = [...new Set(values.map(String))];
661
+ return [
662
+ "match",
663
+ ["to-string", ["get", property]],
664
+ ...categories.flatMap((c, i) => [c, colors[i % colors.length]]),
665
+ fallback
666
+ ];
667
+ }
668
+
541
669
  // src/lib/keyring.ts
542
670
  var DEFAULT_STAGE = "v1";
543
671
  var _apiKey, _stage, _isGeoloniaStyle;
@@ -823,6 +951,24 @@ var textColor = "#000000";
823
951
  var textHaloColor = "#FFFFFF";
824
952
  var backgroundColor = "rgba(255, 0, 0, 0.4)";
825
953
  var strokeColor = "#FFFFFF";
954
+ var polygonFillColor = [
955
+ "string",
956
+ ["get", "fill"],
957
+ backgroundColor
958
+ ];
959
+ var pointRadius = [
960
+ "case",
961
+ ["==", "small", ["get", "marker-size"]],
962
+ 7,
963
+ ["==", "large", ["get", "marker-size"]],
964
+ 13,
965
+ 9
966
+ ];
967
+ var pointColor = [
968
+ "string",
969
+ ["get", "marker-color"],
970
+ backgroundColor
971
+ ];
826
972
  var template = {
827
973
  type: "FeatureCollection",
828
974
  features: []
@@ -846,10 +992,10 @@ var SimpleStyle = class {
846
992
  id: "geolonia-simple-style",
847
993
  cluster: true,
848
994
  heatmap: false,
849
- // TODO: It should support heatmap.
850
995
  clusterColor: "#ff0000",
851
996
  ...options
852
997
  };
998
+ this.heatmap = normalizeHeatmap(this.options.heatmap);
853
999
  }
854
1000
  /**
855
1001
  * 表示中のデータを新しい GeoJSON で差し替えます。
@@ -880,6 +1026,7 @@ var SimpleStyle = class {
880
1026
  features: points
881
1027
  }
882
1028
  );
1029
+ this.applyDataDrivenPaint();
883
1030
  return this;
884
1031
  }
885
1032
  /**
@@ -924,7 +1071,7 @@ var SimpleStyle = class {
924
1071
  type: "FeatureCollection",
925
1072
  features: points
926
1073
  },
927
- cluster: this.options.cluster,
1074
+ cluster: this.options.cluster && !this.heatmap && !this.options.circle,
928
1075
  clusterMaxZoom: 14,
929
1076
  clusterRadius: 50
930
1077
  });
@@ -973,8 +1120,13 @@ var SimpleStyle = class {
973
1120
  "text-allow-overlap": false
974
1121
  }
975
1122
  });
976
- this.setPointGeometries();
977
- this.setCluster();
1123
+ if (this.heatmap) {
1124
+ this.setHeatmap();
1125
+ } else {
1126
+ this.setPointGeometries();
1127
+ this.setCluster();
1128
+ }
1129
+ this.applyDataDrivenPaint();
978
1130
  return this;
979
1131
  }
980
1132
  /**
@@ -1018,8 +1170,12 @@ var SimpleStyle = class {
1018
1170
  source: this.options.id,
1019
1171
  filter: ["==", "$type", "Polygon"],
1020
1172
  paint: {
1021
- "fill-color": ["string", ["get", "fill"], backgroundColor],
1022
- "fill-opacity": ["number", ["get", "fill-opacity"], 1],
1173
+ "fill-color": polygonFillColor,
1174
+ "fill-opacity": [
1175
+ "number",
1176
+ ["get", "fill-opacity"],
1177
+ this.options.choropleth ? 0.7 : 1
1178
+ ],
1023
1179
  "fill-outline-color": ["string", ["get", "stroke"], strokeColor]
1024
1180
  }
1025
1181
  });
@@ -1060,30 +1216,28 @@ var SimpleStyle = class {
1060
1216
  * `marker-size`(`small`、`large`、その他)に応じて円の半径やラベルのオフセットを変え、
1061
1217
  * `marker-color`、`stroke`、`title`、`text-color` などの simplestyle プロパティを反映します。
1062
1218
  * あわせて円レイヤーとシンボルレイヤーの双方に {@link SimpleStyle.setPopup | setPopup} でポップアップを設定します。
1219
+ * `circle` オプションを指定したときは、`marker-symbol` の有無にかかわらずすべてのポイントを円で描き、
1220
+ * シンボルレイヤーは追加しません。
1063
1221
  * 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
1064
1222
  */
1065
1223
  setPointGeometries() {
1224
+ const circleOnly = !!this.options.circle;
1066
1225
  this.map.addLayer({
1067
1226
  id: `${this.options.id}-circle-points`,
1068
1227
  type: "circle",
1069
1228
  source: `${this.options.id}-points`,
1070
- filter: ["all", ["!has", "point_count"], ["!has", "marker-symbol"]],
1229
+ filter: circleOnly ? ["!has", "point_count"] : ["all", ["!has", "point_count"], ["!has", "marker-symbol"]],
1071
1230
  paint: {
1072
- "circle-radius": [
1073
- "case",
1074
- ["==", "small", ["get", "marker-size"]],
1075
- 7,
1076
- ["==", "large", ["get", "marker-size"]],
1077
- 13,
1078
- 9
1079
- ],
1080
- "circle-color": ["string", ["get", "marker-color"], backgroundColor],
1231
+ "circle-radius": pointRadius,
1232
+ "circle-color": pointColor,
1081
1233
  "circle-opacity": ["number", ["get", "fill-opacity"], 1],
1082
1234
  "circle-stroke-width": ["number", ["get", "stroke-width"], 1],
1083
1235
  "circle-stroke-color": ["string", ["get", "stroke"], strokeColor],
1084
1236
  "circle-stroke-opacity": ["number", ["get", "stroke-opacity"], 1]
1085
1237
  }
1086
1238
  });
1239
+ this.setPopup(this.map, `${this.options.id}-circle-points`);
1240
+ if (circleOnly) return;
1087
1241
  this.map.addLayer({
1088
1242
  id: `${this.options.id}-symbol-points`,
1089
1243
  type: "symbol",
@@ -1117,9 +1271,73 @@ var SimpleStyle = class {
1117
1271
  ]
1118
1272
  }
1119
1273
  });
1120
- this.setPopup(this.map, `${this.options.id}-circle-points`);
1121
1274
  this.setPopup(this.map, `${this.options.id}-symbol-points`);
1122
1275
  }
1276
+ /**
1277
+ * ポイントのヒートマップレイヤーを設定します。
1278
+ *
1279
+ * `heatmap` オプションを指定したときに、ポイントのマーカーとクラスターの代わりに使います。
1280
+ * 重みは {@link SimpleStyle.applyDataDrivenPaint | applyDataDrivenPaint} がデータに合わせて設定します。
1281
+ * 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
1282
+ */
1283
+ setHeatmap() {
1284
+ this.map.addLayer({
1285
+ id: `${this.options.id}-heatmap`,
1286
+ type: "heatmap",
1287
+ source: `${this.options.id}-points`,
1288
+ paint: {
1289
+ "heatmap-weight": 1,
1290
+ "heatmap-intensity": ["interpolate", ["linear"], ["zoom"], 9, 1, 14, 3],
1291
+ "heatmap-radius": 22,
1292
+ "heatmap-opacity": 0.85,
1293
+ "heatmap-color": heatmapColor(this.heatmap ?? {})
1294
+ }
1295
+ });
1296
+ }
1297
+ /**
1298
+ * `choropleth`、`heatmap`、`circle` オプションの式を、現在のデータに合わせて設定します。
1299
+ *
1300
+ * 値の範囲やカテゴリはデータから求めるため、{@link SimpleStyle.addTo | addTo} と
1301
+ * {@link SimpleStyle.updateData | updateData} のたびに呼び出します。
1302
+ */
1303
+ applyDataDrivenPaint() {
1304
+ if (!this.map) return;
1305
+ const id = this.options.id;
1306
+ const features = this.geojson.features;
1307
+ const set = (layer, name, value) => {
1308
+ if (this.map.getLayer(layer)) {
1309
+ this.map.setPaintProperty(layer, name, value);
1310
+ }
1311
+ };
1312
+ const choropleth = normalizeChoropleth(this.options.choropleth);
1313
+ if (choropleth) {
1314
+ set(
1315
+ `${id}-polygon`,
1316
+ "fill-color",
1317
+ choroplethColor(choropleth, features, polygonFillColor)
1318
+ );
1319
+ }
1320
+ if (this.heatmap) {
1321
+ set(
1322
+ `${id}-heatmap`,
1323
+ "heatmap-weight",
1324
+ heatmapWeight(this.heatmap, features)
1325
+ );
1326
+ }
1327
+ const circle = this.options.circle;
1328
+ if (circle) {
1329
+ set(
1330
+ `${id}-circle-points`,
1331
+ "circle-radius",
1332
+ circleRadius(circle, features, pointRadius)
1333
+ );
1334
+ set(
1335
+ `${id}-circle-points`,
1336
+ "circle-color",
1337
+ circleColor(circle, features, pointColor)
1338
+ );
1339
+ }
1340
+ }
1123
1341
  /**
1124
1342
  * 指定したレイヤーにクリックでポップアップを表示するイベントハンドラーを設定します。
1125
1343
  *
@@ -1256,7 +1474,8 @@ var SimpleStyle = class {
1256
1474
  `${id}-polygon`,
1257
1475
  `${id}-linestring`,
1258
1476
  `${id}-clusters`,
1259
- `${id}-cluster-count`
1477
+ `${id}-cluster-count`,
1478
+ `${id}-heatmap`
1260
1479
  ];
1261
1480
  for (const layerId of layerIds) {
1262
1481
  if (this.map.getLayer(layerId)) {
@@ -1684,6 +1903,61 @@ function normalizeConstructorArg(arg) {
1684
1903
  return arg;
1685
1904
  }
1686
1905
 
1906
+ // src/lib/transform-request.ts
1907
+ function transformGeoloniaRequest(url, resourceType, { apiKey, stage, sessionId: sessionId2, sourcesUrl }) {
1908
+ if (resourceType === "Source" && url.startsWith("https://api.geolonia.com")) {
1909
+ return { url: sourcesUrl, request: { url: sourcesUrl } };
1910
+ }
1911
+ let transformedUrl = url;
1912
+ if (url.startsWith("geolonia://")) {
1913
+ const tilesMatch = url.match(
1914
+ /^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/
1915
+ );
1916
+ if (tilesMatch?.groups) {
1917
+ transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
1918
+ }
1919
+ }
1920
+ const transformedUrlObj = new URL(transformedUrl);
1921
+ const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
1922
+ if (resourceType === "Source" && geoloniaTilesHost) {
1923
+ if (stage === "dev" && transformedUrlObj.hostname === "tileserver.geolonia.com") {
1924
+ transformedUrlObj.hostname = "tileserver-dev.geolonia.com";
1925
+ }
1926
+ transformedUrlObj.searchParams.set("sessionId", sessionId2);
1927
+ transformedUrlObj.searchParams.set("key", apiKey);
1928
+ const transformed = transformedUrlObj.toString();
1929
+ return { url: transformed, request: { url: transformed } };
1930
+ }
1931
+ if ((resourceType === "SpriteJSON" || resourceType === "SpriteImage") && transformedUrl.match(/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//)) {
1932
+ const pathParts = transformedUrlObj.pathname.split("/");
1933
+ pathParts[1] = stage;
1934
+ transformedUrlObj.pathname = pathParts.join("/");
1935
+ transformedUrlObj.searchParams.set("key", apiKey);
1936
+ const transformed = transformedUrlObj.toString();
1937
+ return { url: transformed, request: { url: transformed } };
1938
+ }
1939
+ return { url: transformedUrl };
1940
+ }
1941
+ function isThenable(value) {
1942
+ return typeof value === "object" && value !== null && typeof value.then === "function";
1943
+ }
1944
+ function createTransformRequest(context) {
1945
+ const { userTransformRequest } = context;
1946
+ return (url, resourceType) => {
1947
+ const core = transformGeoloniaRequest(url, resourceType, context);
1948
+ if (typeof userTransformRequest !== "function") {
1949
+ return core.request;
1950
+ }
1951
+ const userResult = userTransformRequest(core.url, resourceType);
1952
+ if (isThenable(userResult)) {
1953
+ return Promise.resolve(userResult).then(
1954
+ (resolved) => resolved ?? core.request ?? { url: core.url }
1955
+ );
1956
+ }
1957
+ return userResult ?? core.request;
1958
+ };
1959
+ }
1960
+
1687
1961
  // src/lib/geolonia-map.ts
1688
1962
  var pmtilesRegistered = false;
1689
1963
  function ensurePMTiles() {
@@ -1756,44 +2030,13 @@ var GeoloniaMap = class extends maplibregl5.Map {
1756
2030
  const sourcesUrl = new URL(`${apiUrl}/sources`);
1757
2031
  sourcesUrl.searchParams.set("key", apiKey);
1758
2032
  sourcesUrl.searchParams.set("sessionId", sessionId2);
1759
- const userTransformRequest = options.transformRequest;
1760
- const transformRequest = (url, resourceType) => {
1761
- if (resourceType === "Source" && url.startsWith("https://api.geolonia.com")) {
1762
- return { url: sourcesUrl.toString() };
1763
- }
1764
- let transformedUrl = url;
1765
- if (url.startsWith("geolonia://")) {
1766
- const tilesMatch = url.match(
1767
- /^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/
1768
- );
1769
- if (tilesMatch?.groups) {
1770
- transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
1771
- }
1772
- }
1773
- const transformedUrlObj = new URL(transformedUrl);
1774
- const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
1775
- if (resourceType === "Source" && geoloniaTilesHost) {
1776
- if (stage === "dev" && transformedUrlObj.hostname === "tileserver.geolonia.com") {
1777
- transformedUrlObj.hostname = "tileserver-dev.geolonia.com";
1778
- }
1779
- transformedUrlObj.searchParams.set("sessionId", sessionId2);
1780
- transformedUrlObj.searchParams.set("key", apiKey);
1781
- return { url: transformedUrlObj.toString() };
1782
- }
1783
- if ((resourceType === "SpriteJSON" || resourceType === "SpriteImage") && transformedUrl.match(
1784
- /^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//
1785
- )) {
1786
- const pathParts = transformedUrlObj.pathname.split("/");
1787
- pathParts[1] = stage;
1788
- transformedUrlObj.pathname = pathParts.join("/");
1789
- transformedUrlObj.searchParams.set("key", apiKey);
1790
- return { url: transformedUrlObj.toString() };
1791
- }
1792
- if (typeof userTransformRequest === "function") {
1793
- return userTransformRequest(transformedUrl, resourceType);
1794
- }
1795
- return void 0;
1796
- };
2033
+ const transformRequest = createTransformRequest({
2034
+ apiKey,
2035
+ stage,
2036
+ sessionId: sessionId2,
2037
+ sourcesUrl: sourcesUrl.toString(),
2038
+ userTransformRequest: options.transformRequest
2039
+ });
1797
2040
  let loading;
1798
2041
  const showLoader = options.loader !== false;
1799
2042
  if (showLoader) {
@@ -1831,6 +2074,9 @@ var GeoloniaMap = class extends maplibregl5.Map {
1831
2074
  "geojson",
1832
2075
  "cluster",
1833
2076
  "clusterColor",
2077
+ "choropleth",
2078
+ "heatmap",
2079
+ "circle",
1834
2080
  "simpleVector",
1835
2081
  "3d",
1836
2082
  "errorMessage"
@@ -1862,7 +2108,7 @@ var GeoloniaMap = class extends maplibregl5.Map {
1862
2108
  const nav = parseControlOption(options.navigationControl ?? true);
1863
2109
  if (nav.enabled) {
1864
2110
  this.addControl(
1865
- new maplibregl5.NavigationControl(),
2111
+ new maplibregl5.NavigationControl({ visualizePitch: true }),
1866
2112
  nav.position
1867
2113
  );
1868
2114
  }
@@ -1945,7 +2191,10 @@ var GeoloniaMap = class extends maplibregl5.Map {
1945
2191
  if (options.geojson) {
1946
2192
  const ss = new SimpleStyle(options.geojson, {
1947
2193
  cluster: options.cluster !== false,
1948
- clusterColor: options.clusterColor || "#ff0000"
2194
+ clusterColor: options.clusterColor || "#ff0000",
2195
+ choropleth: options.choropleth,
2196
+ heatmap: options.heatmap,
2197
+ circle: options.circle
1949
2198
  });
1950
2199
  ss.addTo(this);
1951
2200
  if (!options.center) {
@@ -2055,7 +2304,7 @@ var GeoloniaMap = class extends maplibregl5.Map {
2055
2304
  };
2056
2305
 
2057
2306
  // src/version.ts
2058
- var VERSION = "0.6.0";
2307
+ var VERSION = "0.8.0";
2059
2308
  export {
2060
2309
  attribution_default as CustomAttributionControl,
2061
2310
  DEFAULT_STAGE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/maps-core",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "module": "dist/npm/index.js",
6
6
  "types": "dist/npm/index.d.ts",
@@ -20,26 +20,26 @@
20
20
  "@turf/bbox": "^7.4.0",
21
21
  "@turf/center": "^7.4.0",
22
22
  "pmtiles": "^4.5.0",
23
- "sanitize-html": "^2.17.7",
23
+ "sanitize-html": "^2.18.1",
24
24
  "tinycolor2": "^1.4.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "maplibre-gl": "^6.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@biomejs/biome": "^2.0.0",
31
- "@playwright/test": "^1.58.2",
30
+ "@biomejs/biome": "^2.5.15",
31
+ "@playwright/test": "^1.64.1",
32
32
  "@types/sanitize-html": "^2.16.1",
33
33
  "@types/tinycolor2": "^1.4.6",
34
- "@vitest/coverage-v8": "^5.0.1",
35
- "esbuild": "^0.28.1",
36
- "jsdom": "^29.0.1",
37
- "maplibre-gl": "6.10.0",
38
- "tsup": "^8",
34
+ "@vitest/coverage-v8": "^5.0.5",
35
+ "esbuild": "^0.28.2",
36
+ "jsdom": "^30.1.3",
37
+ "maplibre-gl": "6.15.0",
38
+ "tsup": "^9",
39
39
  "typedoc": "^0.28.20",
40
- "typedoc-plugin-markdown": "^4.12.0",
41
- "typescript": "^5.8",
42
- "vite": "^8.1.2",
40
+ "typedoc-plugin-markdown": "^4.14.0",
41
+ "typescript": "^6.0",
42
+ "vite": "^8.3.4",
43
43
  "vitest": "^5.0.2"
44
44
  },
45
45
  "scripts": {