zoukankan      html  css  js  c++  java
  • gmap

    Google Map Api 添加自定叠加层实现须要实现GOverlay接口,须要实现以下几个方法. •initialize() called in response to GMap2.addOverlay() •remove() called in response to GMap2.removeOverlay() •copy() to allow templating of the new overlay •redraw() called in response to a display change within the map 以下,为实现自定文字标注的例子. 1 function TextOverlay(latLng, html) { 2 this.latLng = latLng; 3 this.html = html; 4 } 5 TextOverlay.prototype = new google.maps.Overlay(); 6 TextOverlay.prototype.initialize = function(map) { 7 var div = document.createElement("div"); 8 div.style.position = "absolute"; 9 div.style.width = "1000px"; 10 div.innerHTML = this.html; 11 map.getPane(G_MAP_MAP_PANE).appendChild(div); 12 this.map_ = map; 13 this.div_ = div; 14 this.redraw(true); 15 } 16 TextOverlay.prototype.remove = function() { 17 this.div_.parentNode.removeChild(this.div_); 18 } 19 TextOverlay.prototype.copy = function() { 20 return new TextOverlay(this.latLng, this.html); 21 } 22 TextOverlay.prototype.redraw = function(force) { 23 if (!force) { 24 return; 25 } 26 var position = this.map_.fromLatLngToDivPixel(this.latLng); 27 this.div_.style.left = position.x + "px"; 28 this.div_.style.top = position.y + "px"; 29 } 30 TextOverlay.prototype.setLatLng = function(latLng) { 31 this.latLng = latLng; 32 this.redraw(true); 33 } 34 TextOverlay.prototype.getLatLng = function() { 35 return this.latLng; 36 } 37 $(function() { 38 var latLng = map.getCenter(); 39 var textOverlay = new TextOverlay(latLng, "我爱你!"); 40 map.addOverlay(textOverlay); 41 });

  • 相关阅读:
    后端结对编程报告(2018.6.6)
    Burn Down Chart(2018.6.4~2018.6.10)
    C#多线程List的非线程安全性
    C#泛型参数多线程与复杂参数多线程
    Java学习之App开发公司手机端设想
    Java学习之SpringBoot整合SSM Demo
    Java学习之Mysql结构优化
    Java学习之Dubbo+ZooKeeper分布式服务Demo
    C# 面向切面编程--监控日志记录方案
    C# 通用类型转换方法
  • 原文地址:https://www.cnblogs.com/rosanshao/p/1830376.html
Copyright © 2011-2022 走看看