简体   繁体   English

地图叠加层未显示。 如何显示叠加层?

[英]map overlay not showing. How to show overlay?

I am trying to show an overlay on the map but it not showing it. 我正在尝试在地图上显示叠加层,但未显示出来。 I copied this code from official documentation. 我从官方文档中复制了此代码。 What wrong going here. 这怎么了 How can I resolve this issue? 我该如何解决这个问题? Is this code refreshing map once overlay is assigned? 分配叠加层后,此代码是否会刷新地图? Is this code drawing an overlay on the map? 该代码是否在地图上绘制覆盖图?

Code: 码:

 var overlay; function initMap() { USGSOverlay.prototype = new google.maps.OverlayView(); var map = new google.maps.Map(document.getElementById('map'), { zoom: 20, mapTypeId: google.maps.MapTypeId.ROADMAP, zoomControl: false, mapTypeControl: false, scaleControl: false, panControl: false, navigationControl: false, streetViewControl: false, gestureHandling: 'cooperative', }); var bounds = new google.maps.LatLngBounds( new google.maps.LatLng(62.281819, -150.287132), new google.maps.LatLng(62.400471, -150.005608) ); var srcImage = 'https://developers.google.com/maps/documentation/' + 'javascript/examples/full/images/talkeetna.png'; overlay = new USGSOverlay(bounds, srcImage, map); } function USGSOverlay(bounds, image, map) { this.bounds_ = bounds; this.image_ = image; this.map_ = map; this.div_ = null; this.setMap(map); } USGSOverlay.prototype.onAdd = function() { var div = document.createElement('div'); div.style.borderStyle = 'none'; div.style.borderWidth = '0px'; div.style.position = 'absolute'; var img = document.createElement('img'); img.src = this.image_; img.style.width = '100%'; img.style.height = '100%'; img.style.position = 'absolute'; div.appendChild(img); this.div_ = div; var panes = this.getPanes(); panes.overlayLayer.appendChild(div); } USGSOverlay.prototype.draw = function() { var overlayProjection = this.getProjection(); var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest()); var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast()); var div = this.div_; div.style.left = sw.x + 'px'; div.style.top = ne.y + 'px'; div.style.width = (ne.x - sw.x) + 'px'; div.style.height = (sw.y - ne.y) + 'px'; } USGSOverlay.prototype.onRemove = function() { this.div_.parentNode.removeChild(this.div_); this.div_ = null; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/gmaps.js/0.4.25/gmaps.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="map" data-map-zoom="9"></div> 

Error: 错误:

this.setMap is not a function this.setMap不是函数

Live Demo: 现场演示:

https://www.vsss.co.in/Right/ https://www.vsss.co.in/Right/

You missed this part on the top : 您在顶部错过了这一部分:

      var overlay;
      USGSOverlay.prototype = new google.maps.OverlayView();

this will give you setMap and other functions from OverlayView 这将为您提供setMap和其他OverlayView函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM