1/* 2 * AxGmap version 1.2.1 3 * (jQuery plugin) 4 * 5 * URL : https://github.com/Nouris-Inc/jquery-axgmap/ 6 * Author : tsaeki (http://nouris.jp/) 7 * Copyright : copyright (c) 2015 Nouris Inc. 8 * License : licensed under the MIT licenses. 9 */ 10 11;(function($, window, document, undefined) { 12 13 var AxGmap = function (element){ 14 this.element = $(element); 15 this.gmap; 16 this.markers = []; 17 this.infoWindows = []; 18 this.init(); 19 } 20 21 AxGmap.prototype = { 22 init: function (){ 23 this.createGmap(); 24 this.fin(); 25 }, 26 createGmap: function(){ 27 var options = this.createGmapOption(); 28 var children = this.element.children(); 29 this.gmap = new google.maps.Map(this.element[0], options); 30 this.createMarker(children); 31 this.showMapStatus(); 32 }, 33 createMarker: function(elements){ 34 var self = this; 35 var openWindowSet = null; 36 elements.each(function(index){ 37 var element = $(this); 38 var windowOpen = false; 39 var options = self.createMarkerOption(element); 40 if (options.windowOpen) { 41 windowOpen = true; 42 delete options.windowOpen; 43 } 44 var marker = new google.maps.Marker(options); 45 self.markers.push(marker); 46 var content = element.html().trim(); 47 if (content.length) { 48 var infoWindowSet = self.createInfoWindowSet(content, marker); 49 self.infoWindows.push(infoWindowSet); 50 if (windowOpen) { 51 openWindowSet = infoWindowSet; 52 }; 53 } 54 }); 55 if (openWindowSet) { 56 self.openInfoWindow(openWindowSet); 57 }; 58 }, 59 createInfoWindowSet: function(content, marker){ 60 var self = this; 61 var infoWindow = new google.maps.InfoWindow({content: content}); 62 google.maps.event.addListener(marker, 'click', function(){ 63 self.openInfoWindow({'infoWindow':infoWindow, 'marker':marker}); 64 }); 65 return {'infoWindow':infoWindow, 'marker':marker}; 66 }, 67 createLatLng: function(element){ 68 var lat = 0; 69 var lng = 0; 70 var latlng = element.data('latlng') ? element.data('latlng') : this.element.data('latlng'); 71 if (latlng) { 72 var split = latlng.split(','); 73 lat = this.parseNum(split[0].trim()); 74 lng = this.parseNum(split[1].trim()); 75 }; 76 return new google.maps.LatLng(lat, lng); 77 }, 78 createGmapOption: function(){ 79 var self = this; 80 var options = { 81 center: this.createLatLng(this.element), 82 zoom: 9 83 }; 84 if (this.element.data("mapType")) { 85 var mapType = this.element.data("mapType").toUpperCase(); 86 $.extend(options, {'mapTypeId': google.maps.MapTypeId[mapType]}); 87 }; 88 if (this.element.data("mapWidth") != null) { 89 this.element.width(this.element.data("mapWidth")); 90 }; 91 if (this.element.data("mapHeight") != null) { 92 this.element.height(this.element.data("mapHeight")); 93 }; 94 var properties = ["zoom", "draggable", "scrollwheel", "maxZoom", "minZoom", "mapTypeControl", "overviewMapControl", "panControl", "rotateControl", "scaleControl", "streetViewControl", "zoomControl"]; 95 $.each(properties, function(index, property){ 96 if (self.element.data(property) != null) { 97 options[property] = self.element.data(property); 98 } 99 }); 100 return options; 101 }, 102 createMarkerOption: function(element){ 103 var options = { 104 map: this.gmap, 105 position: this.createLatLng(element) 106 }; 107 if (element.data('title') != null) { 108 options['title'] = element.data('title'); 109 } 110 if (element.data('markerImage') != null) { 111 options['icon'] = element.data('markerImage'); 112 } 113 if (element.data('windowOpen')) { 114 options['windowOpen'] = true; 115 } 116 return options; 117 }, 118 openInfoWindow: function(infoWindowSet){ 119 var self = this; 120 infoWindowSet.infoWindow.open(self.gmap, infoWindowSet.marker); 121 $.each(self.infoWindows, function(index, val){ 122 if(val.infoWindow != infoWindowSet.infoWindow){ 123 val.infoWindow.close(); 124 } 125 }); 126 }, 127 parseNum: function(val){ 128 return (typeof val == null) ? 0.0 : parseFloat(val); 129 }, 130 showMapStatus: function(){ 131 var self = this; 132 if (!this.element.data("mapStatus")) { 133 return; 134 }; 135 var status = $('<div style="color:#000; background-color:#fff; border:solid 1px #ccc; width:' + self.element.width() + 'px"><dl style="margin:1em;"><dt>Center LatLng</dt><dd class="axgmap-status-latlng"></dd><dt>Zoom</dt><dd class="axgmap-status-zoom"></dd><dt>Right Click LatLng</dt><dd class="axgmap-status-rightclick">none</dd></dl></div>'); 136 status.insertAfter(this.element); 137 google.maps.event.addListener(this.gmap, 'idle', function(){ 138 $('.axgmap-status-latlng', status).empty().append(self.gmap.getCenter().lat().toFixed(6) + ', ' + self.gmap.getCenter().lng().toFixed(6)); 139 $('.axgmap-status-zoom', status).empty().append(self.gmap.getZoom()); 140 }); 141 google.maps.event.addListener(this.gmap, 'rightclick', function(event){ 142 $('.axgmap-status-rightclick', status).empty().append(event.latLng.lat().toFixed(6) + ', ' + event.latLng.lng().toFixed(6)); 143 }); 144 }, 145 fin: function(){ 146 if (!AxGmap.didCreated) { 147 AxGmap.didCreated = true; 148 $('<style>.gm-style img{max-width:inherit;}</style>').appendTo('head'); 149 }; 150 } 151 }; 152 153 $.fn.axgmap = function(){ 154 return this.each(function(){ 155 if(!$.data(this, 'AxGmap')){ 156 $.data(this, 'AxGmap', new AxGmap(this)); 157 } 158 }); 159 }; 160 161 $(function() { 162 $('.axgmap').axgmap(); 163 }); 164 165})(jQuery, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.