PageSourceSearch

https://www.clinic-toku.com/wp-content/plugins/event-organiser/js/maps/googlemaps-adapter.js?ver=3.7.6

js clinic-toku.com collected 2026-10-07 03:19:44 UTC 8,165 bytes, 220 lines download raw bytes

1var eventorganiserMapsAdapter = eventorganiserMapsAdapter || {};
2eventorganiserMapsAdapter.googlemaps = eventorganiserMapsAdapter.googlemaps || {};
3eventorganiserMapsAdapter.provider = eventorganiserMapsAdapter.googlemaps;
4/**
5 * Google Maps Adapter class
6 * Dynamic Prototype Pattern, Adapter
7 *
8 * @param string elementID A DOM ID of the container for the map
9 * @param object args Properties of the map
10 */
11eventorganiserMapsAdapter.googlemaps.map = function ( elementID, args) {
12
13    this.elementID = elementID;
14    this.args = args;
15    var mapArgs = {
16        zoom: args.zoom,
17        scrollwheel: args.scrollwheel,
18        zoomControl: args.zoomcontrol,
19        rotateControl: args.rotatecontrol,
20        panControl: args.pancontrol,
21        overviewMapControl: args.overviewmapcontrol,
22        streetViewControl: args.streetviewcontrol,
23        draggable: args.draggable,
24        mapTypeControl: args.maptypecontrol,
25        //mapTypeId: google.maps.MapTypeId.ROADMAP
26        mapTypeId: google.maps.MapTypeId[args.maptypeid],
27        styles: args.styles,
28        minZoom: args.minzoom,
29        maxZoom: args.maxzoom,
30    };
31
32    mapArgs = wp.hooks.applyFilters( 'eventorganiser.google_map_options', mapArgs, this.args )
33
34    this._markers = {};
35    this._map     = new google.maps.Map( document.getElementById( this.elementID ), mapArgs );
36
37    // constructor prototype to share properties and methods
38    if ( typeof this.setCenter !== "function" ) {
39        /**
40         * Set the center of the map to the specified location
41         * @param object location With properties 'lat' and 'lng'
42         */
43        eventorganiserMapsAdapter.googlemaps.map.prototype.setCenter = function( location ) {
44            this._map.setCenter( { lat: parseFloat( location.lat ), lng: parseFloat( location.lng ) } );
45        };
46
47        /**
48         * Set the zoom level of the map
49         * @param int zoom
50         */
51        eventorganiserMapsAdapter.googlemaps.map.prototype.setZoom = function( zoom ) {
52            this._map.setZoom( zoom );
53        };
54
55        /**
56         * Set the zoom level of the map to fit the array of locations
57         * @param array locations Array of objects with properties 'lat' and 'lng'
58         */
59        eventorganiserMapsAdapter.googlemaps.map.prototype.fitLocations = function( locations ) {
60            var bounds = new google.maps.LatLngBounds();
61            for ( var j = 0; j < locations.length; j++ ) {
62                var latlng = { lat: parseFloat( locations[j].lat ), lng: parseFloat( locations[j].lng ) };
63                bounds.extend(latlng);
64            }
65            this._map.fitBounds( bounds );
66        };
67
68        /**
69         * Add a marker to the location
70         * A location has an ID (venue_id), position ({lat:<lat>, lng:<lng>}) and,
71				 * optional, tooltip content (tooltipContent), icon URL
72         * @param object location, with position property (with lat, lng properties)
73         */
74        eventorganiserMapsAdapter.googlemaps.map.prototype.addMarker = function( location ) {
75            location.map = this;
76            var marker = new eventorganiserMapsAdapter.googlemaps.marker( location );
77            this._markers[location.venue_id] = marker;
78            return marker;
79        };
80    }
81
82    //Add the locations
83    if ( this.args.locations.length > 1 ) {
84        this.fitLocations( this.args.locations );
85    } else if( this.args.locations.length > 0 ) {
86        this.setCenter( this.args.locations[0] );
87    }
88
89    wp.hooks.doAction( 'eventorganiser.google_map_loaded', this );
90};
91
92/**
93 * A marker instance tied to a specific location
94 * Argument must include the properties: map (a map adapter instance), position (lat/lng object),
95 * venue_id (location ID), tooltipContent (optional, content for tooltip), icon (optional icon image URL)
96 * @param object args
97 */
98eventorganiserMapsAdapter.googlemaps.marker = function ( args ) {
99
100    this.map = args.map;
101
102    var marker_options = jQuery.extend({}, args, {
103        venue_id: args.venue_id,
104        position: { lat: parseFloat( args.position.lat ), lng: parseFloat( args.position.lng ) },
105        icon: args.icon,
106        map: this.map._map
107    });
108
109    //Store the google instance of the marker
110    this._marker = new google.maps.Marker( marker_options );
111
112    if ( args.tooltipContent ) {
113        var infowindow = new google.maps.InfoWindow({
114            content: marker_options.tooltipContent
115        });
116        var _marker = this._marker;
117        google.maps.event.addListener(this._marker, 'click', function() {
118            infowindow.open( marker_options.map, _marker );
119        });
120    }
121
122    var proxiedCallbacks = {};
123
124    var mapAdapter =  this.map;
125
126    // constructor prototype to share properties and methods
127    if ( typeof this.setPosition !== "function" ) {
128        /**
129         * Set the location of the marker
130         * @param object latLng with properties lat and lng
131         */
132        eventorganiserMapsAdapter.googlemaps.marker.prototype.setPosition = function( latLng ) {
133            this._marker.setPosition( latLng );
134        };
135
136				eventorganiserMapsAdapter.googlemaps.marker.prototype.setIcon = function( url ) {
137						this._marker.setIcon( url );
138				};
139
140        /**
141         * Event handler for the marker
142         * Only explicitly supported events: drag, dragEnd, move
143         * @param eventName Event to listen to
144         * @param callback Callback to be triggered when event occurs
145         */
146        eventorganiserMapsAdapter.googlemaps.marker.prototype.on = function( eventName, callback ) {
147            var eventNameMapped;
148            switch( eventName ) {
149                case 'move':
150                    eventNameMapped = 'position_changed';//event name according to Google
151                    break;
152                default:
153                    eventNameMapped = eventName;
154            }
155
156            proxiedCallbacks[eventNameMapped] = callback;
157
158            google.maps.event.addListener(this._marker, eventNameMapped, function( evt ){
159                var callback = proxiedCallbacks[eventNameMapped];
160
161                var proxyEvt = {
162                    _evt: evt,
163                    type: eventName,
164                    target: {
165                        map: mapAdapter,
166                        latlng: {}
167                    }
168                }
169                if ( ! evt || typeof evt.latLng == undefined ) {
170                    var latLng = this.getPosition();
171                } else {
172                    var latLng = evt.latLng;
173                }
174
175                proxyEvt.target.latlng = {
176                    lat: latLng.lat().toFixed(6),
177                    lng: latLng.lng().toFixed(6)
178                }
179                callback.call( mapAdapter, proxyEvt );
180            } );
181        }
182    }
183}
184
185/**
186 * A geocoder
187 * Accepts an address and passes latitude/longitude co-ordinates to  the callback
188 */
189eventorganiserMapsAdapter.googlemaps.geocoder = function( ) {
190    this._geocoder = new google.maps.Geocoder();
191    if ( typeof this.geocode !== "function" ) {
192        /**
193         * Look up address and pass latitude/longitude co-ordinates to callback
194         * @param object address - with keys such as 'address' (street address), 'city', 'state', 'postcode' etc
195         * @param callable callback
196         */
197        eventorganiserMapsAdapter.googlemaps.geocoder.prototype.geocode = function ( address, callback ) {
198
199            //Comma delimitate the address
200            var addressString = "";
201            for (var i in address) {
202                addressString += address[i] + ", ";
203            }
204
205            this._geocoder.geocode(
206                { 'address': addressString},
207                function (results, status) {
208                    if ( status == google.maps.GeocoderStatus.OK ){
209                        callback.call( this, {
210                            lat: results[0].geometry.location.lat(),
211                            lng: results[0].geometry.location.lng()
212                        } );
213                    }else{
214                        return callback.call( this, false );
215                    }
216                }
217            );
218        };
219    }
220}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.