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

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

bug:2148 - compatibility with piwigo 2.2
bug:2062 - compatibility with IE7

File size: 6.8 KB
Line 
1/**
2 * -----------------------------------------------------------------------------
3 * file: gmapsPicture.js
4 * file version: 1.1.1
5 * date: 2011-04-21
6 */
7
8
9var viewportInitialized = {
10      icon:false,
11      meta:false
12    },
13    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  if(properties.kmlFileUrl!='')
70  {
71    kmlFile = new google.maps.KmlLayer(properties.kmlFileUrl,
72      {
73        preserveViewport:true
74      }
75    );
76  }
77  else
78  {
79    kmlFile=null;
80  }
81
82  map.kmlFile=kmlFile;
83
84  properties.gMap=map;
85  properties.gMapCenter=latlng;
86}
87
88/**
89 * if picture is geolocated, center map on geolocation
90 * otherwise, try to center on the kml file (by fitting bounds)
91 */
92function centerMap(map)
93{
94  if(gmaps.geolocated)
95  {
96    map.gMap.setCenter(map.gMapCenter);
97  }
98  else
99  {
100    fitKmlBounds(map);
101  }
102}
103
104/**
105 * if map have a kml file, fit to kml bounds
106 */
107function fitKmlBounds(map)
108{
109  if(map.gMap!=null) map.gMap.fitBounds(map.gMap.kmlFile.getDefaultViewport());
110}
111
112$(window).load(function ()
113  {
114    gmaps.popupMapIndex=-1;
115
116    for(i=0;i<gmaps.maps.length;i++)
117    {
118      applyMap(gmaps.maps[i]);
119      gmaps.maps[i].gMap.setCenter(gmaps.maps[i].gMapCenter);
120      $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
121
122      if(gmaps.maps[i].gMap.kmlFile!=null)
123        gmaps.maps[i].gMap.kmlFile.setMap(gmaps.maps[i].gMap);
124
125      if(gmaps.maps[i].displayType=='IP')
126      {
127        gmaps.popupMapIndex=i;
128        if(gmaps.maps[i].sizeMode=='A')
129        {
130          $('#iGMapsIcon').css(
131            {
132              width: ($(window).width()*gmaps.popupAutomaticSize)+'px',
133              height:($(window).height()*gmaps.popupAutomaticSize)+'px'
134            }
135          );
136        }
137      }
138    }
139
140    /*
141     * this trick is needed for the gally template, because the map initialisation
142     *  don't works if the container is not visible
143     *
144     * for the classic default template, this code is ignored
145     *
146     * >>>
147     */
148    if($('#iGMapContent').length>0)
149    {
150      tabId=$('#iGMapContent').get(0).parentNode.parentNode.id;
151      tabId='tab'+tabId.toUpperCase().substring(0,1)+tabId.substr(1);
152      $("#"+tabId+" a").bind('click', function ()
153        {
154          if(viewportInitialized.meta==false)
155          {
156            for(i=0;i<gmaps.maps.length;i++)
157            {
158              if(gmaps.maps[i].displayType=='MP')
159              {
160                google.maps.event.trigger(gmaps.maps[i].gMap, 'resize');
161                centerMap(gmaps.maps[i]);
162                $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
163              }
164            }
165            viewportInitialized.meta=true;
166          }
167        }
168      );
169    }
170    /*
171     * <<<
172     */
173
174
175    /*
176     * manage the popup map
177     */
178    if($('#iGMapsIconContent').length>0)
179    {
180      $('#iGMapsIconContent').dialog(
181        {
182          autoOpen:false,
183          width:$('#iGMapsIcon').width(),
184          height:'auto',
185          modal: true,
186          closeText:'X',
187          dialogClass: 'gmapsPopup',
188          title: gmaps.maps[gmaps.popupMapIndex].title,
189          open: function ()
190            {
191              if(viewportInitialized.icon==false && gmaps.popupMapIndex!=-1)
192              {
193                if(gmaps.maps[gmaps.popupMapIndex].gMap.kmlFile!=null)
194                  gmaps.maps[gmaps.popupMapIndex].gMap.kmlFile.setMap(gmaps.maps[gmaps.popupMapIndex].gMap);
195
196                google.maps.event.trigger(gmaps.maps[gmaps.popupMapIndex].gMap, 'resize');
197                centerMap(gmaps.maps[gmaps.popupMapIndex]);
198                $('#iGMapsIcon span, #iGMapsIcon a').css('font-size', '55.0%');
199                viewportInitialized.icon=true;
200              }
201
202              google.maps.event.addListener(
203                gmaps.maps[gmaps.popupMapIndex].gMap,
204                'dragend',
205                function()
206                {
207                  $('#gmapsCenterMap').css('display', 'inline');
208                  $('#gmapsBoundKml').css('display', 'inline');
209                }
210              );
211
212              google.maps.event.addListener(
213                gmaps.maps[gmaps.popupMapIndex].gMap,
214                'zoom_changed',
215                function()
216                {
217                  $('#gmapsCenterMap').css('display', 'inline');
218                  $('#gmapsBoundKml').css('display', 'inline');
219                }
220              );
221            }
222        }
223      );
224
225      if(gmaps.geolocated)
226      {
227        $('div.gmapsPopup div.ui-dialog-titlebar')
228        .append('<a href="#" id="gmapsCenterMap" style="display:none;" onclick="centerMap(gmaps.maps[gmaps.popupMapIndex]); $(this).css(\'display\', \'none\').blur(); return(false);">'+
229                '<span>&bull;</span></a>');
230        $('#gmapsCenterMap').attr('title', gmaps.lang.centermap);
231      }
232
233      if(gmaps.maps[gmaps.popupMapIndex].gMap.kmlFile!=null)
234      {
235        $('div.gmapsPopup div.ui-dialog-titlebar')
236          .append('<a href="#" id="gmapsBoundKml" onclick="fitKmlBounds(gmaps.maps[gmaps.popupMapIndex]); $(this).css(\'display\', \'none\').blur(); return(false);">'+
237                  '<span>&sim;</span></a>');
238        $('#gmapsBoundKml').attr('title', gmaps.lang.boundkml);
239      }
240    }
241
242  }
243);
244
245
Note: See TracBrowser for help on using the repository browser.