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

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

Packing js files +using GPC 3.3.0 categorySelector

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