PageSourceSearch

https://www.commufa.jp/-/media/Base-Themes/Google-Maps-JS-Connector/Scripts/google-maps-connector.js

js commufa.jp collected 2026-09-24 18:11:01 UTC 12,849 bytes, 361 lines download raw bytes

1XA.connector.mapsConnector = (function ($, document) {
2
3    "use strict";
4
5    var api = {},
6        maps = [],
7        markers = [],
8        map,
9        getMapType,
10        createMarker,
11        infoWindows = [],
12        addMarker,
13        callbacks = [],
14        animationTimeout,
15        loading = false;
16
17    getMapType = function (options) {
18        switch (options.mode) {
19            case 'Roadmap': {
20                return google.maps.MapTypeId.ROADMAP;
21            }
22            case 'Satellite': {
23                return google.maps.MapTypeId.SATELLITE;
24            }
25            case 'Hybrid':{
26                return google.maps.MapTypeId.HYBRID;
27            }
28            default: {
29                return google.maps.MapTypeId.ROADMAP;
30            }
31        }
32    };
33
34    createMarker = function(mapId, data) {
35        var marker;
36        if (data.icon === null) {
37            marker = new google.maps.Marker({
38                position: new google.maps.LatLng(data.latitude, data.longitude),
39                map: maps[mapId],
40                title: data.title
41            });
42        } else {
43            marker = new google.maps.Marker({
44                position: new google.maps.LatLng(data.latitude, data.longitude),
45                map: maps[mapId],
46                title: data.title,
47                icon: data.icon
48            });
49        }
50        if (data.latitude === '' && data.longitude === '') {
51            //if marker doesn't have coordinated then create it but doesn't show it on the map
52            marker.setVisible(false);
53        }
54        return marker;
55    };
56
57    addMarker = function(mapId, marker, data) {
58        //save POI id - this will be used while removing dynamic POIs from the map
59        marker.id = data.id;
60
61        if (markers[mapId]) {
62            markers[mapId].push({ marker: marker, type: data.type});
63        } else {
64            markers[mapId] = [];
65            markers[mapId].push({ marker: marker, type: data.type});
66        }
67    };
68
69    api.loadScript = function(key, callback) {
70        //save each callback and call them all when script will be loaded - protection for loading maps twice
71        callbacks.push(callback);
72
73        if (!loading) {
74            loading = true;
75            var script = document.createElement("script"),
76                src = "https://maps.googleapis.com/maps/api/js?v=3.exp";
77            script.type = "text/javascript";
78            if (typeof key !== "undefined" && key !== "") {
79                src += "&key=" + key + "&v=3.exp&signed_in=false";
80            } else {
81                src += "&signed_in=false";
82            }
83            src += "&libraries=places&callback=XA.connector.mapsConnector.scriptsLoaded";
84            script.src = src;
85            script.onload = function () {
86                console.log("Google loader has been loaded, waiting for maps api");
87            };
88            document.body.appendChild(script);
89        }
90    };
91
92    api.scriptsLoaded = function () {
93        var i, length = callbacks.length;
94        for (i = 0; i < length; i++) {
95            callbacks[i].call();
96        }
97        loading = false;
98    };
99
100    api.showMap = function(mapId, options, viewBounds) {
101        var mapOptions,
102            listener,
103            scrollwheel = options.disableMapZoomOnScroll !== "1",
104            mapDragging = options.disableMapScrolling !== "1";
105
106        if (viewBounds instanceof Array) {
107                mapOptions = {
108                    zoom: options.zoom,
109                    scrollwheel: scrollwheel,
110                    draggable: mapDragging,
111                    center: new google.maps.LatLng(viewBounds[0], viewBounds[1]),
112                    mapTypeId: getMapType(options)
113                };
114                map = new google.maps.Map(document.getElementById(options.canvasId), mapOptions);
115        } else {
116                mapOptions = {
117                    scrollwheel: scrollwheel,
118                    draggable: mapDragging,
119                    mapTypeId: getMapType(options)
120                };
121                map = new google.maps.Map(document.getElementById(options.canvasId), mapOptions);
122                map.fitBounds(viewBounds);
123                if (options.poiCount < 2) {
124                    listener = google.maps.event.addListener(map, "idle", function() { 
125                        if (markers.length > 0 && markers[mapId].length < 2) {
126                            map.setZoom(options.zoom); 
127                            google.maps.event.removeListener(listener); 
128                        }
129                    });
130                }
131        }
132
133        listener = google.maps.event.addListener(map, "zoom_changed", function(a, b, c, d) { 
134            var zoom = map.getZoom();
135            if (zoom < 1) {
136                map.setZoom(1);
137            }
138        });
139
140        maps[mapId] = map;
141    };
142
143    api.renderPoi = function(mapId, data) {
144        var marker = createMarker(mapId, data),
145            key = mapId + "#" + data.id;
146
147        addMarker(mapId, marker, data);
148
149        if (data.html !== "" && data.html !== null) {
150            infoWindows[key] = new google.maps.InfoWindow({
151                content: data.html
152            });
153        }
154
155        if (typeof infoWindows[key] !== "undefined") {
156            (function(currentKey, marker) {
157                google.maps.event.addListener(marker, "click", function() {
158                    for (var key in infoWindows) {
159                        if (infoWindows.hasOwnProperty(key)) {
160                            infoWindows[key].close();
161                        }
162                    }
163                    infoWindows[currentKey].open(maps[mapId], marker);
164                });
165            })(key, marker);
166        }
167    };
168
169    api.renderDynamicPoi = function(mapId, data, getPoiContent) {
170        var marker = createMarker(mapId, data);            
171
172        addMarker(mapId, marker, data);
173
174        google.maps.event.addListener(marker, "click", function () {
175            if (typeof (getPoiContent) === "function") {
176                var poiId = data.id,
177                    poiTypeId = data.poiTypeId,
178                    poiVariantId = data.poiVariantId;
179
180                if (poiVariantId == null) {
181                    return;
182                }
183
184                getPoiContent(poiId, poiTypeId, poiVariantId, function (result) {
185                    if (infoWindows[mapId]) {
186                        infoWindows[mapId].close();
187                    }
188                    infoWindows[mapId] = new google.maps.InfoWindow({
189                        content: result.Html
190                    });
191                    infoWindows[mapId].open(maps[mapId], marker);
192                });
193            }
194        });
195    };
196
197    api.clearMarkers = function(mapId) {
198        var mapMarkers;
199        if (markers.hasOwnProperty(mapId)) {
200            mapMarkers = markers[mapId];
201            for (var i = 0; i < mapMarkers.length; i++) {
202                if (mapMarkers[i].type === "Dynamic") {
203                    mapMarkers[i].marker.setMap(null);
204                }
205            }
206            markers[mapId] = mapMarkers.filter(function (markerData) {
207                if (markerData.type === "Static" || markerData.type === "MyLocation") {
208                    return true;
209                } else {
210                    return false;
211                }
212            });
213        }
214    };
215
216    api.updateMapPosition = function (mapId) {
217        var map = maps[mapId],
218            marker,
219            mapMarkers = [],
220            bounds = new google.maps.LatLngBounds(),
221            i;
222
223        if (markers.hasOwnProperty(mapId)) {
224            mapMarkers = markers[mapId];
225        }
226
227        for (i =0; i < mapMarkers.length; i++) {
228            marker = mapMarkers[i].marker;
229            bounds.extend(new google.maps.LatLng(marker.position.lat(), marker.position.lng()));
230        }
231
232        map.fitBounds(bounds);
233    };
234
235    api.centerMap = function(mapId, data, centerMap, animate) {
236        var map = maps[mapId],
237            mapMarkers = [],
238            animatedMarker;
239
240        if (centerMap) {
241            map.setCenter(new google.maps.LatLng(data.coordinates[0], data.coordinates[1]));
242        }
243
244        if (animate) {
245            if (markers.hasOwnProperty(mapId)) {
246                mapMarkers = markers[mapId];
247            }
248            for (var i = 0; i < mapMarkers.length; i++) {
249                mapMarkers[i].marker.setAnimation(null);
250                if (mapMarkers[i].marker.id === data.id) {
251                    animatedMarker = mapMarkers[i].marker;
252                    mapMarkers[i].marker.setMap(null);
253                }
254            }
255            if (typeof animatedMarker !== "undefined") {
256                animatedMarker.setMap(map);
257                animatedMarker.setAnimation(google.maps.Animation.BOUNCE);
258                animationTimeout = setTimeout(function () {
259                    animatedMarker.setMap(map);
260                }, 2000);
261            }
262        }
263    };
264
265    api.getCentralPoint = function(poisCoords) {
266        var i,
267            poiCoords,
268            count = poisCoords.length,
269            bounds = new google.maps.LatLngBounds();
270
271        for (i = 0; i < count; i++) {
272            poiCoords = poisCoords[i];
273            if (poiCoords.latitude !== "" && poiCoords.longitude !== "") {
274                bounds.extend(new google.maps.LatLng(poiCoords.latitude, poiCoords.longitude));
275            }
276        }
277        return bounds;
278    };
279
280    api.locationAutocomplete = function(queryParams, successCallback, failCallback){
281        var autocomplete = new google.maps.places.AutocompleteService(),
282            maxResults = queryParams.maxResults <= 0 ? 1 : queryParams.maxResults;
283            autocomplete.getQueryPredictions({input : queryParams.text}, function(results){
284                    var predictions = [], length;
285                    if(results != null && results.length) {
286                        length = results.length >= maxResults ? maxResults : results.length;
287
288                        for (var i = 0; i < length; i++) {
289                            predictions.push(_.extend(results[i], {text : results[i].description}));
290                        }
291
292                        successCallback(predictions);
293                    }
294                    else {
295                        failCallback();
296                    }
297            });
298    };
299
300    api.addressLookup = function (queryParams, successCallback, failCallback) {
301        var search,
302            query;
303
304        if(queryParams.hasOwnProperty("place_id")){ //places lookup
305            search = new google.maps.places.PlacesService(typeof map !== "undefined" ? map : new google.maps.Map(document.createElement("div")));
306            search.getDetails({
307                placeId : queryParams["place_id"]
308            }, function(results,status){
309                if (status == google.maps.places.PlacesServiceStatus.OK) {
310                    if(typeof(results) !== "undefined" && typeof(results.geometry.location) !== "undefined"){
311                        successCallback([results.geometry.location.lat(),results.geometry.location.lng()]);
312                        return;
313                    }
314                }
315                failCallback();
316            });
317        }
318        else { //standard lookup
319            query = {
320                address : queryParams.text
321            };
322            search = new google.maps.Geocoder();
323            search.geocode(query, function(results,status){
324                if (status == google.maps.GeocoderStatus.OK) {
325                    if(typeof(results[0]) !== "undefined" && typeof(results[0].geometry.location) !== "undefined"){
326                        successCallback([results[0].geometry.location.lat(),results[0].geometry.location.lng()]);
327                        return;
328                    }
329                }
330                failCallback();
331            });
332        }
333    };
334
335    api.updateMyPoiLocation = function(mapId, coordinates, zoom) {
336        var map = maps[mapId],
337            mapMarkers = [],
338            myLocationMarker;
339
340        if (markers.hasOwnProperty(mapId)) {
341            mapMarkers = markers[mapId];
342            myLocationMarker = mapMarkers.filter(function (marker) {
343                if (marker.type === "MyLocation") {
344                    return true;
345                }
346                return false;
347            });
348            if (myLocationMarker.length > 0) {                
349                myLocationMarker[0].marker.setPosition(new google.maps.LatLng(coordinates[0], coordinates[1]));
350                myLocationMarker[0].marker.setVisible(true);                
351                this.updateMapPosition(mapId);
352                if (typeof zoom !== "undefined") {
353                    map.setZoom(zoom); 
354                }
355            }
356        }
357    };
358
359    return api;
360
361})(jQuery, document);

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.