เลเยอร์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เลเยอร์คือวัตถุบนแผนที่ที่ประกอบด้วยรายการแยกต่างหากอย่างน้อย 1 รายการ แต่มีการดัดแปลงเป็นหน่วยเดียว โดยทั่วไปแล้ว เลเยอร์จะแสดงคอลเล็กชันของออบเจ็กต์ที่คุณเพิ่มไว้ด้านบนแผนที่เพื่อระบุการเชื่อมโยงทั่วไป Maps JavaScript API จะจัดการการแสดงผลของวัตถุภายในเลเยอร์โดยแสดงผลรายการที่ประกอบเป็นวัตถุหนึ่งๆ (โดยปกติคือการวางซ้อนไทล์) และแสดงเมื่อวิดเจ็ตแผนที่มีการเปลี่ยนแปลง เลเยอร์ยังอาจเปลี่ยนแปลงเลเยอร์การแสดงแผนที่ด้วย โดยเปลี่ยนไทล์พื้นฐานเล็กน้อยให้สอดคล้องกับเลเยอร์ โปรดทราบว่าเลเยอร์ส่วนใหญ่อาจเข้าถึงผ่านออบเจ็กต์แต่ละรายการไม่ได้ตามการออกแบบ แต่สามารถจัดการเป็นกลุ่มได้เท่านั้น
ภาพรวมเลเยอร์
Maps JavaScript API มีเลเยอร์หลายประเภท ดังนี้
- เลเยอร์ข้อมูล Google Maps มีคอนเทนเนอร์สําหรับข้อมูลเชิงพื้นที่ที่กําหนดเอง
คุณสามารถใช้ชั้นข้อมูลเพื่อจัดเก็บข้อมูลที่กําหนดเอง หรือเพื่อแสดงข้อมูล GeoJSON ใน Google Maps
-
เลเยอร์แผนที่ความร้อนจะแสดงผลข้อมูลภูมิศาสตร์โดยใช้การแสดงภาพแผนที่ความร้อน
-
เลเยอร์ KML จะแสดงผลองค์ประกอบ KML และ GeoRSS ในการวางซ้อนไทล์ Maps JavaScript API
-
เลเยอร์การจราจรจะแสดงสภาพการจราจรบนแผนที่
-
เลเยอร์ขนส่งสาธารณะจะแสดงเครือข่ายขนส่งสาธารณะของเมืองบนแผนที่
- ออบเจ็กต์
เลเยอร์การปั่นจักรยานจะแสดงผลเลเยอร์ของเส้นทางจักรยานและ/หรือการวางซ้อนเฉพาะจักรยานเป็นเลเยอร์ทั่วไป ระบบจะแสดงเลเยอร์นี้โดยค่าเริ่มต้นภายใน DirectionsRenderer เมื่อขอเส้นทางสำหรับโหมดการเดินทาง BICYCLING
เพิ่มเลเยอร์
หากต้องการเพิ่มเลเยอร์ลงในแผนที่ คุณเพียงต้องเรียกใช้ setMap()
โดยส่งออบเจ็กต์แผนที่ที่จะแสดงเลเยอร์ ในทำนองเดียวกัน หากต้องการซ่อนเลเยอร์ ให้เรียกใช้ setMap()
โดยส่ง null
ข้อมูลโค้ดด้านล่างจะวางแผนที่ให้ศูนย์กลางอยู่ที่ลอนดอน สหราชอาณาจักร และเพิ่มเลเยอร์ขนส่งสาธารณะ
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(51.5,-0.11)
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(map);
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-06 UTC
[null,null,["อัปเดตล่าสุด 2025-08-06 UTC"],[[["\u003cp\u003eLayers in Maps JavaScript API are objects consisting of multiple items that are treated as a single unit and often represent collections of objects on the map.\u003c/p\u003e\n"],["\u003cp\u003eThe API provides various layer types, including Data, Heatmap, KML, Traffic, Transit, and Bicycling layers, each serving a distinct purpose for displaying geospatial data.\u003c/p\u003e\n"],["\u003cp\u003eYou can easily add or hide a layer by calling the \u003ccode\u003esetMap()\u003c/code\u003e method, providing the map object or \u003ccode\u003enull\u003c/code\u003e respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe example code demonstrates adding a Transit layer to a map centered on London.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/multilayer \"View this page for the Android platform docs.\") [JavaScript](/maps/documentation/javascript/layers \"View this page for the JavaScript platform docs.\")\n\nLayers are objects on the map that consist of one or more separate items,\nbut are manipulated as a single unit. Layers generally reflect collections of\nobjects that you add on top of the map to designate a common association. The\nMaps JavaScript API manages the presentation of objects within layers\nby rendering their constituent items into one object (typically a tile overlay) and\ndisplaying them as the map's viewport changes. Layers may also alter the presentation\nlayer of the map itself, slightly altering the base tiles in a fashion\nconsistent with the layer. Note that most layers, by design, may not be\naccessed via their individual objects, but may only be manipulated as a\nunit.\n\nLayers Overview\n\nThe Maps JavaScript API has several types of layers:\n\n- The [**Google Maps Data\n layer**](/maps/documentation/javascript/datalayer) provides a container for arbitrary geospatial data. You can use the Data layer to store your custom data, or to display GeoJSON data on a Google map.\n- The [**Heatmap layer**](/maps/documentation/javascript/heatmaplayer) renders geographic data using a *Heatmap* visualization.\n- The [**KML layer**](/maps/documentation/javascript/kmllayer) renders KML and GeoRSS elements into a Maps JavaScript API tile overlay.\n- The [**Traffic layer**](/maps/documentation/javascript/trafficlayer#traffic_layer) displays traffic conditions on the map.\n- The [**Transit layer**](/maps/documentation/javascript/trafficlayer#transit_layer) displays the public transport network of your city on the map.\n- The [**Bicycling layer**](/maps/documentation/javascript/trafficlayer#bicycling_layer) object renders a layer of bike paths and/or bicycle-specific overlays into a common layer. This layer is returned by default within the **DirectionsRenderer** when requesting directions of travel mode **BICYCLING**.\n\nAdd a layer\n\nTo add a layer to a map, you only need to call `setMap()`,\npassing it the map object on which to display the layer. Similarly, to hide a\nlayer, call `setMap()`, passing `null`.\n\nThe below snippet centers the map on London, UK, and adds the [Transit\nlayer](/maps/documentation/javascript/trafficlayer#transit_layer). \n\n```javascript\nvar mapOptions = {\n zoom: 13,\n center: new google.maps.LatLng(51.5,-0.11)\n}\n\nvar map = new google.maps.Map(document.getElementById(\"map\"), mapOptions);\n\nvar transitLayer = new google.maps.TransitLayer();\ntransitLayer.setMap(map);\n```"]]