Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Los modelos son recursos 3D que se pueden agregar a una escena para representar objetos. Los mapas en 3D fotorrealistas de la API de Maps JavaScript admiten la inclusión de modelos glTF. Estos modelos se pueden escalar y rotar para permitir una mayor personalización.
El constructor Model3DElement toma un conjunto de Model3DElementOptions que especifica las coordenadas LatLng del modelo y un conjunto de parámetros para admitir el posicionamiento del modelo.
Los modelos admiten las siguientes opciones:
position: Es la ubicación del modelo expresada en coordenadas LatLng.
orientation: Es la rotación del sistema de coordenadas del modelo. Las rotaciones se aplican en el siguiente orden: giro, inclinación y, luego, orientación.
scale: Escala el modelo en su espacio de coordenadas. El valor predeterminado es 1.
altitudeMode: Cómo se interpreta la altitud expresada en position.
src: Es la URL del modelo.
En el siguiente ejemplo, se muestra cómo agregar modelos al mapa y modificarlos con las opciones de personalización disponibles:
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();
Agrega un modelo interactivo
Los modelos también admiten interacción. En el siguiente ejemplo, se cambia la escala del modelo cuando se hace clic en él.
[null,null,["Última actualización: 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();"]]