シェイプとライン
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
地図にはさまざまなシェイプを追加できます。シェイプは地図上のオブジェクトであり、LatLng
座標系と紐付けされています。Maps JavaScript API の Photorealistic 3D Maps では、地図に線やポリゴンを追加できます。
ポリライン
地図上にラインを描画するにはポリラインを使用します。Polyline3DElement
クラスは、地図上で連結された一連のラインからなる線形オーバーレイを定義します。Polyline
オブジェクトは LatLng
位置の配列で構成され、これらの位置を決まった順序で連結する一連の線分を作成します。
ポリラインを追加する
Polyline
コンストラクタは、ラインの LatLng
座標を指定する一連の Polyline3DElementOptions
と、ポリラインの視覚的な動作を調整する一連のスタイルを受け取ります。
ポリライン オブジェクトは、一連の直線セグメントとして地図上に描画されます。ラインの構成時に Polyline3DElementOptions
内で、ライン ストロークの色、太さ、不透明度、高さ、幾何学的なスタイリング オプションをカスタムで指定できます。または、構成後にこれらのプロパティを変更できます。ポリラインがサポートしているストローク スタイルは次のとおりです。
outerColor
: "#FFFFFF"
形式の 16 進数 HTML カラー。
outerWidth
: 0.0
~1.0
の数値。strokeWidth
の割合として解釈されます。
strokeColor
: "#FFFFFF"
形式の 16 進数 HTML カラー。
strokeWidth
: 線の幅(ピクセル単位)。
geodesic
: ポリゴンのエッジが地球の曲率に沿っているか、直線として描画されるか。
altitudeMode
: 座標の高度コンポーネントの解釈方法
drawsOccludedSegments
: オブジェクト(建物など)によって隠されているポリゴンの部分を描画するかどうかを示すブール値。
extruded
: ポリラインを地面に接続するかどうかを示すブール値。
async function init() {
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
const map = new Map3DElement({
center: { lat: 37.772675996068915, lng: -122.3978382542777, altitude: 2500 },
tilt: 45,
heading: 5.9743656,
mode: MapMode.HYBRID,
});
const { Polyline3DElement, AltitudeMode } = await google.maps.importLibrary("maps3d");
const polylineOptions = {
strokeColor: "#EA433580",
strokeWidth: 10,
altitudeMode: "ABSOLUTE",
extruded: true,
drawsOccludedSegments: true,
}
const polyline = new google.maps.maps3d.Polyline3DElement(polylineOptions)
polyline.coordinates = [
{lat: 37.80515638571346, lng: -122.4032569467164},
{lat: 37.80337073509504, lng: -122.4012878349353},
{lat: 37.79925208843463, lng: -122.3976697250461},
{lat: 37.7989102378512, lng: -122.3983408725656},
{lat: 37.79887832784348, lng: -122.3987094864192},
{lat: 37.79786443410338, lng: -122.4066878788802},
{lat: 37.79549248916587, lng: -122.4032992702785},
{lat: 37.78861484290265, lng: -122.4019489189814},
{lat: 37.78618687561075, lng: -122.398969592545},
{lat: 37.7892310309145, lng: -122.3951458683092},
{lat: 37.7916358762409, lng: -122.3981969390652}
];
map.append(polyline)
document.body.append(map);
}
init();
インタラクティブ ポリライン
次の例では、クリック イベントを登録した後で、ポリラインのストロークの色を変更しています。
async function init() {
const colors = ["red", "blue", "green", "yellow"];
const { Map3DElement, MapMode, Polyline3DInteractiveElement } = await google.maps.importLibrary("maps3d");
const map = new Map3DElement({
center: {lat: 0, lng: -180, altitude: 15000000},
mode: MapMode.HYBRID,
});
document.body.append(map);
const polyline = new Polyline3DInteractiveElement({
coordinates: [
{ lat: 37.772, lng: -122.214 },
{ lat: 21.291, lng: -157.821 },
{ lat: -18.142, lng: 178.431 },
{ lat: -27.467, lng: 153.027 }
],
strokeColor: 'red',
strokeWidth: 10,
});
polyline.addEventListener('gmp-click', (event) => {
polyline.strokeColor = colors[~~(Math.random() * colors.length)];
});
map.append(polyline);
}
init();
ポリゴン
ポリゴンは閉じられたパス(またはループ)により囲まれた領域を表し、一連の座標により定義されます。Polygon
オブジェクトは、指定された順序の一連の座標で構成されている点で Polyline
オブジェクトと似ています。ポリゴンは、ストロークと塗りつぶしにより描画されます。ポリゴンの縁(ストローク)の色と幅、閉じられた領域(塗りつぶし)の色と不透明度をカスタムで定義できます。色は 16 進数の HTML 形式で指定します。色名はサポートされていません。
Polygon
オブジェクトを使うと、次のような複雑なシェイプを描画できます。
- 単一のポリゴンで定義される、隣接しない複数の領域。
- 中に穴がある領域。
- 1 つ以上の領域の共通部分。
複雑なシェイプを定義するには、複数のパスを持つポリゴンを使用します。
ポリゴンを追加する
ポリゴンの領域には複数の個別のパスが含まれている場合があるため、Polygon
オブジェクトの paths プロパティでは配列の配列を指定します。各配列のタイプは MVCArray
です。各配列では、順序が指定された一連の LatLng
座標が個別に定義されます。
1 つのパスのみで構成される基本的なポリゴンの場合、単一の LatLng
座標配列を使用して Polygon
を構成できます。Maps JavaScript API の Photorealistic 3D Maps では、構成時にこの配列を outerCoordinates
プロパティに格納する際、配列の配列に変換されます。
async function init() {
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
const map3DElement = new Map3DElement({
center: { lat: 43.6425, lng: -79.3871, altitude: 400 },
range: 1000,
tilt: 60,
mode: MapMode.SATELLITE,
});
const { Polygon3DElement, AltitudeMode } = await google.maps.importLibrary("maps3d");
const polygonOptions = {
strokeColor: "#EA433580",
strokeWidth: 4,
fillColor: "#0000FF80",
altitudeMode: "ABSOLUTE",
extruded: true,
drawsOccludedSegments: true,
}
const towerPolygon = new google.maps.maps3d.Polygon3DElement(polygonOptions);
towerPolygon.outerCoordinates = [
{ lat: 43.6427196, lng: -79.3876802, altitude: 600 },
{ lat: 43.6421742, lng: -79.3869184, altitude: 600 },
{ lat: 43.643001, lng: -79.3866475, altitude: 600 }
];
map3DElement.append(towerPolygon);
document.body.append(map3DElement);
}
init();
インタラクティブなポリゴン
次の例では、クリック イベントを登録した後で、ポリゴンのストロークの色を変更しています。
async function init() {
const colors = ["red", "blue", "green", "yellow"];
const { Map3DElement, MapMode } = await google.maps.importLibrary("maps3d");
const map3DElement = new Map3DElement({
center: { lat: 43.6425, lng: -79.3871, altitude: 400 },
range: 1000,
tilt: 60,
mode: MapMode.SATELLITE,
});
const { Polygon3DInteractiveElement, AltitudeMode } = await google.maps.importLibrary("maps3d");
const polygonOptions = {
strokeColor: "#EA433580",
strokeWidth: 4,
fillColor: "#0000FF80",
altitudeMode: "ABSOLUTE",
extruded: true,
drawsOccludedSegments: true,
}
const towerPolygon = new google.maps.maps3d.Polygon3DInteractiveElement(polygonOptions);
towerPolygon.outerCoordinates = [
{ lat: 43.6427196, lng: -79.3876802, altitude: 600 },
{ lat: 43.6421742, lng: -79.3869184, altitude: 600 },
{ lat: 43.643001, lng: -79.3866475, altitude: 600 }
];
towerPolygon.addEventListener('gmp-click', (event) => {
towerPolygon.strokeColor = colors[~~(Math.random() * colors.length)];
});
map3DElement.append(towerPolygon);
document.body.append(map3DElement);
}
init();
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-12 UTC。
[null,null,["最終更新日 2025-08-12 UTC。"],[],[],null,["Select platform: [Android](/maps/documentation/maps-3d/android-sdk/add-polygons \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-polygons \"View this page for the iOS platform docs.\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage\n| descriptions](/maps/launch-stages).\n\n\u003cbr /\u003e\n\nYou can add various shapes to your map. A shape is an object on the map, tied to\na `LatLng` coordinate system. The Photorealistic 3D Maps in Maps JavaScript API supports the addition of\nlines and polygons to the map.\n\nPolylines\n\nTo draw a line on your map, use a polyline. The\n[`Polyline3DElement`](/maps/documentation/javascript/reference/3d-map#Polyline3DElement)\nclass defines a linear overlay of connected line segments on the map. A\n`Polyline` object consists of an array of `LatLng` locations, and creates a\nseries of line segments that connect those locations in an ordered sequence.\n\nAdd a polyline\n\nThe `Polyline` constructor takes a set of `Polyline3DElementOptions` specifying\nthe `LatLng` coordinates of the line and a set of styles to adjust the\npolyline's visual behavior.\n\nPolyline objects are drawn as a series of straight segments on the map. You can\nspecify custom colors, widths, opacities, heights, and geometric styling options\nfor the stroke of the line within the `Polyline3DElementOptions` when\nconstructing your line, or you can change those properties after construction. A\npolyline supports the following stroke styles:\n\n- `outerColor`: A hexadecimal HTML color of the format `\"#FFFFFF\"`.\n- `outerWidth`: A numerical value between `0.0` and `1.0`, which is interpreted as a percentage of the `strokeWidth`.\n- `strokeColor`: A hexadecimal HTML color of the format `\"#FFFFFF\"`.\n- `strokeWidth`: The width of the line in pixels.\n- `geodesic`: whether the edges of the polyon follows the curvature of the earth, or be drawn as straight lines.\n- `altitudeMode`: How altitude components in the coordinates are interpreted\n- `drawsOccludedSegments`: A boolean indicating whether parts of the polygon obscured by objects (such as buildings) should be drawn.\n- `extruded`: A boolean indicating if the polyline should be connected to the ground.\n\n async function init() {\n const { Map3DElement, MapMode } = await google.maps.importLibrary(\"maps3d\");\n\n const map = new Map3DElement({\n center: { lat: 37.772675996068915, lng: -122.3978382542777, altitude: 2500 },\n tilt: 45,\n heading: 5.9743656,\n mode: MapMode.HYBRID,\n });\n\n const { Polyline3DElement, AltitudeMode } = await google.maps.importLibrary(\"maps3d\");\n\n const polylineOptions = {\n strokeColor: \"#EA433580\",\n strokeWidth: 10,\n altitudeMode: \"ABSOLUTE\",\n extruded: true,\n drawsOccludedSegments: true,\n }\n const polyline = new google.maps.maps3d.Polyline3DElement(polylineOptions)\n\n polyline.coordinates = [\n {lat: 37.80515638571346, lng: -122.4032569467164},\n {lat: 37.80337073509504, lng: -122.4012878349353},\n {lat: 37.79925208843463, lng: -122.3976697250461},\n {lat: 37.7989102378512, lng: -122.3983408725656},\n {lat: 37.79887832784348, lng: -122.3987094864192},\n {lat: 37.79786443410338, lng: -122.4066878788802},\n {lat: 37.79549248916587, lng: -122.4032992702785},\n {lat: 37.78861484290265, lng: -122.4019489189814},\n {lat: 37.78618687561075, lng: -122.398969592545},\n {lat: 37.7892310309145, lng: -122.3951458683092},\n {lat: 37.7916358762409, lng: -122.3981969390652}\n ];\n\n map.append(polyline)\n document.body.append(map);\n }\n init();\n\nInteractive polylines\n\nThe following example changes the polyline's stroke color after registering a\nclick event. \n\n async function init() {\n const colors = [\"red\", \"blue\", \"green\", \"yellow\"];\n const { Map3DElement, MapMode, Polyline3DInteractiveElement } = await google.maps.importLibrary(\"maps3d\");\n const map = new Map3DElement({\n center: {lat: 0, lng: -180, altitude: 15000000},\n mode: MapMode.HYBRID,\n });\n\n document.body.append(map);\n const polyline = new Polyline3DInteractiveElement({\n coordinates: \\[\n { lat: 37.772, lng: -122.214 },\n { lat: 21.291, lng: -157.821 },\n { lat: -18.142, lng: 178.431 },\n { lat: -27.467, lng: 153.027 }\n \\],\n strokeColor: 'red',\n strokeWidth: 10,\n });\n polyline.addEventListener('gmp-click', (event) =\\\u003e {\n polyline.strokeColor = colors\\[\\~\\~(Math.random() \\* colors.length)\\];\n });\n map.append(polyline);\n }\n\n init();\n\nPolygons\n\nA polygon represents an area enclosed by a closed path (or loop), which is\ndefined by a series of coordinates.\n[`Polygon`](/maps/documentation/javascript/reference/3d-map#Polygon3DElement)\nobjects are similar to `Polyline` objects in that they consist of a series of\ncoordinates in an ordered sequence. Polygons are drawn with a stroke and a fill.\nYou can define custom colors and widths for the edge of the polygon (the stroke)\nand custom colors and opacities for the enclosed area (the fill). Colors should\nbe indicated in hexadecimal HTML format. Color names are not supported.\n\n`Polygon` objects can describe complex shapes, including:\n\n- Multiple non-contiguous areas defined by a single polygon.\n- Areas with holes in them.\n- Intersections of one or more areas.\n\nTo define a complex shape, you use a polygon with multiple paths.\n\nAdd a polygon\n\nBecause a polygonal area may include several separate paths, the `Polygon`\nobject's paths property specifies an array of arrays, each of type `MVCArray`.\nEach array defines a separate sequence of ordered `LatLng` coordinates.\n\nFor basic polygons consisting of only one path, you can construct a `Polygon`\nusing a single array of `LatLng` coordinates. The Photorealistic 3D Maps in Maps JavaScript API will\nconvert the array into an array of arrays upon construction when storing\nit within the `outerCoordinates` property. \n\n async function init() {\n const { Map3DElement, MapMode } = await google.maps.importLibrary(\"maps3d\");\n\n const map3DElement = new Map3DElement({\n center: { lat: 43.6425, lng: -79.3871, altitude: 400 },\n range: 1000,\n tilt: 60,\n mode: MapMode.SATELLITE,\n });\n\n const { Polygon3DElement, AltitudeMode } = await google.maps.importLibrary(\"maps3d\");\n\n const polygonOptions = {\n strokeColor: \"#EA433580\",\n strokeWidth: 4,\n fillColor: \"#0000FF80\",\n altitudeMode: \"ABSOLUTE\",\n extruded: true,\n drawsOccludedSegments: true,\n }\n\n const towerPolygon = new google.maps.maps3d.Polygon3DElement(polygonOptions);\n\n towerPolygon.outerCoordinates = [\n { lat: 43.6427196, lng: -79.3876802, altitude: 600 },\n { lat: 43.6421742, lng: -79.3869184, altitude: 600 },\n { lat: 43.643001, lng: -79.3866475, altitude: 600 }\n ];\n\n map3DElement.append(towerPolygon);\n document.body.append(map3DElement);\n }\n init();\n\nInteractive polygons\n\nThe following example changes the polygon's stroke color after registering a\nclick event. \n\n async function init() {\n const colors = [\"red\", \"blue\", \"green\", \"yellow\"];\n const { Map3DElement, MapMode } = await google.maps.importLibrary(\"maps3d\");\n\n const map3DElement = new Map3DElement({\n center: { lat: 43.6425, lng: -79.3871, altitude: 400 },\n range: 1000,\n tilt: 60,\n mode: MapMode.SATELLITE,\n });\n const { Polygon3DInteractiveElement, AltitudeMode } = await google.maps.importLibrary(\"maps3d\");\n const polygonOptions = {\n strokeColor: \"#EA433580\",\n strokeWidth: 4,\n fillColor: \"#0000FF80\",\n altitudeMode: \"ABSOLUTE\",\n extruded: true,\n drawsOccludedSegments: true,\n }\n const towerPolygon = new google.maps.maps3d.Polygon3DInteractiveElement(polygonOptions);\n towerPolygon.outerCoordinates = [\n { lat: 43.6427196, lng: -79.3876802, altitude: 600 },\n { lat: 43.6421742, lng: -79.3869184, altitude: 600 },\n { lat: 43.643001, lng: -79.3866475, altitude: 600 }\n ];\n towerPolygon.addEventListener('gmp-click', (event) =\\\u003e {\n towerPolygon.strokeColor = colors\\[\\~\\~(Math.random() \\* colors.length)\\];\n });\n map3DElement.append(towerPolygon);\n\n document.body.append(map3DElement);\n }\n\n init();"]]