| 259 | * 從 Element 的 prototype 跟建構子看來,Element 類別包含 id, element, type, event 四個 field,getHiddenPolylineOverlay(points, weigth, id)、getArrowGroundOverlay(arrow_url, sw, ne)、getMarker(icon_url, point, id) 三個暫時的 inner function,drawOnMap()、removeFromMap()兩個 method (其他被註解掉了) |
| 260 | {{{ |
| 261 | function Element(raw_element) { |
| 262 | var me = this; |
| 263 | this.id = raw_element.id |
| 264 | this.element = raw_element; |
| 265 | this.type = raw_element.type; |
| 266 | |
| 267 | var getHiddenPolylineOverlay = function(points, weigth, id) { |
| 268 | var latlngs = new Array(); |
| 269 | $.each(points, function(index, point){ |
| 270 | latlngs.push(new GLatLng(point.lat, point.lng)); |
| 271 | }); |
| 272 | var polyline = new GPolygon(latlngs, "#000000", 10, 0.0); |
| 273 | GEvent.addListener(polyline, 'click', function(latlng) { |
| 274 | G_MAP.openInfoWindow("ELEMENT", id, latlng); |
| 275 | }); |
| 276 | return polyline; |
| 277 | }; |
| 278 | |
| 279 | var getArrowGroundOverlay = function(arrow_url, sw, ne) { |
| 280 | var bound = new GLatLngBounds(new GLatLng(ne.lat, ne.lng), new GLatLng(sw.lat, sw.lng)); |
| 281 | var arrow = new GGroundOverlay(CN_BASE + 'arrow/' + arrow_url + '.png', bound); |
| 282 | return arrow; |
| 283 | } |
| 284 | |
| 285 | var getMarker = function(icon_url, point, id) { |
| 286 | var image = CN_BASE + 'icon/' + icon_url + '.png'; |
| 287 | var icon = new GIcon(G_DEFAULT_ICON, image); |
| 288 | if (icon_url.length == 2) |
| 289 | icon.iconSize = new GSize(45,32); |
| 290 | else |
| 291 | icon.iconSize = new GSize(25,32); |
| 292 | var marker = new GMarker(point, {icon:icon}); |
| 293 | GEvent.addListener(marker, 'click', function() { |
| 294 | G_MAP.openInfoWindow("ELEMENT", id, point); |
| 295 | }); |
| 296 | return marker; |
| 297 | } |
| 298 | if (this.type == 'point') { |
| 299 | this.point = new GLatLng(raw_element.lat, raw_element.lng); |
| 300 | this.marker = getMarker(raw_element.pic, this.point, this.id); |
| 301 | } else { |
| 302 | this.hidden_polyline = getHiddenPolylineOverlay(raw_element.hot_points, C_POLYLINE_WEIGHT, this.id); |
| 303 | this.arrow = getArrowGroundOverlay(raw_element.arrow, raw_element.arrow_points[0], raw_element.arrow_points[1]); |
| 304 | |
| 305 | } |
| 306 | this.events = raw_element.event_ids; |
| 307 | }; |
| 308 | |
| 309 | Element.prototype = { |
| 310 | drawOnMap: function() { |
| 311 | if (this.type == 'line') { |
| 312 | G_MAP.addOverlay(this.hidden_polyline); |
| 313 | G_MAP.addOverlay(this.arrow); |
| 314 | } else { |
| 315 | G_MAP.addOverlay(this.marker); |
| 316 | } |
| 317 | }, |
| 318 | |
| 319 | removeFromMap: function() { |
| 320 | if (this.type == 'line') { |
| 321 | G_MAP.removeOverlay(this.hidden_polyline); |
| 322 | G_MAP.removeOverlay(this.arrow); |
| 323 | } else { |
| 324 | G_MAP.removeOverlay(this.marker); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | highLight: function() { |
| 330 | G_MAP.removeOverlay(this.current_overlay); |
| 331 | G_MAP.addOverlay(this.highlight_overlay); |
| 332 | this.current_overlay = this.highlight_overlay; |
| 333 | }, |
| 334 | |
| 335 | deHighLight: function() { |
| 336 | G_MAP.removeOverlay(this.current_overlay); |
| 337 | G_MAP.addOverlay(this.overlay); |
| 338 | this.current_overlay = this.overlay; |
| 339 | }, |
| 340 | |
| 341 | adjustZoomLevel: function() { |
| 342 | } |
| 343 | */ |
| 344 | }; |
| 345 | }}} |