reviewsהשקת Places UI Kit: ספריית רכיבים מוכנה לשימוש בעלות נמוכה, שמאפשרת לכם להוסיף לכל מפה שתבחרו את ממשק המשתמש המוכר של 'מקומות' במפות Google. כדאי לנסות אותו ולשלוח לנו משוב כדי לעזור לנו לעצב את העתיד של GMP.
אפשר להוסיף למפה צורות שונות. צורה היא אובייקט במפה שקשור לLatLng מערכת קואורדינטות. מפות פוטוריאליסטיות תלת-ממדיות ב-Maps JavaScript API תומכות בהוספה של קווים ומצולעים למפה.
קו פוליגוני
כדי לשרטט קו במפה, משתמשים בקו פוליגוני. המחלקות
Polyline3DElement
מגדירות שכבת-על לינארית של מקטעי קו מחוברים במפה. אובייקט Polyline מורכב ממערך של מיקומי LatLng, ויוצר סדרה של קטעי קו שמחברים את המיקומים האלה ברצף מסודר.
הוספת קו מרובה
הבונה Polyline מקבל קבוצה של Polyline3DElementOptions שמציינת את LatLng הקואורדינטות של הקו וקבוצה של סגנונות להתאמת ההתנהגות החזותית של הקו.
אובייקטים מסוג Polyline מצוירים כסדרה של קטעים ישרים במפה. אפשר לציין צבעים, רוחבים, רמות אטימות, גבהים ואפשרויות עיצוב גיאומטריות מותאמים אישית לקו בתוך התג Polyline3DElementOptions כשיוצרים את הקו, או לשנות את המאפיינים האלה אחרי היצירה. קו פוליגוני תומך בסגנונות הקו הבאים:
outerColor: צבע הקסדצימלי ב-HTML בפורמט "#FFFFFF".
outerWidth: ערך מספרי בין 0.0 ל-1.0, שמתורגם לאחוז מתוך strokeWidth.
strokeColor: צבע הקסדצימלי ב-HTML בפורמט "#FFFFFF".
strokeWidth: רוחב הקו בפיקסלים.
geodesic: האם הקצוות של הפוליגון עוקבים אחרי העיקול של כדור הארץ, או שהם מצוירים כקווים ישרים.
altitudeMode: איך מפרשים את רכיבי הגובה בקואורדינטות
drawsOccludedSegments: ערך בוליאני שמציין אם צריך לצייר חלקים של הפוליגון שמוסתרים על ידי אובייקטים (כמו בניינים).
extruded: ערך בוליאני שמציין אם הקו צריך להיות מחובר לקרקע.
מצולע מייצג אזור שמוקף בנתיב סגור (או בלולאה), שמוגדר על ידי סדרה של קואורדינטות.
אובייקטים מסוג Polygon דומים לאובייקטים מסוג Polyline בכך שהם מורכבים מסדרה של קואורדינטות ברצף מסודר. פוליגונים מצוירים עם קו מתאר ומילוי.
אפשר להגדיר צבעים ורוחבים מותאמים אישית לקצה של המצולע (הקו) וצבעים ואטימויות מותאמים אישית לאזור הסגור (המילוי). צריך לציין את הצבעים בפורמט הקסדצימלי של HTML. אין תמיכה בשמות של צבעים.
אובייקטים של Polygon יכולים לתאר צורות מורכבות, כולל:
כמה אזורים לא סמוכים שמוגדרים על ידי פוליגון יחיד.
אזורים עם חורים.
הצטלבות של אזור אחד או יותר.
כדי להגדיר צורה מורכבת, משתמשים במצולע עם כמה נתיבים.
הוספת מצולע
מכיוון שאזור פוליגוני יכול לכלול כמה נתיבים נפרדים, מאפיין הנתיבים של האובייקט Polygon
object מציין מערך של מערכים, שכל אחד מהם הוא מסוג MVCArray.
כל מערך מגדיר רצף נפרד של קואורדינטות LatLng מסודרות.
למצולעים בסיסיים שמורכבים מנתיב אחד בלבד, אפשר ליצור Polygon באמצעות מערך אחד של קואורדינטות LatLng. מפות פוטוריאליסטיות תלת-ממדיות ב-Maps JavaScript API ימירו את המערך למערך של מערכים בזמן היצירה, כשהוא מאוחסן במאפיין outerCoordinates.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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();"]]