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

Last change on this file since 7308 was 7308, checked in by grum, 13 years ago

fix bug and implement new features
bug:1926, bug:1927, bug:1929, bug:1930, bug:1931, bug:1939, bug:1946

File size: 6.6 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 = new google.maps.Marker(
43                  {
44                    position:latlng,
45                    map: map,
46                    title:properties.markerTitle
47                  }
48                );
49
50
51  re=/^mS(\d\d)_.*/i;
52  iM=re.exec(properties.markerImg);
53  if(iM!=null) iM=new Number(iM[1]);
54
55  if(iM!=null)
56  {
57    var markerImg = new google.maps.MarkerImage('plugins/GMaps/img/'+properties.markerImg,
58        new google.maps.Size(markerImgProp[iM].w, markerImgProp[iM].h),
59        new google.maps.Point(0,0),
60        new google.maps.Point(markerImgProp[iM].x, markerImgProp[iM].y));
61    marker.setIcon(markerImg);
62  }
63
64
65
66
67
68  if(properties.kmlFileUrl!='')
69  {
70    kmlFile = new google.maps.KmlLayer(properties.kmlFileUrl,
71      {
72        preserveViewport:true
73      }
74    );
75  }
76  else
77  {
78    kmlFile=null;
79  }
80
81  map.kmlFile=kmlFile;
82
83
84  properties.gMap=map;
85  properties.gMapCenter=latlng;
86}
87
88$(window).load(function ()
89  {
90    gmaps.currentMapLoadIndex=-1;
91
92    for(i=0;i<gmaps.maps.length;i++)
93    {
94      applyMap(gmaps.maps[i]);
95      gmaps.maps[i].gMap.setCenter(gmaps.maps[i].gMapCenter);
96      $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
97
98      if(gmaps.maps[i].gMap.kmlFile!=null)
99        gmaps.maps[i].gMap.kmlFile.setMap(gmaps.maps[i].gMap);
100
101      if(gmaps.maps[i].displayType=='IP')
102      {
103        gmaps.currentMapLoadIndex=i;
104        if(gmaps.maps[i].sizeMode=='A')
105        {
106          $('#iGMapsIcon').css(
107            {
108              width: ($(window).width()*gmaps.popupAutomaticSize)+'px',
109              height:($(window).height()*gmaps.popupAutomaticSize)+'px'
110            }
111          );
112        }
113      }
114    }
115
116    /*
117     * this trick is needed for the gally template, because the map initialisation
118     *  don't works if the container is not visible
119     *
120     * for the classic default template, this code is ignored
121     *
122     * >>>
123     */
124    if($('#iGMapContent').length>0)
125    {
126      tabId=$('#iGMapContent').get(0).parentNode.parentNode.id;
127      tabId='tab'+tabId.toUpperCase().substring(0,1)+tabId.substr(1);
128      $("#"+tabId+" a").bind('click', function ()
129       {
130          if(viewportInitialized.meta==false)
131          {
132            for(i=0;i<gmaps.maps.length;i++)
133            {
134              if(gmaps.maps[i].displayType=='MP')
135              {
136                google.maps.event.trigger(gmaps.maps[i].gMap, 'resize');
137                gmaps.maps[i].gMap.setCenter(gmaps.maps[1].gMapCenter);
138                $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
139              }
140            }
141            viewportInitialized.meta=true;
142          }
143       }
144      );
145    }
146    /*
147     * <<<
148     */
149
150
151    /*
152     * manage the popup map
153     */
154    if($('#iGMapsIconContent').length>0)
155    {
156      $('#iGMapsIconContent').dialog(
157        {
158          autoOpen:false,
159          width:'auto',
160          height:'auto',
161          modal: true,
162          closeText:'X',
163          dialogClass: 'gmapsPopup',
164          title: gmaps.maps[gmaps.currentMapLoadIndex].title,
165          open: function ()
166            {
167              if(viewportInitialized.icon==false && gmaps.currentMapLoadIndex!=-1)
168              {
169                google.maps.event.trigger(gmaps.maps[gmaps.currentMapLoadIndex].gMap, 'resize');
170                gmaps.maps[gmaps.currentMapLoadIndex].gMap.setCenter(gmaps.maps[gmaps.currentMapLoadIndex].gMapCenter);
171                $('#iGMapsIcon span, #iGMapsIcon a').css('font-size', '55.0%');
172                if(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile!=null)
173                  gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.setMap(gmaps.maps[gmaps.currentMapLoadIndex].gMap);
174                viewportInitialized.icon=true;
175              }
176
177              google.maps.event.addListener(
178                gmaps.maps[gmaps.currentMapLoadIndex].gMap,
179                'dragend',
180                function()
181                {
182                  $('#gmapsCenterMap').css('display', 'inline');
183                  $('#gmapsBoundKml').css('display', 'inline');
184                }
185              );
186
187              google.maps.event.addListener(
188                gmaps.maps[gmaps.currentMapLoadIndex].gMap,
189                'zoom_changed',
190                function()
191                {
192                  $('#gmapsCenterMap').css('display', 'inline');
193                  $('#gmapsBoundKml').css('display', 'inline');
194                }
195              );
196            }
197        }
198      );
199
200      $('div.gmapsPopup div.ui-dialog-titlebar')
201      .append('<a href="#" id="gmapsCenterMap" style="display:none;" onclick="gmaps.maps[gmaps.currentMapLoadIndex].gMap.setCenter(gmaps.maps[gmaps.currentMapLoadIndex].gMapCenter); $(this).css(\'display\', \'none\').blur(); return(false);">'+
202              '<span>&bull;</span></a>');
203      $('#gmapsCenterMap').attr('title', gmaps.lang.centermap);
204
205      if(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile!=null)
206      {
207        $('div.gmapsPopup div.ui-dialog-titlebar')
208          .append('<a href="#" id="gmapsBoundKml" onclick="gmaps.maps[gmaps.currentMapLoadIndex].gMap.fitBounds(gmaps.maps[gmaps.currentMapLoadIndex].gMap.kmlFile.getDefaultViewport()); $(this).css(\'display\', \'none\').blur(); return(false);">'+
209                  '<span>&sim;</span></a>');
210        $('#gmapsBoundKml').attr('title', gmaps.lang.boundkml);
211      }
212
213
214    }
215
216
217  }
218);
219
220
Note: See TracBrowser for help on using the repository browser.