source: extensions/GMaps/js/gmapsPicture.js @ 7479

Last change on this file since 7479 was 7479, checked in by grum, 14 years ago

implement feature:1950

File size: 6.8 KB
Line 
1/**
2 * -----------------------------------------------------------------------------
3 * file: gmapsPicture.js
4 * file version: 1.1.0
5 * date: 2010-10-20
6 */
7
8
9var viewportInitialized = {
10  icon:false,
11  meta:false
12};
13var markerImgProp = [
14  null,
15  { w:32, h:32, x:15, y:31 }, // s01
16  { w:32, h:32, x:15, y:31 }, // s02
17  { w:32, h:32, x:10, y:31 }, // s03
18  { w:30, h:40, x:4, y:39 }, // s04
19];
20
21
22function applyMap(properties)
23{
24  var latlng=new google.maps.LatLng(gmaps.coords.latitude, gmaps.coords.longitude),
25      map = new google.maps.Map($("#"+properties.id).get(0),
26              {
27                mapTypeId: properties.mapType,
28                zoom: properties.zoomLevel,
29                center:latlng,
30                navigationControl: (properties.navigationControl==-1)?false:true,
31                scrollwheel: (properties.navigationControl==-1)?false:true,
32                scaleControl: (properties.scaleControl=='n')?false:true,
33                streetViewControl: (properties.streetViewControl=='n')?false:true,
34                mapTypeControl:(properties.mapTypeControl==-1)?false:true,
35                mapTypeControlOptions:
36                  {
37                    style:properties.mapTypeControl
38                  },
39                markerTitle:'',
40              }
41            ),
42      marker = null;
43
44  if(gmaps.geolocated)
45  {
46    marker= new google.maps.Marker(
47      {
48        position:latlng,
49        map: map,
50        title:properties.markerTitle
51      }
52    );
53  }
54
55  re=/^mS(\d\d)_.*/i;
56  iM=re.exec(properties.markerImg);
57  if(iM!=null) iM=new Number(iM[1]);
58
59  if(iM!=null && marker!=null)
60  {
61    var markerImg = new google.maps.MarkerImage('plugins/GMaps/img/'+properties.markerImg,
62        new google.maps.Size(markerImgProp[iM].w, markerImgProp[iM].h),
63        new google.maps.Point(0,0),
64        new google.maps.Point(markerImgProp[iM].x, markerImgProp[iM].y));
65    marker.setIcon(markerImg);
66  }
67
68
69
70
71
72  if(properties.kmlFileUrl!='')
73  {
74    kmlFile = new google.maps.KmlLayer(properties.kmlFileUrl,
75      {
76        preserveViewport:true
77      }
78    );
79  }
80  else
81  {
82    kmlFile=null;
83  }
84
85  map.kmlFile=kmlFile;
86
87
88  properties.gMap=map;
89  properties.gMapCenter=latlng;
90}
91
92/**
93 * if picture is geolocated, center map on geolocation
94 * otherwise, try to center on the kml file (by fitting bounds)
95 */
96function centerMap(map)
97{
98  if(gmaps.geolocated)
99  {
100    map.gMap.setCenter(map.gMapCenter);
101  }
102  else
103  {
104    fitKmlBounds(map);
105  }
106}
107
108/**
109 * if map have a kml file, fit to kml bounds
110 */
111function fitKmlBounds(map)
112{
113  if(map.gMap!=null) map.gMap.fitBounds(map.gMap.kmlFile.getDefaultViewport());
114}
115
116$(window).load(function ()
117  {
118    gmaps.currentMapLoadIndex=-1;
119
120    for(i=0;i<gmaps.maps.length;i++)
121    {
122      applyMap(gmaps.maps[i]);
123      gmaps.maps[i].gMap.setCenter(gmaps.maps[i].gMapCenter);
124      $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
125
126      if(gmaps.maps[i].gMap.kmlFile!=null)
127        gmaps.maps[i].gMap.kmlFile.setMap(gmaps.maps[i].gMap);
128
129      if(gmaps.maps[i].displayType=='IP')
130      {
131        gmaps.currentMapLoadIndex=i;
132        if(gmaps.maps[i].sizeMode=='A')
133        {
134          $('#iGMapsIcon').css(
135            {
136              width: ($(window).width()*gmaps.popupAutomaticSize)+'px',
137              height:($(window).height()*gmaps.popupAutomaticSize)+'px'
138            }
139          );
140        }
141      }
142    }
143
144    /*
145     * this trick is needed for the gally template, because the map initialisation
146     *  don't works if the container is not visible
147     *
148     * for the classic default template, this code is ignored
149     *
150     * >>>
151     */
152    if($('#iGMapContent').length>0)
153    {
154      tabId=$('#iGMapContent').get(0).parentNode.parentNode.id;
155      tabId='tab'+tabId.toUpperCase().substring(0,1)+tabId.substr(1);
156      $("#"+tabId+" a").bind('click', function ()
157        {
158          if(viewportInitialized.meta==false)
159          {
160            for(i=0;i<gmaps.maps.length;i++)
161            {
162              if(gmaps.maps[i].displayType=='MP')
163              {
164                google.maps.event.trigger(gmaps.maps[i].gMap, 'resize');
165                centerMap(gmaps.maps[i]);
166                $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
167              }
168            }
169            viewportInitialized.meta=true;
170          }
171        }
172      );
173    }
174    /*
175     * <<<
176     */
177
178
179    /*
180     * manage the popup map
181     */
182    if($('#iGMapsIconContent').length>0)
183    {
184      $('#iGMapsIconContent').dialog(
185        {
186          autoOpen:false,
187          width:'auto',
188          height:'auto',
189          modal: true,
190          closeText:'X',
191          dialogClass: 'gmapsPopup',
192          title: gmaps.maps[gmaps.currentMapLoadIndex].title,
193          open: function ()
194            {
195              if(viewportInitialized.icon==false && gmaps.currentMapLoadIndex!=-1)
196              {
197                if(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile!=null)
198                  gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.setMap(gmaps.maps[gmaps.currentMapLoadIndex].gMap);
199
200                google.maps.event.trigger(gmaps.maps[gmaps.currentMapLoadIndex].gMap, 'resize');
201                centerMap(gmaps.maps[gmaps.currentMapLoadIndex]);
202                $('#iGMapsIcon span, #iGMapsIcon a').css('font-size', '55.0%');
203                viewportInitialized.icon=true;
204              }
205
206              google.maps.event.addListener(
207                gmaps.maps[gmaps.currentMapLoadIndex].gMap,
208                'dragend',
209                function()
210                {
211                  $('#gmapsCenterMap').css('display', 'inline');
212                  $('#gmapsBoundKml').css('display', 'inline');
213                }
214              );
215
216              google.maps.event.addListener(
217                gmaps.maps[gmaps.currentMapLoadIndex].gMap,
218                'zoom_changed',
219                function()
220                {
221                  $('#gmapsCenterMap').css('display', 'inline');
222                  $('#gmapsBoundKml').css('display', 'inline');
223                }
224              );
225            }
226        }
227      );
228
229      if(gmaps.geolocated)
230      {
231        $('div.gmapsPopup div.ui-dialog-titlebar')
232        .append('<a href="#" id="gmapsCenterMap" style="display:none;" onclick="centerMap(gmaps.maps[gmaps.currentMapLoadIndex]); $(this).css(\'display\', \'none\').blur(); return(false);">'+
233                '<span>&bull;</span></a>');
234        $('#gmapsCenterMap').attr('title', gmaps.lang.centermap);
235      }
236
237      if(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile!=null)
238      {
239        $('div.gmapsPopup div.ui-dialog-titlebar')
240          .append('<a href="#" id="gmapsBoundKml" onclick="fitKmlBounds(gmaps.maps[gmaps.currentMapLoadIndex]); $(this).css(\'display\', \'none\').blur(); return(false);">'+
241                  '<span>&sim;</span></a>');
242        $('#gmapsBoundKml').attr('title', gmaps.lang.boundkml);
243      }
244
245
246    }
247
248
249  }
250);
251
252
Note: See TracBrowser for help on using the repository browser.