WME Google Maps

Shows a Google Maps icon in WME bottom right corner. When clicked, opens Google Maps on the same WME location, zoom and language (satellite).

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         WME Google Maps
// @description  Shows a Google Maps icon in WME bottom right corner. When clicked, opens Google Maps on the same WME location, zoom and language (satellite).
// @namespace    https://greasyfork.org/users/gad_m/wme_google_maps
// @version      0.2.14
// @author       gad_m
// @include 	 /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @exclude      https://www.waze.com/user/*editor/*
// @exclude      https://www.waze.com/*/user/*editor/*
// @icon         https://www.google.com/images/branding/product/ico/maps15_bnuw3a_32dp.ico
// ==/UserScript==

/* global W */
/* global jQuery */
/* global OpenLayers */
/* global I18n */

(function() {

    if (typeof W !== 'undefined' && W['userscripts'] && W['userscripts']['state'] && W['userscripts']['state']['isReady']) {
        console.debug('wme-google-maps: WME is ready.');
        init();
    } else {
        console.debug('wme-google-maps: WME is not ready. adding event listener.');
        document.addEventListener("wme-ready", init, {
            once: true,
        });
    }

    function convertZoom(editorZoom) {
        //let newZoom = /* 12 + */ editorZoom;
        let result = editorZoom + 'z';
        console.log('wme-google-maps: convertZoom() converting: ' + editorZoom + ' returning: ' + result);
        return result;
    }

    function convertLocale(editorLocale) {
        // does nothing (for now).
        let result = editorLocale;
        console.log('wme-google-maps: convertLocale() converting: ' + editorLocale + ' returning: ' + result);
        return result;
    }

    function init() {
        console.log('wme-google-maps: init()');
        let controlPermalink = jQuery('.WazeControlPermalink');
        let googleMapsLink = document.createElement('a');
        googleMapsLink.id = 'wme-google-maps-a';
        googleMapsLink.title = 'Google Maps';
        googleMapsLink.style.display = "inline-block";
        googleMapsLink.style.marginRight = "2px";
        googleMapsLink.href = 'https://www.google.com/maps';
        googleMapsLink.target = '_blank';
        let googleMapsDiv = document.createElement('div');
        googleMapsDiv.class = 'icon';
        googleMapsDiv.style.width = "20px";
        googleMapsDiv.style.height = "20px";
        googleMapsDiv.style.backgroundImage = "url(https://www.google.com/images/branding/product/ico/maps15_bnuw3a_32dp.ico)";
        googleMapsDiv.style.backgroundSize = "20px 20px";
        googleMapsLink.appendChild(googleMapsDiv);
        controlPermalink.append(googleMapsLink);
        jQuery('#wme-google-maps-a').click(function () {
            console.log('wme-google-maps: click() map center: ' + W.map.getCenter());
            let centerLonLat = new OpenLayers.LonLat(W.map.getCenter().lon,W.map.getCenter().lat);
            centerLonLat.transform(new OpenLayers.Projection(W['Config'].map['projection']['local']), new OpenLayers.Projection(W['Config'].map['projection'].remote));
            console.log('wme-google-maps: click() centerLonLat: ' + centerLonLat);
            let zoom = convertZoom(parseInt(W.map.getZoom()));
            let locale = convertLocale(I18n.locale);
            let href = 'https://www.google.com/maps/@' + centerLonLat.lat + ',' + centerLonLat.lon + ',' + zoom + '/data=!3m1!1e3?hl=' + locale;
            console.log('wme-google-maps: click() returning: ' + href);
            this.href = href;
        });
        console.log('wme-google-maps: init() done!');
    } // end init()
}.call(this));