| 153 | * 關於 G_MAP = new RedcliffMap(); 這行程式 |
| 154 | {{{ |
| 155 | #!js |
| 156 | |
| 157 | # 首先要看的是 RedcliffMap 這個類別物件的建構子(Constructor) |
| 158 | |
| 159 | RedcliffMap.prototype = { |
| 160 | changeTiles: function(opacity_val) { |
| 161 | // IE6 does not support opacity, so we remove the layer if opacity is 0 |
| 162 | if (this.tileLayerOverlay != null) { |
| 163 | this.gmap.removeOverlay(this.tileLayerOverlay); |
| 164 | } |
| 165 | if (opacity_val < 0.01) { |
| 166 | this.tileLayerOverlay = null; |
| 167 | } else { |
| 168 | this.tileLayerOverlay = new GTileLayerOverlay( |
| 169 | new GTileLayer(null, null, null, { |
| 170 | tileUrlTemplate: URL.tile_url, |
| 171 | isPng:true, |
| 172 | opacity:opacity_val |
| 173 | }) |
| 174 | ); |
| 175 | this.gmap.addOverlay(this.tileLayerOverlay); |
| 176 | } |
| 177 | }, |
| 178 | addOverlay: function(overlay) { |
| 179 | this.gmap.addOverlay(overlay); |
| 180 | }, |
| 181 | removeOverlay: function(overlay) { |
| 182 | this.gmap.removeOverlay(overlay); |
| 183 | }, |
| 184 | openInfoWindow: function(type, id, latlng) { |
| 185 | if (type == "EVENT") { |
| 186 | var event = EVENT.getItem(id); |
| 187 | var info_div = Utils.constructInfoWindowHtml([event]); |
| 188 | this.gmap.openInfoWindowHtml(latlng, info_div); |
| 189 | //this.highLightOverlay(event.element_ids); |
| 190 | } |
| 191 | if (type == "ELEMENT") { |
| 192 | var element = ELEMENT.getItem(id); |
| 193 | var events = new Array(); |
| 194 | $.each(element.events, function(index, event_id) { |
| 195 | if (CURRENT_EVENT_HASH.hasItem(event_id)) { |
| 196 | var event = EVENT.getItem(event_id); |
| 197 | events.push(event); |
| 198 | } |
| 199 | }); |
| 200 | if (events.length > 1) { |
| 201 | var info_tabs = Utils.constructInfoWindowTabsHtml(events); |
| 202 | this.gmap.openInfoWindowTabsHtml(latlng, info_tabs); |
| 203 | } else { |
| 204 | var info_div = Utils.constructInfoWindowHtml(events); |
| 205 | this.gmap.openInfoWindowHtml(latlng, info_div); |
| 206 | } |
| 207 | //this.highLightOverlay(id); |
| 208 | } |
| 209 | }, |
| 210 | highLightOverlay: function(element_ids) { |
| 211 | $.each(element_ids, function(index, element_id) { |
| 212 | if (CURRENT_ELEMENT_HASH.hasItem(element_id)) { |
| 213 | var element = ELEMENT.getItem(element_id); |
| 214 | element.highLight(); |
| 215 | HIGH_LIGHT_ELEMENT.push(element_id); |
| 216 | } |
| 217 | }); |
| 218 | }, |
| 219 | |
| 220 | deHighLightOverlay: function() { |
| 221 | while (HIGH_LIGHT_ELEMENT.length > 0) { |
| 222 | var element_id = HIGH_LIGHT_ELEMENT.pop(); |
| 223 | var element = ELEMENT.getItem(element_id); |
| 224 | //element.deHighLight(); |
| 225 | } |
| 226 | }, |
| 227 | |
| 228 | setCenter: function(center, level) { |
| 229 | this.gmap.panTo(center); |
| 230 | }, |
| 231 | |
| 232 | clearOverlays: function() { |
| 233 | this.gmap.closeInfoWindow(); |
| 234 | while (CURRENT_ELEMENT.length > 0) { |
| 235 | var element_id = CURRENT_ELEMENT.pop(); |
| 236 | var elem = ELEMENT.getItem(element_id); |
| 237 | CURRENT_ELEMENT_HASH.removeItem(element_id); |
| 238 | elem.removeFromMap(); |
| 239 | } |
| 240 | |
| 241 | while (CURRENT_EVENT.length > 0) { |
| 242 | var event_id = CURRENT_EVENT.pop(); |
| 243 | CURRENT_EVENT_HASH.removeItem(element_id); |
| 244 | } |
| 245 | CURRENT_OVERLAY_ID = ""; |
| 246 | }, |
| 247 | |
| 248 | updateOverlay: function(type, id) { |
| 249 | if (type + '_' + id == CURRENT_OVERLAY_ID) |
| 250 | return; |
| 251 | CURRENT_OVERLAY_ID = type + '_' + id; |
| 252 | this.clearOverlays(); |
| 253 | |
| 254 | var element_ids; |
| 255 | var event_ids; |
| 256 | if (type == 'E') { |
| 257 | var big_event = BIG_EVENT.getItem(id); |
| 258 | element_ids = big_event.element_ids; |
| 259 | event_ids = big_event.event_ids; |
| 260 | } else { |
| 261 | var people = PEOPLE.getItem(id); |
| 262 | element_ids = people.element_ids; |
| 263 | event_ids = people.event_ids; |
| 264 | } |
| 265 | |
| 266 | $.each(element_ids, function(index, element_id) { |
| 267 | var elem = ELEMENT.getItem(element_id); |
| 268 | elem.drawOnMap(); |
| 269 | CURRENT_ELEMENT.push(element_id); |
| 270 | CURRENT_ELEMENT_HASH.setItem(element_id, ""); |
| 271 | }); |
| 272 | |
| 273 | $.each(event_ids, function(index, event_id) { |
| 274 | CURRENT_EVENT.push(event_id); |
| 275 | CURRENT_EVENT_HASH.setItem(event_id, ""); |
| 276 | }); |
| 277 | } |
| 278 | }; |
| 279 | |
| 280 | function RedcliffMap(node) { |
| 281 | var me = this; |
| 282 | |
| 283 | # 參考 http://code.google.com/intl/zh-TW/apis/maps/documentation/mapplets/basics.html#GMap2 |
| 284 | # GMap2 代表 Google Map 的 map 根元件 |
| 285 | this.gmap = new GMap2(); |
| 286 | |
| 287 | # 設定初始地圖中心經緯度位置 |
| 288 | this.gmap.setCenter(new GLatLng(29.833, 113.618), 7, G_PHYSICAL_MAP); |
| 289 | |
| 290 | # 用 GTileLayerOverlay 來取代原始的地圖底圖 |
| 291 | # 參考 http://code.google.com/intl/zh-TW/apis/maps/documentation/overlays.html#Tile_Overlays |
| 292 | # 參考 http://code.google.com/intl/zh-TW/apis/maps/documentation/reference.html#GTileLayerOverlay |
| 293 | # 建構子定義 GTileLayerOverlay(tileLayer:GTileLayer, opts?:GTileLayerOverlayOptions) |
| 294 | |
| 295 | this.tileLayerOverlay = new GTileLayerOverlay( |
| 296 | |
| 297 | # 參考 http://code.google.com/intl/zh-TW/apis/maps/documentation/reference.html#GTileLayer |
| 298 | # 建構子定義 GTileLayer(copyrights:GCopyrightCollection, minResolution:Number, |
| 299 | # maxResolution:Number, options?:GTileLayerOptions) |
| 300 | # 參考 http://code.google.com/intl/zh-TW/apis/maps/documentation/reference.html#GTileLayerOptions |
| 301 | # 這裡設定 tileUrlTemplate: URL.tile_url = http://mt.google.cn/mt?v=cnsg1.2&hl=zh-CN&x={X}&y={Y}&z={Z} |
| 302 | # 根據 API 文件 Templates 必須是這樣: http://host/tile?x={X}&y={Y}&z={Z}.png |
| 303 | |
| 304 | new GTileLayer(null, null, null, { |
| 305 | tileUrlTemplate: URL.tile_url, |
| 306 | isPng:true, |
| 307 | opacity:1.0 |
| 308 | }) |
| 309 | ); |
| 310 | this.gmap.addOverlay(this.tileLayerOverlay); |
| 311 | }; |
| 312 | }}} |