File: map_control.xsl

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (350 lines) | stat: -rw-r--r-- 9,638 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?xml version="1.0"?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:v="http://www.openlinksw.com/vspx/"
  xmlns:vm="http://www.openlinksw.com/vspx/ods/">

  <!--
  Displays a map using the google maps
  Params:
     sql
       This is the SQL query to return the following columns for each point in the map:
         _LNG REAL : the longitude as a real value
         _LAT REAL : the latitude as a real value
	 _KEY_VAL ANY : The column whose value is compared to the 'key-val' value to find the center of the map
	 EXCERPT : the text to go into the bubble window
     baloon-inx : the index (1 based) of the EXCERPT column in the result set
     lat-inx : the index (1 based) of the _LAT column in the result set
     lng-inx : the index (1 based) of the _LNG column in the result set
     key-name-inx : the index (1 based) of the _KEY_VAL column in the result set
     key-val : the value to compare to the _KEY_VAL column
     base_url : the base uri for the marker icon
     div-id : the HTTP id of the DIV section to put the map in.
  -->
  <xsl:template match="vm:map-control">
   <![CDATA[
  <script
       src="http://maps.google.com/maps?file=api&amp;v=1&amp;key=<?U WA_MAPS_GET_KEY () ?>"
       type="text/javascript" >
      </script>

  <script
      src="/ods/comp/map_control.js"
       type="text/javascript" >
      </script>
      ]]>
  &lt;?vsp
    declare _inst_id integer;
    declare _sid, _realm varchar;
    _sid := self.sid;
    _realm := self.realm;

    WA_MAPS_AJAX_SET_VALS_GET_ID (
      _inst_id,
      <xsl:value-of select="@sql" />,
      <xsl:value-of select="@baloon-inx" />,
      <xsl:value-of select="@lat-inx" />,
      <xsl:value-of select="@lng-inx" />,
      <xsl:value-of select="@key-name-inx" />,
      <xsl:value-of select="@key-val" />,
      <xsl:value-of select="@base_url" />,
      _sid,
      _realm
      );
    commit work;
  ?&gt;

  <![CDATA[
  <script
       type="text/javascript" >
  function onLoad ()
  {
      zoom_level=]]><xsl:value-of select="@zoom" /><![CDATA[;
      initMap (
	"]]><xsl:value-of select="@div_id"/><![CDATA[",
	"/ods/search_ajax.vsp",
	"/ods/images/icons')",
	"<?V _inst_id ?>", zoom_level );
  }
  window.onload=onLoad;
  </script>
  ]]>
 </xsl:template>

<xsl:template match="vm:oatmap-control">

