/[drupal]/contributions/modules/mykml/jquery.jmaps.js
ViewVC logotype

Contents of /contributions/modules/mykml/jquery.jmaps.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Sep 5 23:10:22 2007 UTC (2 years, 2 months ago) by challer
Branch: MAIN
CVS Tags: DRUPAL-5--2-0, HEAD
Branch point for: DRUPAL-5
File MIME type: text/javascript
initial upload
1 /*
2 * jQuery Maps (jMaps) - A jQuery plugin for Google Maps API
3 * Author: Tane Piper (digitalspaghetti@gmail.com)
4 * With special thanks Dave Cardwell (who helped on getting this plugin to work).
5 * Website: http://code.google.com/p/gmapp/
6 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
7 * For Google Maps API see http://www.google.com/apis/maps/
8 *
9 * === Changelog ===
10 * Version 1.1 (16/07/2007)
11 * Changed name to remove Google from main name - namespace now .jmap.
12 * Added additional options:
13 * + Add map dragging enable/disable.
14 * + Add scroll wheel zooming.
15 * + Add smooth continuous zooming (on certain browsers).
16 * + Added clean unloading of Google objects.
17 * Added .addPoly method. Allows the creation of polylines on the map.
18 * Added .addKml support for rendering KML Files.
19 * Added .directions Driving Direction support.
20 *
21 * Version 1.0 (13/07/2007)
22 * Initial version.
23 * Creates Google Map.
24 * Add points to map.
25 * Takes address or postcode, Geocodes and centers map. Also creates a draggable marker.
26 */
27
28 (function($) {
29 function searchAddress(jmap, address, GGeocoder, settings) {
30 GGeocoder.getLatLng(address, function(point){
31 if (!point) {
32 alert(address + " not found");
33 } else {
34 jmap.setCenter(point,settings.zoom);
35 var marker = new GMarker(point, {draggable: true});
36 jmap.addOverlay(marker);
37 marker.openInfoWindowHtml("Latitude: " + mylocation.lat() + "<br />Longitude: " + mylocation.lng());
38 GEvent.addListener(marker, "dragend", function(){
39 mylocation = marker.getPoint();
40 marker.openInfoWindowHtml("Latitude: " + mylocation.lat() + "<br />Longitude: " + mylocation.lng());
41 });
42 }
43 });
44 };
45
46 $.fn.extend({
47 jmap: function(settings) {
48 var version = "0.1";
49
50 /* Default Settings*/
51 settings = jQuery.extend({
52 maptype: G_HYBRID_TYPE,
53 center: [55.958858,-3.162302],
54 zoom: 12,
55 control: "small",
56 showtype: true,
57 showoverview: true,
58 dragging: true,
59 scrollzoom: true,
60 smoothzoom: true,
61 searchfield: "#Address",
62 searchbutton: "#findaddress"
63 },settings);
64
65 if (GBrowserIsCompatible())
66 {
67 return this.each(function(){
68 var jmap = this.GMap2 = new GMap2(this);
69 GGeocoder = new GClientGeocoder();
70
71 this.GMap2.setCenter(new GLatLng(settings.center[0],settings.center[1]),settings.zoom,settings.maptype);
72 switch(settings.control)
73 {
74 case "small":
75 this.GMap2.addControl(new GSmallMapControl());
76 break;
77 case "large":
78 this.GMap2.addControl(new GLargeMapControl());
79 break;
80 case "none":
81 break;
82 default:
83 this.GMap2.addControl(new GSmallMapControl());
84 }
85
86 if (settings.showtype == true){
87 this.GMap2.addControl(new GMapTypeControl());
88 }
89 if (settings.showoverview == true){
90 this.GMap2.addControl(new GOverviewMapControl());
91 }
92
93 if (settings.scrollzoom == true) {
94 /* Off by default */
95 this.GMap2.enableScrollWheelZoom();
96 }
97 if (settings.smoothzoom == true) {
98 /* Off by default*/
99 this.GMap2.enableContinuousZoom();
100 }
101 if (settings.dragging == false) {
102 /* On by default */
103 this.GMap2.disableDragging();
104 }
105
106 /* Seach for the lat & lng of our address*/
107 jQuery(settings.searchbutton).bind('click', function(){
108 searchAddress(jmap, jQuery(settings.searchfield).attr('value'), GGeocoder, settings);
109 });
110
111 jQuery(document).unload(function(){ GUnload(); });
112 });
113 }
114 },
115
116 myMap: function() {
117 return this[0].GMap2;
118
119 },
120
121 addPoint: function(pointlat, pointlng, pointhtml, isdraggable, removable) {
122 var jmap = this[0].GMap2;
123 console.log(jmap);
124 var marker = new GMarker(new GLatLng(pointlat,pointlng), { draggable: isdraggable } );
125 GEvent.addListener(marker, "click", function(){
126 marker.openInfoWindowHtml(pointhtml);
127 });
128 if (removable == true) {
129 GEvent.addListener(marker, "dblclick", function(){
130 return jmap.removeOverlay(marker);
131 });
132 }
133 return jmap.addOverlay(marker);
134 },
135 addPoly: function (poly) {
136 var jmap = this[0].GMap2;
137 return jmap.addOverlay(poly);
138 },
139 /* FIXME: KML File not rendering*/
140 addKml: function (kmlfile) {
141 var jmap = this[0].GMap2;
142 var geoXml = new GGeoXml(kmlfile);
143 return jmap.addOverlay(geoXml);
144 },
145 directions: function(query,panel) {
146 var jmap = this[0].GMap2;
147 var dirpanel = document.getElementById(panel);
148 directions = new GDirections(jmap, dirpanel);
149 directions.load(query);
150 }
151 });
152 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2