Google 地圖提供了設定 InfoWindows 樣式的有限指南。本文探討了自訂這些元素的技術。
您可以使用 InfoBubble(InfoWindow 的替代方案)實作許多樣式選項。
infoBubble = new InfoBubble({ map: map, content: '<div class="mylabel">The label</div>', position: new google.maps.LatLng(-32.0, 149.0), shadowStyle: 1, padding: 0, backgroundColor: 'rgb(57,57,57)', borderRadius: 5, arrowSize: 10, borderWidth: 1, borderColor: '#2c2c2c', disableAutoPan: true, hideCloseButton: true, arrowPosition: 30, backgroundClassName: 'transparent', arrowStyle: 2 }); infoBubble.open();
此腳本擴充了 GOverlay,創建了更靈活且可自訂的資訊視窗。
/* An InfoBox is like an info window, but it displays * under the marker, opens quicker, and has flexible styling. * @param {GLatLng} latlng Point to place bar at * @param {Map} map The map on which to display this InfoBox. * @param {Object} opts Passes configuration options - content, * offsetVertical, offsetHorizontal, className, height, width */ function InfoBox(opts) { google.maps.OverlayView.call(this); this.latlng_ = opts.latlng; this.map_ = opts.map; this.offsetVertical_ = -195; this.offsetHorizontal_ = 0; this.height_ = 165; this.width_ = 266; var me = this; this.boundsChangedListener_ = google.maps.event.addListener(this.map_, "bounds_changed", function() { return me.panMap.apply(me); }); // Once the properties of this OverlayView are initialized, set its map so // that we can display it. This will trigger calls to panes_changed and // draw. this.setMap(this.map_); }
請注意,在使用資訊視窗自訂時,您可能需要覆寫多個方法。
以上是如何自訂 Google 地圖 InfoWindows 的樣式?的詳細內容。更多資訊請關注PHP中文網其他相關文章!