WME GIS

Displays the jurisdiction of the current location, and adds a button to open the GIS if available

目前為 2016-07-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          WME GIS
// @author        @Philistine11
// @namespace     https://greasyfork.org/en/users/53803
// @description   Displays the jurisdiction of the current location, and adds a button to open the GIS if available
// @include       https://www.waze.com/editor/*
// @version       1.1.1
// ==/UserScript==

function gis_init() {
    var location = $('div.location-info-region');
    if  (location.length===0) {
        setTimeout(gis_init, 500);
        return;
    }
    location.after('<div style="float:left"><div class="location-info">&nbsp;-&nbsp;<span id="jurisdiction"></span>&nbsp;<a id="gis" class="btn btn-default disabled" style="vertical-align:top" target="_blank" href="#">GIS</a></div></div>');

    var states = {};
    $.getJSON('https://script.google.com/macros/s/AKfycbx2bytvT5Un0TWcaU7BpVkauqeE8zqt8Mek7Zq-OF-bznGYDyZw/exec?link=10dR8z16eKPHeI-ywLcHh2UNS3enQ7gt36Hhzm9nOJbA', function(rows) {
        for (var row in rows)
            states[rows[row][0]] = rows[row][1];
    });

    W.map.events.register('moveend', null, function() {
        var center = W.map.getCenter().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
        $.getJSON('https://maps.googleapis.com/maps/api/geocode/json?latlng='+center.lat+','+center.lon, function(data) {
            if(data.status === "OK"){
                var locs = data.results[0].address_components;
                var state = "";
                var jurisdiction = "";
                for (var loc = 0; loc < locs.length; loc++) {
                    if (locs[loc].types.indexOf("administrative_area_level_1") != -1)
                        state = locs[loc].short_name;
                    else if (locs[loc].types.indexOf("administrative_area_level_2") != -1)
                        jurisdiction = locs[loc].short_name;
                    else if (locs[loc].types.indexOf("locality") != -1 && jurisdiction === "")
                        jurisdiction = 'City of ' + locs[loc].short_name;
                }

                $('#jurisdiction').text(jurisdiction);
                $('#gis').prop('href', '#').addClass('disabled');

                if (states.hasOwnProperty(state)) {
                    $('#gis').removeClass('hidden');
                    $.get('https://script.google.com/macros/s/AKfycbx2bytvT5Un0TWcaU7BpVkauqeE8zqt8Mek7Zq-OF-bznGYDyZw/exec?link='+states[state], function(rows) {
                        for (var row in rows)
                            if (rows[row][0] == jurisdiction) {
                                $('#gis').prop('href', rows[row][1].replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
                                break;
                            }
                    });
                } else
                    $('#gis').addClass('hidden');
            }
        });
    });
}

gis_init();