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

Last change on this file since 20354 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
RevLine 
[7176]1/**
2 * -----------------------------------------------------------------------------
3 * file: gmapsPicture.js
[10551]4 * file version: 1.1.1
5 * date: 2011-04-21
[7176]6 */
[7125]7
[7176]8
[7125]9var viewportInitialized = {
[7500]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
[10551]18      { w:30, h:40, x:4, y:39 } // s04
[7500]19    ];
[7125]20
[7139]21
[7125]22function applyMap(properties)
23{
[7176]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,
[7177]33                streetViewControl: (properties.streetViewControl=='n')?false:true,
[7176]34                mapTypeControl:(properties.mapTypeControl==-1)?false:true,
35                mapTypeControlOptions:
36                  {
37                    style:properties.mapTypeControl
38                  },
[10551]39                markerTitle:''
[7176]40              }
41            ),
[7479]42      marker = null;
[7125]43
[7479]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  }
[7125]54
[7139]55  re=/^mS(\d\d)_.*/i;
56  iM=re.exec(properties.markerImg);
57  if(iM!=null) iM=new Number(iM[1]);
58
[7479]59  if(iM!=null && marker!=null)
[7125]60  {
[7139]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);
[7125]66  }
67
[7139]68
[7125]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
[7479]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
[7125]112$(window).load(function ()
113  {
[7500]114    gmaps.popupMapIndex=-1;
[7125]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      {
[7500]127        gmaps.popupMapIndex=i;
[7125]128        if(gmaps.maps[i].sizeMode=='A')
129        {
130          $('#iGMapsIcon').css(
131            {
[7308]132              width: ($(window).width()*gmaps.popupAutomaticSize)+'px',
133              height:($(window).height()*gmaps.popupAutomaticSize)+'px'
[7125]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 ()
[7479]153        {
[7125]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');
[7479]161                centerMap(gmaps.maps[i]);
[7125]162                $('#'+gmaps.maps[i].id+' span, #'+gmaps.maps[i].id+' a').css('font-size', '55.0%');
163              }
164            }
165            viewportInitialized.meta=true;
166          }
[7479]167        }
[7125]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,
[10551]183          width:$('#iGMapsIcon').width(),
[7125]184          height:'auto',
185          modal: true,
186          closeText:'X',
187          dialogClass: 'gmapsPopup',
[7500]188          title: gmaps.maps[gmaps.popupMapIndex].title,
[7125]189          open: function ()
190            {
[7500]191              if(viewportInitialized.icon==false && gmaps.popupMapIndex!=-1)
[7125]192              {
[7500]193                if(gmaps.maps[gmaps.popupMapIndex].gMap.kmlFile!=null)
194                  gmaps.maps[gmaps.popupMapIndex].gMap.kmlFile.setMap(gmaps.maps[gmaps.popupMapIndex].gMap);
[7479]195
[7500]196                google.maps.event.trigger(gmaps.maps[gmaps.popupMapIndex].gMap, 'resize');
197                centerMap(gmaps.maps[gmaps.popupMapIndex]);
[7125]198                $('#iGMapsIcon span, #iGMapsIcon a').css('font-size', '55.0%');
199                viewportInitialized.icon=true;
200              }
201
202              google.maps.event.addListener(
[7500]203                gmaps.maps[gmaps.popupMapIndex].gMap,
[7125]204                'dragend',
205                function()
206                {
207                  $('#gmapsCenterMap').css('display', 'inline');
208                  $('#gmapsBoundKml').css('display', 'inline');
209                }
210              );
211
212              google.maps.event.addListener(
[7500]213                gmaps.maps[gmaps.popupMapIndex].gMap,
[7125]214                'zoom_changed',
215                function()
216                {
217                  $('#gmapsCenterMap').css('display', 'inline');
218                  $('#gmapsBoundKml').css('display', 'inline');
219                }
220              );
221            }
222        }
223      );
224
[7479]225      if(gmaps.geolocated)
226      {
227        $('div.gmapsPopup div.ui-dialog-titlebar')
[7500]228        .append('<a href="#" id="gmapsCenterMap" style="display:none;" onclick="centerMap(gmaps.maps[gmaps.popupMapIndex]); $(this).css(\'display\', \'none\').blur(); return(false);">'+
[7479]229                '<span>&bull;</span></a>');
230        $('#gmapsCenterMap').attr('title', gmaps.lang.centermap);
231      }
[7125]232
[7500]233      if(gmaps.maps[gmaps.popupMapIndex].gMap.kmlFile!=null)
[7125]234      {
235        $('div.gmapsPopup div.ui-dialog-titlebar')
[7500]236          .append('<a href="#" id="gmapsBoundKml" onclick="fitKmlBounds(gmaps.maps[gmaps.popupMapIndex]); $(this).css(\'display\', \'none\').blur(); return(false);">'+
[7125]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.