PageSourceSearch

https://www.himsr.co.in/wp-content/plugins/event-organiser/js/maps/openstreetmap-adapter.js?ver=3.12.5

js himsr.co.in collected 2026-10-02 23:00:07 UTC 7,838 bytes, 218 lines download raw bytes

1var eventorganiserMapsAdapter = eventorganiserMapsAdapter || {};
2eventorganiserMapsAdapter.openstreetmap = eventorganiserMapsAdapter.openstreetmap || {};
3eventorganiserMapsAdapter.provider = eventorganiserMapsAdapter.openstreetmap;
4
5/**
6 * OSM Adapter class
7 * Dynamic Prototype Pattern, Adapter
8 *
9 * @param string elementID A DOM ID of the container for the map
10 * @param object args Properties of the map
11 */
12eventorganiserMapsAdapter.openstreetmap.map = function( elementID, args) {
13
14    this.elementID = elementID;
15    this.args = jQuery.extend({
16        zoom: 12,
17        minZoom: 0,
18        maxZoom: 18,
19    }, args );
20    var mapArgs = {
21        zoom: this.args.zoom,
22        minZoom: this.args.minZoom,
23        maxZoom: this.args.maxZoom,
24        draggable: this.args.draggable,
25        zoomControl: this.args.zoomcontrol,//whether to display +/- for zooming;
26        scrollWheelZoom: this.args.scrollwheel,//zoom using scroll wheel
27        tiles: {
28            url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
29            attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
30        },
31        worldCopyJump: true
32    };
33    this._markers = {};
34
35    this._map = L.map( document.getElementById( this.elementID ), mapArgs );
36    L.tileLayer( mapArgs.tiles.url, mapArgs.tiles).addTo(this._map);
37
38    // constructor prototype to share properties and methods
39    if ( typeof this.setCenter !== "function" ) {
40        /**
41         * Set the center of the map to the specified location
42         * @param object location With properties 'lat' and 'lng'
43         */
44        eventorganiserMapsAdapter.openstreetmap.map.prototype.setCenter = function( location ) {
45            var latlng = L.latLng(location.lat, location.lng);
46            this._map.setView( latlng, args.zoom );
47        };
48
49        /**
50         * Set the zoom level of the map
51         * @param int zoom
52         */
53        eventorganiserMapsAdapter.openstreetmap.map.prototype.setZoom = function( zoom ) {
54            this._map.setZoom( zoom );
55        };
56
57        /**
58         * Set the zoom level of the map to fit the array of locations
59         * @param array locations Array of objects with properties 'lat' and 'lng'
60         */
61        eventorganiserMapsAdapter.openstreetmap.map.prototype.fitLocations = function( locations ) {
62            var bounds = new L.LatLngBounds();
63            for( var j = 0; j < locations.length; j++ ) {
64
65                var lat = locations[j].lat;
66                var lng = locations[j].lng;
67
68                if (lat === undefined || lng === undefined) {
69                    continue;
70                }
71                var latlng = L.latLng(lat, lng);
72                bounds.extend(latlng);
73            }
74            this._map.fitBounds( bounds );
75        };
76
77        /**
78         * Add a marker to the location
79         * A location has an ID (venue_id), location (lat, lng) and, optional, tooltip content (tooltipContent)
80         * @param object location
81         */
82        eventorganiserMapsAdapter.openstreetmap.map.prototype.addMarker = function( location ) {
83            location.map = this;
84            var marker = new eventorganiserMapsAdapter.openstreetmap.marker( location );
85            this._markers[location.venue_id] = marker;
86            return marker;
87        };
88    }
89
90    if ( this.args.locations.length > 1 ) {
91        this.fitLocations( this.args.locations );
92    } else if( this.args.locations.length > 0) {
93        this.setCenter( this.args.locations[0] );
94    }
95
96};
97
98/**
99 * A marker instance tied to a specific location
100 * Argument must include the properties: map (a map adapter instance), position (lat/lng object),
101 * venue_id (location ID), tooltipContent (optional, content for tooltip), icon (optional icon image URL)
102 * @param object args
103 */
104eventorganiserMapsAdapter.openstreetmap.marker = function ( args ) {
105
106    this.map = args.map;
107
108    var marker_options = jQuery.extend({}, args, {});
109    delete marker_options.icon;
110
111    this._marker = L.marker([args.position.lat, args.position.lng], marker_options);
112    this._marker.addTo(this.map._map);
113
114    if( args.tooltipContent ){
115        this._marker.bindPopup( args.tooltipContent )
116    }
117
118    var mapAdapter =  this.map;
119
120    // constructor prototype to share properties and methods
121    if ( typeof this.setCenter !== "function" ) {
122        /**
123         * Set the location of the marker
124         * @param object latLng with properties lat and lng
125         */
126        eventorganiserMapsAdapter.openstreetmap.marker.prototype.setPosition = function( latLng ) {
127            this._marker.setLatLng( [latLng.lat, latLng.lng ]  );
128        };
129
130        eventorganiserMapsAdapter.openstreetmap.marker.prototype.getPosition = function( latLng ) {
131            let position = this._marker.getLatLng();
132            return {lat: position.lat, lng: position.lng}
133        };
134
135        eventorganiserMapsAdapter.openstreetmap.marker.prototype.remove = function( ) {
136            this._marker.remove();
137        };
138
139        eventorganiserMapsAdapter.openstreetmap.marker.prototype.setIcon = function( url ) {
140            var markerInst = this._marker;
141            jQuery("<img/>",{
142                load : function(){
143                    markerInst.setIcon(L.icon({
144                        iconUrl: url,
145                        iconSize: [this.width, this.height],
146                        iconAnchor: [this.width/2, this.height]
147                    }));
148                },
149                src  : url
150            });
151        };
152
153        /**
154         * Event handler for the marker
155         * Only explicitly supported events: drag, dragEnd, move
156         * @param eventName Event to listen to
157         * @param callback Callback to be triggered when event occurs
158         */
159        eventorganiserMapsAdapter.openstreetmap.marker.prototype.on = function( eventName, callback ) {
160            //TODO store callbacks to we can support removing them
161            this._marker.on( eventName, function( evt ){
162                var proxyEvt = {
163                    _evt: evt,
164                    type: eventName,
165                    target: {
166                        map: mapAdapter,
167                        latlng: evt.target._latlng
168                    }
169                }
170                callback.call( mapAdapter, proxyEvt );
171            } );
172        }
173
174
175				if(args.icon){
176					this.setIcon(args.icon);
177				}
178
179    }
180
181}
182
183/**
184 * A geocoder
185 * Accepts an address and passes latitude/longitude co-ordinates to  the callback
186 */
187eventorganiserMapsAdapter.openstreetmap.geocoder = function( ) {
188    if ( typeof this.geocode !== "function" ) {
189        /**
190         * Look up address and pass latitude/longitude co-ordinates to callback
191         * @param object address - with keys such as 'address' (street address), 'city', 'state', 'postcode' etc
192         * @param callable callback
193         */
194        eventorganiserMapsAdapter.openstreetmap.geocoder.prototype.geocode = function ( address, callback ) {
195            jQuery.ajax({
196                url: 'https://nominatim.openstreetmap.org/search',
197                data: {
198                    street: address.address,
199                    city: address.city,
200                    state: address.state,
201                    postalcode: address.postcode,
202                    format: 'json'
203                },
204                success: function( data ) {
205                    var latlng = false;
206                    if ( data.length > 0 ) {
207                        latlng = {
208                            lat: parseFloat( data[0].lat ),
209                            lng: parseFloat( data[0].lon ),
210                        };
211                    }
212                    return callback.call( this, latlng );
213                },
214                dataType: 'json'
215            });
216        };
217    }
218}

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.