&lt;?vsp

  declare rendered_javascript any;
  rendered_javascript:=string_output();

  declare _lat_inx,_lng_inx,_key_name_inx,_baloon_inx,_zoom integer;
  _lat_inx:=<xsl:value-of select="@lat-inx" />;
  _lng_inx:=<xsl:value-of select="@lng-inx" />;
  _key_name_inx:=<xsl:value-of select="@key-name-inx" />;
  _baloon_inx:=<xsl:value-of select="@baloon-inx" />;
  _zoom:=<xsl:value-of select="@zoom" />;

  declare _sql,_key_val varchar;
  _sql:=<xsl:value-of select="@sql" />;
  _key_val:='<xsl:value-of select="@key-val" />';

  declare group_inx integer;
  group_inx:=1;

  declare markericon_path,markericon_width,markericon_height varchar;
  markericon_path:='images/icons/user_16.png';
  markericon_width:='16';
  markericon_height:='16';

  declare center_lat, center_lng varchar;
  center_lat := NULL;
  center_lng := NULL;

  declare hndl, row any;

  http('var markersArr = [];var user_dshtml='''';\r\n',rendered_javascript);


  exec (_sql, NULL, NULL, vector (), 0, NULL, NULL, hndl);
  declare _idx integer;
  _idx:=0;
  while (0 = exec_next (hndl, NULL, NULL, row))
  {
      declare _baloon_col varchar;
      declare _lat, _lng varchar;
      declare _count integer;
      declare _key_data any;

      _baloon_col := row[_baloon_inx - 1];
      _lat := sprintf ('%.6f', row[_lat_inx - 1]);
      _lng := sprintf ('%.6f', row[_lng_inx - 1]);
      _key_data := row[_key_name_inx - 1];


      if (_key_data = _key_val )
      {
          center_lat := _lat;
          center_lng := _lng;
      }

      http (sprintf('user_dshtml=''%s'';',replace(_baloon_col,'''','`')),rendered_javascript);
      http (sprintf('commonMapObj.addMarker(%d,%s,%s,''%s'',%s,%s,ref(commonMapObj,user_dshtml));',group_inx,_lat,_lng,markericon_path,markericon_width,markericon_height),rendered_javascript);
      http (sprintf('markersArr.push([%s,%s]);\r\n',_lat,_lng),rendered_javascript);

      _idx:=_idx+1;
  }
  exec_close (hndl);

  if(_zoom=0){
      if(_idx>0)
        http ('commonMapObj.optimalPosition(markersArr);\r\n',rendered_javascript);

  }else{
      http (sprintf('commonMapObj.centerAndZoom(%s,%s,%d);\r\n',center_lat,center_lng,_zoom),rendered_javascript);
  }


?&gt;
<![CDATA[
<script  type="text/javascript">

ODSInitArray.push(mapInitPrepare);

function mapInitPrepare()
{
  if (typeof(window.mapInit) == "function")
    {
      OAT.Loader.load(["map"], function(){setTimeout(mapInit,60)});
    };

  return;
}

var MAX_ZOOM_LEVEL = 15;
var BURLINGTON_LAT = 42.490;
var BURLINGTON_LNG = -71.19;


function ref(_map,user_dshtml){
 		return function(marker) {

        var user_div=OAT.Dom.create("div");
        user_div.innerHTML = user_dshtml;

				_map.closeWindow();

        _map.openWindow(marker,user_div);
      };
}

function mapInit(){

    if (window._apiKey=='0' && window.YMAPPID!='0')
    {
        var defaultMapType='yahoo';
        var alternativeMapType='google';
    }else
    {
        var defaultMapType='google';
        var alternativeMapType='yahoo';
    }

    var containerDiv=$(']]><xsl:value-of select="@div_id" /><![CDATA[');

    if(containerDiv)
     {

      var changeMapServiceTo='<?V get_keyword('switchmapto', self.vc_event.ve_params,'') ?>';

      var providerType=OAT.MapData.TYPE_G;
      if(changeMapServiceTo=='yahoo' && window.YMAPPID!=0){
          providerType=OAT.MapData.TYPE_Y;
      };


      var mapOptObj = {
	                     fix:OAT.MapData.FIX_ROUND1,
	                     fixDistance:20,
	                     fixEpsilon:0.5
                      };
       var commonMapObj= new OAT.Map(containerDiv,providerType,mapOptObj);
       commonMapObj.centerAndZoom(BURLINGTON_LAT,BURLINGTON_LNG,MAX_ZOOM_LEVEL);
       commonMapObj.addTypeControl();
       commonMapObj.addMapControl();
       commonMapObj.setMapType(OAT.MapData.MAP_HYB);
       <?vsp http(string_output_string(rendered_javascript)); ?>
     }else{
        return;  //        alert('Please define a div container for the map control.');
     };

      var mappingServiceSwitch=OAT.Dom.create("a");


      var hrefParams = '';

      if(window._apiKey!='0' && window.YMAPPID!='0')
      {
          var pArr=OAT.Dom.uriParams();
          if(typeof(pArr.switchmapto)!='undefined')
          {
             if(changeMapServiceTo==defaultMapType || changeMapServiceTo=='')
                pArr.switchmapto = alternativeMapType;
             else
                pArr.switchmapto = defaultMapType;
          }else
            pArr['switchmapto'] = alternativeMapType;

          var i=0;
          for(p in pArr)
          {
            hrefParams += i==0 ? '?'+p+'='+pArr[p] : '&'+p+'='+pArr[p];
            i++;
          }

         mappingServiceSwitch.href = document.location.protocol+'//'+document.location.host+document.location.pathname+hrefParams;

         if(changeMapServiceTo=='yahoo')
            mappingServiceSwitch.innerHTML='Use Google Mapping Service';
         else if( changeMapServiceTo!='yahoo' && window.YMAPPID!=0)
            mappingServiceSwitch.innerHTML='Use Yahoo Mapping Service';

         OAT.Dom.append([containerDiv.parentNode,mappingServiceSwitch])

      }

}

function getParameters() {

   var params = new Array();
   var url = window.location.href;
   var paramsStart = url.indexOf("?");
   var hasMoreParams = true;

   if(paramsStart != -1){

     var paramString = url.substr(paramsStart + 1);
     var params = paramString.split("&");
     for(var i = 0 ; i < params.length ; i++) {

       var pairArray = params[i].split("=");

       if(pairArray.length == 2){
         params[pairArray[0]] = pairArray[1];
       }

     }
     return params;
   }
   return null;
}

function getNonLoginParamsStr()
{
  var allParams = new Array;
  allParams = getParameters();

  var nonLoginParams = '';

  if(allParams!= null && allParams.length > 0 )
  {
     for(var i = 0 ; i < allParams.length ; i++)
     {
        if( allParams[i].indexOf('sid')==-1 &&
            allParams[i].indexOf('realm')==-1 &&
            allParams[i].indexOf('switchmapto')==-1 )
        {
           if(nonLoginParams.length==0)
           {
             nonLoginParams=allParams[i];
           }else
           {
             nonLoginParams=nonLoginParams+'&'+allParams[i];
           }
        }
     }

     return nonLoginParams;

  }

  return null;
}


function dd(txt){
  if(typeof console == 'object'){
    console.debug(txt);
  }
}

</script>
]]>
</xsl:template>


</xsl:stylesheet>