Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. (function(window){
  2. function CustomMarker(__settings__) {
  3. "use strict";
  4. this.latlng = __settings__.latlng;
  5. this.args = __settings__.args;
  6. this.template = __settings__.template;
  7. this.setMap(__settings__.map);
  8. this.width = checkSize(__settings__.width);
  9. this.height = checkSize(__settings__.height);
  10. this.callBackClickListener = __settings__.callBackClickListener
  11. }
  12.  
  13. function checkSize (__val__){
  14. return (!String(__val__).indexOf('px') !== -1) ? String(__val__+"px") : __val__;
  15. }
  16.  
  17. CustomMarker.prototype = new google.maps.OverlayView();
  18.  
  19. CustomMarker.prototype.draw = function() {
  20.  
  21. var self = this;
  22.  
  23. var div = this.div;
  24.  
  25. if (!div) {
  26.  
  27. div = this.div = document.createElement('div');
  28.  
  29. div.className = 'custom_marker_item';
  30.  
  31. div.style.position = 'absolute';
  32. div.style.cursor = 'pointer';
  33. div.style.width = this.width ;
  34. div.style.height = this.height;
  35.  
  36. if(this.args.zIndex){
  37. div.style.zIndex = this.args.zIndex;
  38. }
  39.  
  40. if(!this.template){
  41. div.style.background = 'blue';
  42. }else{
  43. div.innerHTML = this.template;
  44. }
  45.  
  46. if (typeof(self.args.marker_id) !== 'undefined') {
  47. div.dataset.marker_id = self.args.marker_id;
  48. }
  49.  
  50. var self = this;
  51.  
  52. google.maps.event.addDomListener(div, "click", function(event) {
  53. google.maps.event.trigger(self, "click");
  54.  
  55. // function name and parameters to pass
  56. var fnc = self.callBackClickListener;
  57. var fnparams = [self];
  58.  
  59. // find object
  60. fnc.apply(null, fnparams);
  61.  
  62. });
  63.  
  64. var panes = this.getPanes();
  65.  
  66. panes.overlayImage.appendChild(div);
  67. }
  68.  
  69. var point = this.getProjection().fromLatLngToDivPixel(this.latlng);
  70.  
  71. if (point) {
  72. var moveTop = (this.args.top) ? this.args.top : 0;
  73. var moveLeft = (this.args.left) ? this.args.left : 0;
  74. div.style.left = (point.x - moveLeft ) + 'px';
  75. div.style.top = (point.y - moveTop) + 'px';
  76. }
  77. };
  78.  
  79. CustomMarker.prototype.remove = function() {
  80. if (this.div) {
  81. this.div.parentNode.removeChild(this.div);
  82. this.div = null;
  83. }
  84. };
  85.  
  86. CustomMarker.prototype.getPosition = function() {
  87. return this.latlng;
  88. };
  89.  
  90. window.CustomMarker = CustomMarker;
  91.  
  92. }(window));
  93.  
  94.  
  95. var template = $('#template-icon-maps').html();
  96.  
  97. var dataMarker = {
  98. latlng:myPosition,
  99. map:myMas,
  100. args:{
  101. marker_id: myId,
  102. left: 16,
  103. top: 32,
  104. zIndex: myIndex
  105. },
  106. template:html,
  107. width: 32,
  108. height:32,
  109. callBackClickListener: myCallbackFunction
  110. };
  111.  
  112. var overlay = new CustomMarker(dataMarker);
  113.  
  114. function myCallbackFunction (__args__){
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement