1/* 2 * Copyright 2011 Anyware Services 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17function GmapViewer() 18{ 19 20 return { 21 22 addMarkers: function() 23 { 24 var me = this; 25 $j.each(this.data.markers, function (idx, elem) { 26 me.addMarker(elem); 27 }); 28 }, 29 30 addMarker: function (record) 31 { 32 $j(this.mapId).gMap("addMarker", { 33 latitude: record.lat, 34 longitude: record.lng, 35 options: { 36 animation: google.maps.Animation.DROP 37 }, 38 icon: { 39 image: this.pinImageUrl(record.icon, record.number, record.letter), 40 iconsize: record.iconSize || [32,37] 41 }, 42 html: this.renderHtmlTooltip(record.title, record.description) 43 }); 44 }, 45 46 addPolygons: function() 47 { 48 var me = this; 49 $j.each(this.data.polygons, function (idx, elem) { 50 me.addPolygon(elem); 51 }); 52 }, 53 54 addPolygon: function (record) 55 { 56 $j(this.mapId).gMap("addPolygon", { 57 points: record.points, 58 options: { 59 fillColor: '#' + record.color, 60 strokeColor: '#' + record.color, 61 html: this.renderHtmlTooltip(record.title, record.description) 62 }, 63 html: this.renderHtmlTooltip(record.title, record.description) 64 }); 65 }, 66 67 renderHtmlTooltip: function(title, desc) 68 { 69 return '<div class="infowindow"><span class="title">'+ title +'</span>' 70 + '<p class="description">'+ (desc || '') +'</p>' 71 + '</div>'; 72 }, 73 74 pinImageUrl: function (icon, number, letter) 75 { 76 var url = ''; 77 if (letter) 78 { 79 url = this.data.iconBase + 'letter/' + letter + '.png'; 80 } 81 else if (number) 82 { 83 url = this.data.iconBase + 'number/' + number + '.png'; 84 } 85 else 86 { 87 url = this.data.iconBase + icon + '.png'; 88 } 89 return url; 90 }, 91 92 setUp: function (mapIdentifier, gdata, fitbounds) 93 { 94 this.mapId = mapIdentifier; 95 this.data = gdata; 96 this.enableFitbounds = !!fitbounds; 97 98 if (this.data && this.mapId) 99 { 100 if (this.gmap) 101 { 102 $j(this.mapId).gMap("removeAllMarkers"); 103 $j(this.mapId).gMap("removeAllPolygons"); 104 } 105 106 this.prepareFitbounds(); 107 this.gmap = this.initMap(this.data.lat, this.data.lng, this.data.zoomLevel, this.data.mapTypeId); 108 109 this.fitbounds(); 110 this.addMarkers(); 111 this.addPolygons(); 112 } 113 }, 114 115 initMap: function (lat, lng, zoomLevel, mapTypeId) 116 { 117 if (!this.mapId) return; 118 119 var latitude = lat; 120 var longitude = lng; 121 var c; 122 123 if (this.enableFitbounds && this.boundCount > 0) 124 { 125 c = this.bounds.getCenter(); 126 latitude = c.lat(); 127 longitude = c.lng(); 128 } 129 130// if (!this.gmap) 131// { 132// console.log('???'); 133 134 return $j(this.mapId).gMap({ 135 latitude: latitude, 136 longitude: longitude, 137 zoom:zoomLevel, 138 maptype:mapTypeId, 139 mapTypeControl:true, 140 zoomControl:true, 141 panControl:true, 142 streetViewControl:false 143 }); 144// } 145// else 146// { 147// // do re-init... 148// // set center + zoomlevel 149// console.log('reinit map!!'); 150// return this.gmap; 151// } 152 }, 153 154 prepareFitbounds: function() 155 { 156 if (!this.enableFitbounds) 157 { 158 return; 159 } 160 161 this.bounds = new google.maps.LatLngBounds(); 162 this.boundCount = 0; 163 164 var me = this; 165 166 // markers 167 $j.each(this.data.markers, function (idx, elem) { 168 me.bounds.extend(new google.maps.LatLng(elem.lat, elem.lng)); 169 me.boundCount++; 170 }); 171 172 // polygons 173 var p, pl, pi; 174 $j.each(this.data.polygons, function (idx, elem) { 175 p = elem.points; 176 pl = p ? p.length : 0; 177 178 if (p) 179 { 180 for (var i = 0; i < pl; i++) 181 { 182 pi = p[i]; 183 this.bounds.extend(new google.maps.LatLng(pi.lat, pi.lng)); 184 this.boundCount++; 185 } 186 } 187 }); 188 }, 189 190 fitbounds: function() 191 { 192 if (this.enableFitbounds && this.boundCount >= 2) 193 { 194 this.gmap.data('$gmap').fitBounds(this.bounds); 195 } 196 } 197 } 198};
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.