Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
提交 | 用户 | 时间
58d006 1 GMaps.prototype.getFromFusionTables = function(options) {
A 2   var events = options.events;
3
4   delete options.events;
5
6   var fusion_tables_options = options,
7       layer = new google.maps.FusionTablesLayer(fusion_tables_options);
8
9   for (var ev in events) {
10     (function(object, name) {
11       google.maps.event.addListener(object, name, function(e) {
12         events[name].apply(this, [e]);
13       });
14     })(layer, ev);
15   }
16
17   this.layers.push(layer);
18
19   return layer;
20 };
21
22 GMaps.prototype.loadFromFusionTables = function(options) {
23   var layer = this.getFromFusionTables(options);
24   layer.setMap(this.map);
25
26   return layer;
27 };
28
29 GMaps.prototype.getFromKML = function(options) {
30   var url = options.url,
31       events = options.events;
32
33   delete options.url;
34   delete options.events;
35
36   var kml_options = options,
37       layer = new google.maps.KmlLayer(url, kml_options);
38
39   for (var ev in events) {
40     (function(object, name) {
41       google.maps.event.addListener(object, name, function(e) {
42         events[name].apply(this, [e]);
43       });
44     })(layer, ev);
45   }
46
47   this.layers.push(layer);
48
49   return layer;
50 };
51
52 GMaps.prototype.loadFromKML = function(options) {
53   var layer = this.getFromKML(options);
54   layer.setMap(this.map);
55
56   return layer;
57 };
58
59 GMaps.prototype.addLayer = function(layerName, options) {
60   //var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places'];
61   options = options || {};
62   var layer;
63
64   switch(layerName) {
65     case 'weather': this.singleLayers.weather = layer = new google.maps.weather.WeatherLayer();
66       break;
67     case 'clouds': this.singleLayers.clouds = layer = new google.maps.weather.CloudLayer();
68       break;
69     case 'traffic': this.singleLayers.traffic = layer = new google.maps.TrafficLayer();
70       break;
71     case 'transit': this.singleLayers.transit = layer = new google.maps.TransitLayer();
72       break;
73     case 'bicycling': this.singleLayers.bicycling = layer = new google.maps.BicyclingLayer();
74       break;
75     case 'panoramio':
76         this.singleLayers.panoramio = layer = new google.maps.panoramio.PanoramioLayer();
77         layer.setTag(options.filter);
78         delete options.filter;
79
80         //click event
81         if (options.click) {
82           google.maps.event.addListener(layer, 'click', function(event) {
83             options.click(event);
84             delete options.click;
85           });
86         }
87       break;
88       case 'places':
89         this.singleLayers.places = layer = new google.maps.places.PlacesService(this.map);
90
91         //search and  nearbySearch callback, Both are the same
92         if (options.search || options.nearbySearch) {
93           var placeSearchRequest  = {
94             bounds : options.bounds || null,
95             keyword : options.keyword || null,
96             location : options.location || null,
97             name : options.name || null,
98             radius : options.radius || null,
99             rankBy : options.rankBy || null,
100             types : options.types || null
101           };
102
103           if (options.search) {
104             layer.search(placeSearchRequest, options.search);
105           }
106
107           if (options.nearbySearch) {
108             layer.nearbySearch(placeSearchRequest, options.nearbySearch);
109           }
110         }
111
112         //textSearch callback
113         if (options.textSearch) {
114           var textSearchRequest  = {
115             bounds : options.bounds || null,
116             location : options.location || null,
117             query : options.query || null,
118             radius : options.radius || null
119           };
120
121           layer.textSearch(textSearchRequest, options.textSearch);
122         }
123       break;
124   }
125
126   if (layer !== undefined) {
127     if (typeof layer.setOptions == 'function') {
128       layer.setOptions(options);
129     }
130     if (typeof layer.setMap == 'function') {
131       layer.setMap(this.map);
132     }
133
134     return layer;
135   }
136 };
137
138 GMaps.prototype.removeLayer = function(layer) {
139   if (typeof(layer) == "string" && this.singleLayers[layer] !== undefined) {
140      this.singleLayers[layer].setMap(null);
141
142      delete this.singleLayers[layer];
143   }
144   else {
145     for (var i = 0; i < this.layers.length; i++) {
146       if (this.layers[i] === layer) {
147         this.layers[i].setMap(null);
148         this.layers.splice(i, 1);
149
150         break;
151       }
152     }
153   }
154 };