JavaScript Page /Include/GoogleMapAPIWrapper.js (VB.NET)
1: // JScript File
2: function IgnoreZeroLatLongs(bIgnore)
3: {
4: //Check if there is any visible pushpin on map.
5: var cnt = 0;
6: bounds = new GLatLngBounds();
7: for(var i=0;i<markers.getLength();i++)
8: {
9: var ignoremarker = false;
10: var point1 = markers.markers[i].getPoint();
11: if(bIgnore)
12: {
13: if((point1.x==0) && (point1.y==0))
14: {
15: ignoremarker = true;
16: }
17: }
18: if(!ignoremarker)
19: {
20: if(!markers.markers[i].isHidden())
21: {
22: bounds.extend(markers.markers[i].getPoint());
23: //Increment visible pushpin count
24: cnt++;
25: }
26: }
27:
28: }
29: var iZoomLevel = map.getBoundsZoomLevel(bounds);
30: var point = bounds.getCenter();
31:
32: map.setZoom(iZoomLevel);
33: map.setCenter(point);
34:
35: }
36:
37: function ShowFullScreenMap()
38: {
39:
40: var objButton = document.getElementById('btnFullScreen');
41: if(objButton.value=='Full Screen')
42: {
43: var objMap = document.getElementById('GoogleMap_Div');
44: var objDiv = document.getElementById('GoogleMap_Div_Container');
45: objMap.style.width='100%';
46: objMap.style.height='100%';
47:
48: objDiv.style.position='absolute';
49: objDiv.style.left='0px';
50: objDiv.style.top='0px';
51: objDiv.style.width='99%';
52: objDiv.style.height='95%';
53: objDiv.style.backgroundColor='LightGrey';
54:
55: objButton.value='Close Fullscreen';
56: DrawGoogleMap();
57: }
58: else
59: {
60: var objMap = document.getElementById('GoogleMap_Div');
61: var objDiv = document.getElementById('GoogleMap_Div_Container');
62: objMap.style.width='<%=GoogleMapObject.Width %>';
63: objMap.style.height='<%=GoogleMapObject.Height %>';
64:
65: objDiv.style.position='';
66: objDiv.style.left='';
67: objDiv.style.top='';
68: objDiv.style.width='';
69: objDiv.style.height='';
70:
71: objButton.value='Full Screen';
72: //DrawGoogleMap();
73: }
74: }
75:
76: var map;
77: var trafficInfo = null;
78:
79: //function fListeners()
80: //{
81: // this.listeners = new Array();
82: // this.getLength = function() { return this.listeners.length; };
83: // this.pushValue = function(v) { this.listeners.push(v); }
84: // this.getValue = function(i) { return this.listeners[i]; }
85: //}
86: function fMarkers()
87: {
88: this.markers = new Array();
89: this.getLength = function() { return this.markers.length; };
90: this.pushValue = function(v) { this.markers.push(v); }
91: this.getValue = function(i) { return this.markers[i]; }
92: this.getLastValue = function() { return this.markers[this.markers.length-1]; }
93: this.getValueById = function(ID) {
94: var i;
95: for(i=0;i<this.markers.length;i++)
96: {
97: if(this.markers[i].value==ID)
98: {
99: // alert('marker found : '+this.markers[i].value);
100: return this.markers[i];
101: }
102: }
103: return null;
104: }
105: this.removeValueById = function(ID) {
106: var i;
107: for(i=0;i<this.markers.length;i++)
108: {
109: if(this.markers[i].value==ID)
110: {
111: // alert('marker found : '+this.markers[i].value);
112: this.markers.splice(i,1);
113: //alert('changed marker removed');
114:
115: }
116: }
117: return null;
118: }
119: }
120:
121: function fPolylines()
122: {
123: this.polylines = new Array();
124: this.polylinesID = new Array();
125: this.getLength = function() { return this.polylines.length; };
126: this.pushValue = function(v,ID) { this.polylines.push(v); this.polylinesID.push(ID); }
127: this.getValue = function(i) { return this.polylines[i]; }
128: this.getLastValue = function() { return this.polylines[this.polylines.length-1]; }
129: this.getValueById = function(ID) {
130: var i;
131: for(i=0;i<this.polylinesID.length;i++)
132: {
133: if(this.polylinesID[i]==ID)
134: {
135: // alert('polyline found : '+this.polylines[i].value);
136: return this.polylines[i];
137: }
138: }
139: return null;
140: }
141: this.removeValueById = function(ID) {
142: var i;
143: for(i=0;i<this.polylinesID.length;i++)
144: {
145: if(this.polylinesID[i]==ID)
146: {
147: this.polylines.splice(i,1);
148: this.polylinesID.splice(i,1);
149: }
150: }
151: return null;
152: }
153: }
154:
155: function fPolygons()
156: {
157: this.polygons = new Array();
158: this.polygonsID = new Array();
159: this.getLength = function() { return this.polygons.length; };
160: this.pushValue = function(v,ID) { this.polygons.push(v); this.polygonsID.push(ID); }
161: this.getValue = function(i) { return this.polygons[i]; }
162: this.getLastValue = function() { return this.polygons[this.polygons.length-1]; }
163: this.getValueById = function(ID) {
164: var i;
165: for(i=0;i<this.polygonsID.length;i++)
166: {
167: if(this.polygonsID[i]==ID)
168: {
169: return this.polygons[i];
170: }
171: }
172: return null;
173: }
174: this.removeValueById = function(ID) {
175: var i;
176: for(i=0;i<this.polygonsID.length;i++)
177: {
178: if(this.polygonsID[i]==ID)
179: {
180: this.polygons.splice(i,1);
181: this.polygonsID.splice(i,1);
182: }
183: }
184: return null;
185: }
186: }
187:
188: if (GBrowserIsCompatible())
189: {
190:
191:
192: map = new GMap2(document.getElementById("GoogleMap_Div"));
193:
194: var markers = new fMarkers();
195: var polylines = new fPolylines();
196: var polygons = new fPolygons();
197: //var myEventListeners = new fListeners();
198:
199: function CreateMarker(point,icon1,InfoHTML,bDraggable,sTitle)
200: {
201: var marker;
202: marker = new GMarker(point,{icon:icon1,draggable:bDraggable,title: sTitle});
203: if(InfoHTML!='')
204: {
205: GEvent.addListener(marker, "click", function() { this.openInfoWindowHtml(InfoHTML); });
206: }
207: GEvent.addListener(marker, "dragend", function() { GService.SetLatLon(this.value,this.getLatLng().y,this.getLatLng().x);RaiseEvent('PushpinMoved',this.value); });
208: return marker;
209: }
210:
211: function OpenInfoWindow(id,InfoHTML)
212: {
213:
214: var marker = markers.getValueById(id);
215: if(marker!=null)
216: {
217: marker.openInfoWindowHtml(InfoHTML);
218: }
219: }
220:
221: function CreatePolyline(points,color,width,isgeodesic)
222: {
223: var polyline;
224: if(!isgeodesic)
225: {
226: polyline = new GPolyline(points,color,width);
227: }
228: else
229: {
230: var polyOptions = {geodesic:true};
231: polyline = new GPolyline(points,color,width,1,polyOptions);
232: }
233: return polyline;
234: }
235:
236: function CreatePolygon(points,strokecolor,strokeweight,strokeopacity,fillcolor,fillopacity)
237: {
238: var polygon;
239:
240: var polygon = new GPolygon(points,strokecolor,strokeweight,strokeopacity,fillcolor,fillopacity);
241: return polygon;
242: }
243:
244: function fGetGoogleObject(result, userContext)
245: {
246: map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude), result.ZoomLevel);
247:
248: if(result.ShowMapTypesControl)
249: {
250: map.addControl(new GMapTypeControl());
251: }
252:
253: if(result.ShowZoomControl)
254: {
255: map.addControl(new GLargeMapControl());
256: }
257:
258:
259: map.setMapType(eval(result.MapType));
260:
261: var i;
262: if(markers!=null)
263: {
264: for(i=0;i<markers.getLength();i++)
265: {
266: var cmark = markers.getValue(i);
267: if(cmark !=null)
268: {
269: map.removeOverlay(cmark);
270: }
271: }
272: }
273: // if(myEventListeners!=null)
274: // {
275: // for(i=0;i<myEventListeners.getLength();i++)
276: // {
277: // var lisnr = myEventListeners.getValue(i);
278: // if(lisnr!=null)
279: // {
280: // GEvent.removeListener(lisnr);
281: // }
282: // }
283: // }
284: markers = new fMarkers();
285: // myEventListeners = new fListeners();
286:
287: for(i=0;i<result.Points.length;i++)
288: {
289: var myIcon_google;
290:
291: var myPoint = new GLatLng(result.Points[i].Latitude, result.Points[i].Longitude);
292:
293: myIcon_google = null;
294: if(result.Points[i].IconImage!='')
295: {
296: myIcon_google = new GIcon(G_DEFAULT_ICON);
297: markerOptions = { icon:myIcon_google };
298:
299: myIcon_google.iconSize = new GSize(result.Points[i].IconImageWidth,result.Points[i].IconImageHeight);
300: myIcon_google.image = result.Points[i].IconImage;
301: myIcon_google.shadow = result.Points[i].IconShadowImage;
302: myIcon_google.shadowSize = new GSize(result.Points[i].IconShadowWidth, result.Points[i].IconShadowHeight);
303: myIcon_google.iconAnchor = new GPoint(result.Points[i].IconAnchor_posX, result.Points[i].IconAnchor_posY);
304: myIcon_google.infoWindowAnchor = new GPoint(result.Points[i].InfoWindowAnchor_posX, result.Points[i].InfoWindowAnchor_posY);
305: }
306:
307: var marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,result.Points[i].Draggable,result.Points[i].ToolTip);
308: marker.value = result.Points[i].ID;
309: markers.pushValue(marker);
310: map.addOverlay(markers.getLastValue());
311: }
312: //Add polylines
313: // alert('adding polyline');
314:
315: polylines = new fPolylines();
316: for(i=0;i<result.Polylines.length;i++)
317: {
318:      var polypoints = new Array();
319:      var j;
320:      for(j=0;j<result.Polylines[i].Points.length;j++)
321:      {
322:          polypoints.push(new GLatLng(result.Polylines[i].Points[j].Latitude, result.Polylines[i].Points[j].Longitude));
323:      }
324: var polyline = CreatePolyline(polypoints,result.Polylines[i].ColorCode,result.Polylines[i].Width,result.Polylines[i].Geodesic);
325: polylines.pushValue(polyline,result.Polylines[i].ID);
326: map.addOverlay(polylines.getLastValue());
327: }
328: // var polypoints = new Array();
329: // polypoints.push(new GLatLng(43.65669, -79.44268));
330: // polypoints.push(new GLatLng(43.66619, -79.44268));
331: // var poly = CreatePolyline(polypoints,"#66FF00",10,true);
332: // map.addOverlay(poly);
333:
334: // var polypoints = new Array();
335: // polypoints.push(new GLatLng(43.65669, -79.44268));
336: // polypoints.push(new GLatLng(43.66619, -79.44268));
337: // polypoints.push(new GLatLng(43.67619, -79.44268));
338: // var directions = new GDirections(map,document.getElementById("directions_canvas"));
339: //Clear the mapa nd directions of any old information
340: //directions.clear();
341:
342: //Load the map and directions from the specified waypoints
343: //directions.loadFromWaypoints(polypoints);
344:
345:
346: polygons = new fPolygons();
347: for(i=0;i<result.Polygons.length;i++)
348: {
349:      var polypoints = new Array();
350:      var j;
351:      for(j=0;j<result.Polygons[i].Points.length;j++)
352:      {
353:          polypoints.push(new GLatLng(result.Polygons[i].Points[j].Latitude, result.Polygons[i].Points[j].Longitude));
354:      }
355: var polygon = CreatePolygon(polypoints,result.Polygons[i].StrokeColor,result.Polygons[i].StrokeWeight,result.Polygons[i].StrokeOpacity,result.Polygons[i].FillColor,result.Polygons[i].FillOpacity);
356: polygons.pushValue(polygon,result.Polygons[i].ID);
357: map.addOverlay(polygons.getLastValue());
358: }
359:
360:
361: if(result.ShowTraffic)
362: {
363: trafficInfo = new GTrafficOverlay();
364: map.addOverlay(trafficInfo);
365: }
366: if(result.AutomaticBoundaryAndZoom)
367: {
368: RecenterAndZoom(true,result);
369: }
370:
371: }
372:
373: function DrawGoogleMap()
374: {
375:
376: if (GBrowserIsCompatible())
377: {
378: map = new GMap2(document.getElementById("GoogleMap_Div"));
379: geocoder = new GClientGeocoder();
380:
381: GService.GetGoogleObject(fGetGoogleObject);
382: }
383: }
384:
385:
386: function fGetGoogleObjectOptimized(result, userContext)
387: {
388: if(result.RecenterMap)
389: {
390: map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude), result.ZoomLevel);
391: GService.RecenterMapComplete();
392: }
393:
394: map.setMapType(eval(result.MapType));
395:
396: if(result.ShowTraffic)
397: {
398: trafficInfo = new GTrafficOverlay();
399: map.addOverlay(trafficInfo);
400: }
401: else
402: {
403: if(trafficInfo!=null)
404: {
405: map.removeOverlay(trafficInfo);
406: trafficInfo = null;
407: }
408: }
409:
410: var i;
411: for(i=0;i<result.Points.length;i++)
412: {
413: //Create icon
414: var myIcon_google;
415:
416: var myPoint = new GLatLng(result.Points[i].Latitude, result.Points[i].Longitude);
417:
418: myIcon_google = null;
419: if(result.Points[i].IconImage!='')
420: {
421: myIcon_google = new GIcon(G_DEFAULT_ICON);
422: markerOptions = { icon:myIcon_google };
423:
424: myIcon_google.iconSize = new GSize(result.Points[i].IconImageWidth,result.Points[i].IconImageHeight);
425: myIcon_google.image = result.Points[i].IconImage;
426: myIcon_google.shadow = result.Points[i].IconShadowImage;
427: myIcon_google.shadowSize = new GSize(result.Points[i].IconShadowWidth, result.Points[i].IconShadowHeight);
428: myIcon_google.iconAnchor = new GPoint(result.Points[i].IconAnchor_posX, result.Points[i].IconAnchor_posY);
429: myIcon_google.infoWindowAnchor = new GPoint(result.Points[i].InfoWindowAnchor_posX, result.Points[i].InfoWindowAnchor_posY);
430:
431: }
432: //Existing marker, but changed.
433: if(result.Points[i].PointStatus=='C')
434: {
435: var marker = markers.getValueById(result.Points[i].ID);
436: if(marker!=null)
437: {
438: markers.removeValueById(result.Points[i].ID);
439: map.removeOverlay(marker);
440: }
441: var marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,result.Points[i].Draggable,result.Points[i].ToolTip);
442: marker.value = result.Points[i].ID;
443: markers.pushValue(marker);
444: map.addOverlay(markers.getLastValue());
445: }
446: //New Marker
447: if(result.Points[i].PointStatus=='N')
448: {
449: var marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,result.Points[i].Draggable,result.Points[i].ToolTip);
450: marker.value = result.Points[i].ID;
451: markers.pushValue(marker);
452: map.addOverlay(markers.getLastValue());
453: }
454: //Existing marker, but deleted.
455: if(result.Points[i].PointStatus=='D')
456: {
457: var marker = markers.getValueById(result.Points[i].ID);
458: if(marker!=null)
459: {
460: markers.removeValueById(result.Points[i].ID);
461: map.removeOverlay(marker);
462: }
463: }
464: }
465:
466: //Get Polylines
467: for(i=0;i<result.Polylines.length;i++)
468: {
469: //Existing marker, but changed.
470:
471: if(result.Polylines[i].LineStatus=='C')
472: {
473:
474: var polyline = polylines.getValueById(result.Polylines[i].ID);
475: if(polyline!=null)
476: {
477: polylines.removeValueById(result.Polylines[i].ID);
478: map.removeOverlay(polyline);
479: }
480:      var polypoints = new Array();
481:      var j;
482:      for(j=0;j<result.Polylines[i].Points.length;j++)
483:      {
484:           polypoints.push(new GLatLng(result.Polylines[i].Points[j].Latitude, result.Polylines[i].Points[j].Longitude));
485:      }
486: var polyline = CreatePolyline(polypoints,result.Polylines[i].ColorCode,result.Polylines[i].Width,result.Polylines[i].Geodesic);
487: polylines.pushValue(polyline,result.Polylines[i].ID);
488: map.addOverlay(polylines.getLastValue());
489: }
490: //New Marker
491:
492: if(result.Polylines[i].LineStatus=='N')
493: {
494:      var polypoints = new Array();
495:      var j;
496:      for(j=0;j<result.Polylines[i].Points.length;j++)
497:      {
498:           polypoints.push(new GLatLng(result.Polylines[i].Points[j].Latitude, result.Polylines[i].Points[j].Longitude));
499:      }
500: var polyline = CreatePolyline(polypoints,result.Polylines[i].ColorCode,result.Polylines[i].Width,result.Polylines[i].Geodesic);
501: polylines.pushValue(polyline,result.Polylines[i].ID);
502: map.addOverlay(polylines.getLastValue());
503: }
504: //Existing marker, but deleted.
505: if(result.Polylines[i].LineStatus=='D')
506: {
507: var polyline = polylines.getValueById(result.Polylines[i].ID);
508: if(polyline!=null)
509: {
510: polylines.removeValueById(result.Polylines[i].ID);
511: map.removeOverlay(polyline);
512: }
513: }
514: }
515:
516: //Get Polygons
517: for(i=0;i<result.Polygons.length;i++)
518: {
519: //Existing marker, but changed.
520:
521: if(result.Polygons[i].Status=='C')
522: {
523:
524: var polygon = polygons.getValueById(result.Polygons[i].ID);
525: if(polygon!=null)
526: {
527: polygons.removeValueById(result.Polygons[i].ID);
528: map.removeOverlay(polygon);
529: }
530:      var polypoints = new Array();
531:      var j;
532:      for(j=0;j<result.Polygons[i].Points.length;j++)
533:      {
534:           polypoints.push(new GLatLng(result.Polygons[i].Points[j].Latitude, result.Polygons[i].Points[j].Longitude));
535:      }
536: var polygon = CreatePolygon(polypoints,result.Polygons[i].StrokeColor,result.Polygons[i].StrokeWeight,result.Polygons[i].StrokeOpacity,result.Polygons[i].FillColor,result.Polygons[i].FillOpacity);
537: polygons.pushValue(polygon,result.Polygons[i].ID);
538: map.addOverlay(polygons.getLastValue());
539: }
540: //New Marker
541:
542: if(result.Polygons[i].Status=='N')
543: {
544:      var polypoints = new Array();
545:      var j;
546:      for(j=0;j<result.Polygons[i].Points.length;j++)
547:      {
548:           polypoints.push(new GLatLng(result.Polygons[i].Points[j].Latitude, result.Polygons[i].Points[j].Longitude));
549:      }
550: var polygon = CreatePolygon(polypoints,result.Polygons[i].StrokeColor,result.Polygons[i].StrokeWeight,result.Polygons[i].StrokeOpacity,result.Polygons[i].FillColor,result.Polygons[i].FillOpacity);
551: polygons.pushValue(polygon,result.Polygons[i].ID);
552: map.addOverlay(polygons.getLastValue());
553: }
554: //Existing marker, but deleted.
555: if(result.Polygons[i].Status=='D')
556: {
557: var polygon = polygons.getValueById(result.Polygons[i].ID);
558: if(polygon!=null)
559: {
560: polygons.removeValueById(result.Polygons[i].ID);
561: map.removeOverlay(polygon);
562: }
563: }
564: }
565: if(result.AutomaticBoundaryAndZoom)
566: {
567: RecenterAndZoom(true,result);
568: }
569: }
570: }
571:
572: //This function causes Recentering of map. It finds all visible markers on map and decides center point and zoom level based on these markers.
573: function RecenterAndZoom(bRecenter,result)
574: {
575: if(bRecenter)
576: {
577: //Check if there is any visible pushpin on map.
578: var cnt = 0;
579: bounds = new GLatLngBounds();
580: var objIgnore = document.getElementById('chkIgnoreZero');
581: var bIgnore = false;
582: if(objIgnore!=null)
583: {
584: bIgnore = objIgnore.checked;
585: }
586: bIgnore = result.IgnoreZeroLatLngs;
587: for(var i=0;i<markers.getLength();i++)
588: {
589: var ignoremarker = false;
590: if(bIgnore)
591: {
592: var point1 = markers.markers[i].getPoint();
593: if((point1.x==0) && (point1.y==0))
594: {
595: ignoremarker = true;
596: }
597: }
598: if(!ignoremarker)
599: {
600: if(!markers.markers[i].isHidden())
601: {
602: bounds.extend(markers.markers[i].getPoint());
603: //Increment visible pushpin count
604: cnt++;
605: }
606: }
607:
608: }
609: var iZoomLevel = map.getBoundsZoomLevel(bounds);
610: var point = bounds.getCenter();
611:
612: if(iZoomLevel>14)
613: {
614: iZoomLevel = 14;
615: }
616:
617: if(cnt<=0)
618: {
619: point = new GLatLng(result.CenterPoint.Latitude,result.CenterPoint.Longitude);
620: iZoomLevel =result.ZoomLevel;
621: }
622: map.setZoom(iZoomLevel);
623: map.setCenter(point);
624: }
625: }
626: function endRequestHandler(sender, args)
627: {
628: GService.GetOptimizedGoogleObject(fGetGoogleObjectOptimized);
629: }
630: function pageLoad()
631: {
632: if(!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
633: Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
634: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.