Map.setOptions
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sửa đổi bản đồ cơ sở của Google Maps. Cho phép:
1) Đặt MapType hiện tại. 2) Cung cấp kiểu tuỳ chỉnh cho bản đồ cơ sở (MapTypeStyles). 3) Thiết lập danh sách mapTypesIds có sẵn cho bản đồ cơ sở.
Nếu được gọi mà không có tham số, phương thức này sẽ đặt lại loại bản đồ thành loại mặc định của Google.
Trả về bản đồ.
Cách sử dụng | Giá trị trả về |
---|
Map.setOptions(mapTypeId, styles, types) | ui.Map |
Đối số | Loại | Thông tin chi tiết |
---|
mapTypeId | Chuỗi, không bắt buộc | Một mapTypeId để đặt bản đồ cơ sở. Có thể là một trong các giá trị "ROADMAP", "SATELLITE", "HYBRID" hoặc "TERRAIN" để chọn một trong các loại bản đồ API Google Maps tiêu chuẩn hoặc một trong các khoá được chỉ định trong từ điển opt_styles. Nếu bạn để trống và chỉ định 1 kiểu trong opt_styles, thì kiểu đó sẽ được dùng. |
styles | Đối tượng, không bắt buộc | Một từ điển gồm các đối tượng MapTypeStyle tuỳ chỉnh được khoá bằng một tên sẽ xuất hiện trong các chế độ kiểm soát Loại bản đồ của bản đồ. Xem: https://developers.google.com/maps/documentation/javascript/reference#MapTypeStyle |
types | List<String>, không bắt buộc | Danh sách mapTypeIds cần cung cấp. Nếu bạn bỏ qua tham số này nhưng chỉ định opt_styles, thì hệ thống sẽ thêm tất cả các khoá kiểu vào các loại bản đồ tiêu chuẩn của Google Maps API. |
Ví dụ
Trình soạn thảo mã (JavaScript)
// Types
Map.setOptions('HYBRID');
Map.setOptions('ROADMAP');
Map.setOptions('SATELLITE');
Map.setOptions('TERRAIN');
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-25 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eModifies the Google Maps basemap by setting the map type, providing custom styles, and controlling available map types.\u003c/p\u003e\n"],["\u003cp\u003eAccepts parameters to change the basemap's appearance or resets to the default Google Maps style when called without parameters.\u003c/p\u003e\n"],["\u003cp\u003eOffers flexibility in styling through custom MapTypeStyle objects and allows for selection from standard Google Maps API map types or custom styles.\u003c/p\u003e\n"],["\u003cp\u003eUses the \u003ccode\u003esetOptions()\u003c/code\u003e method with arguments for mapTypeId, styles, and types to implement the modifications.\u003c/p\u003e\n"],["\u003cp\u003eReturns the ui.Map object after applying the specified options.\u003c/p\u003e\n"]]],["This function, `Map.setOptions()`, modifies the Google Maps basemap. It can set the `mapTypeId` to \"ROADMAP,\" \"SATELLITE,\" \"HYBRID,\" or \"TERRAIN,\" or to a custom style from the `styles` dictionary. Custom styles (`styles`) are defined as `MapTypeStyle` objects. The available `mapTypeIds` displayed in the basemap can be defined in `types`. If called without arguments, the function reverts to the default Google map type. It returns the modified `ui.Map` object.\n"],null,["# Map.setOptions\n\n\u003cbr /\u003e\n\nModifies the Google Maps basemap. Allows for:\n\n\u003cbr /\u003e\n\n1) Setting the current MapType. 2) Providing custom styles for the basemap (MapTypeStyles). 3) Setting the list of available mapTypesIds for the basemap.\n\nIf called with no parameters, resets the map type to the google default.\n\nReturns the map.\n\n| Usage | Returns |\n|----------------------------------------------------------|---------|\n| `Map.setOptions(`*mapTypeId* `, `*styles* `, `*types*`)` | ui.Map |\n\n| Argument | Type | Details |\n|-------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `mapTypeId` | String, optional | A mapTypeId to set the basemap to. Can be one of \"ROADMAP\", \"SATELLITE\", \"HYBRID\" or \"TERRAIN\" to select one of the standard Google Maps API map types, or one of the keys specified in the opt_styles dictionary. If left as null and only 1 style is specified in opt_styles, that style will be used. |\n| `styles` | Object, optional | A dictionary of custom MapTypeStyle objects keyed with a name that will appear in the map's Map Type Controls. See: https://developers.google.com/maps/documentation/javascript/reference#MapTypeStyle |\n| `types` | List\\\u003cString\\\u003e, optional | A list of mapTypeIds to make available. If omitted, but opt_styles is specified, appends all of the style keys to the standard Google Maps API map types. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Types\nMap.setOptions('HYBRID');\nMap.setOptions('ROADMAP');\nMap.setOptions('SATELLITE');\nMap.setOptions('TERRAIN');\n```"]]