Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I modelli sono asset 3D che possono essere aggiunti alla scena per rappresentare gli oggetti. Le
mappe 3D fotorealistiche nell'API Maps JavaScript supporta l'inclusione di modelli glTF. Questi modelli possono essere scalati e ruotati per consentire un'ulteriore personalizzazione.
Il costruttore
Model3DElement
prende un set di Model3DElementOptions che specifica le coordinate LatLng
del modello e un set di parametri per supportare il posizionamento
del modello.
I modelli supportano le seguenti opzioni:
position: la posizione del modello espressa in coordinate LatLng.
orientation: la rotazione del sistema di coordinate del modello. Le rotazioni vengono applicate nel seguente ordine: rotazione, inclinazione e poi intestazione.
scale: scala il modello nello spazio di coordinate. Il valore predefinito è 1.
altitudeMode: come viene interpretata l'altitudine espressa in position.
src: l'URL del modello.
L'esempio seguente mostra l'aggiunta di modelli alla mappa e la loro modifica utilizzando le opzioni di personalizzazione disponibili:
asyncfunctioninit(){const{Map3DElement,MapMode,Model3DElement}=awaitgoogle.maps.importLibrary("maps3d");constmap=newMap3DElement({center:{lat:37.7438,lng:-121.5088,altitude:1800},heading:-90,tilt:90,mode:MapMode.SATELLITE,});document.body.append(map);constmodels=[// A model with regular settings.{position:{lat:37.76,lng:-121.63,altitude:0},orientation:{tilt:270},},// Scaled down model.{position:{lat:37.75,lng:-121.63,altitude:0},orientation:{tilt:270},scale:0.8,},// Scaled up model.{position:{lat:37.735,lng:-121.63,altitude:0},orientation:{tilt:270},scale:1.2,},// A model with an additional transformation applied.{position:{lat:37.72,lng:-121.63,altitude:0},orientation:{tilt:270,roll:90},},// Non-clamped to the ground model.{position:{lat:37.71,lng:-121.63,altitude:1000},altitudeMode:'RELATIVE_TO_GROUND',orientation:{tilt:270},},];for(const{position,altitudeMode,orientation,scale}ofmodels){constmodel=newModel3DElement({src:'https://storage.googleapis.com/maps-web-api.appspot.com/gltf/windmill.glb',position,altitudeMode,orientation,scale,});map.append(model);}}init();
Aggiungi un modello interattivo
I modelli supportano anche l'interazione. L'esempio seguente modifica la scala
del modello quando viene fatto clic.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-04-29 UTC."],[],[],null,["Select platform: [Android](/maps/documentation/maps-3d/android-sdk/add-3d-models \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-3d-models \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/models \"View this page for the JavaScript 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\n\nModels are 3D assets that can be added to scene to represent objects. The\nPhotorealistic 3D Maps in Maps JavaScript API supports the inclusion of gLTF models. These models can be\nscaled and rotated to allow for further customization.\n\nThe models must support the [core properties of the glTF\nPBR](https://www.khronos.org/gltf/pbr). No extensions or extension properties\nare supported.\n\nAdd a model\n\nThe\n[`Model3DElement`](/maps/documentation/javascript/reference/3d-mapModel3DElement)\nconstructor takes a set of `Model3DElementOptions` specifying the `LatLng`\ncoordinates of the model and a set of parameters to support positioning the\nmodel.\n\nModels support the following options:\n\n- `position`: The location of the model expressed in `LatLng` coordinates.\n- `orientation`: The rotation of the model's coordinate system. Rotations are applied in the following order: roll, tilt and then heading.\n- `scale`: Scales the model in its coordinate space. The default value is `1`.\n- `altitudeMode`: How the altitude expressed in `position` is interpreted.\n- `src`: The URL of the model.\n\n| **Important:** In order for models to render in the scene, you must specify both `position` and `src` options.\n| **Note:** If you're hosting your model files on a different website or server than your main application, you must ensure that your application sets the correct [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) HTTP headers.\n\nThe following example demonstrates adding models to the map and modifying them\nusing the available customization options: \n\n async function init() {\n const { Map3DElement, MapMode, Model3DElement } = await google.maps.importLibrary(\"maps3d\");\n\n const map = new Map3DElement({\n center: {lat: 37.7438, lng: -121.5088, altitude: 1800},\n heading: -90,\n tilt: 90,\n mode: MapMode.SATELLITE,\n });\n\n document.body.append(map);\n const models = \\[\n // A model with regular settings.\n {\n position: {lat: 37.76, lng: -121.63, altitude: 0},\n orientation: {tilt: 270},\n },\n // Scaled down model.\n {\n position: {lat: 37.75, lng: -121.63, altitude: 0},\n orientation: {tilt: 270},\n scale: 0.8,\n },\n // Scaled up model.\n {\n position: {lat: 37.735, lng: -121.63, altitude: 0},\n orientation: {tilt: 270},\n scale: 1.2,\n },\n // A model with an additional transformation applied.\n {\n position: {lat: 37.72, lng: -121.63, altitude: 0},\n orientation: {tilt: 270, roll: 90},\n },\n // Non-clamped to the ground model.\n {\n position: {lat: 37.71, lng: -121.63, altitude: 1000},\n altitudeMode: 'RELATIVE_TO_GROUND',\n orientation: {tilt: 270},\n },\n \\];\n for (const {position, altitudeMode, orientation, scale} of models) {\n const model = new Model3DElement({\n src: 'https://storage.googleapis.com/maps-web-api.appspot.com/gltf/windmill.glb',\n position,\n altitudeMode,\n orientation,\n scale,\n });\n map.append(model);\n }\n }\n\n init();\n\nAdd an interactive model\n\nModels also support interaction. The following example changes the model's scale\nwhen clicked. \n\n async function init() {\n const { Map3DElement, MapMode, Model3DInteractiveElement } = await google.maps.importLibrary(\"maps3d\");\n\n const map = new Map3DElement({\n center: {lat: 37.7438, lng: -121.5088, altitude: 1800},\n heading: -90,\n tilt: 90,\n mode: MapMode.SATELLITE,\n });\n\n document.body.append(map);\n\n const model = new Model3DInteractiveElement({\n src: 'https://storage.googleapis.com/maps-web-api.appspot.com/gltf/windmill.glb',\n position: {lat: 37.76, lng: -121.63, altitude: 0},\n scale: 1.0,\n });\n\n model.addEventListener('gmp-click', (event) =\u003e {\n model.scale = (Math.random() * (1 - 2)).toFixed(2);\n\n });\n\n map.append(model);\n }\n\n init();"]]