WME GIS

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

目前为 2016-07-08 提交的版本,查看 最新版本

// ==UserScript==
// @name          WME GIS
// @author        @Philistine11
// @namespace     https://greasyfork.org/en/users/5380
// @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.0.0
// ==/UserScript==

function gis_bootstrap()
{
    var bGreasemonkeyServiceDefined = false;
    try {
        if ("object" === typeof Components.interfaces.gmIGreasemonkeyService)
            bGreasemonkeyServiceDefined = true;
    } catch (err) {}
    if ( "undefined" === typeof unsafeWindow || ! bGreasemonkeyServiceDefined)
        unsafeWindow = ( function () {
            var dummyElem   = document.createElement('p');
            dummyElem.setAttribute ('onclick', 'return window;');
            return dummyElem.onclick ();
        } ) ();
    gis_init();
}

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>');
    W.map.events.register('moveend', null, function() {
        var center = W.map.getCenter().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
        $.get('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 jurisdiction = "";
                for (var loc = 0; loc < locs.length; loc++) {
                    if (locs[loc].types.indexOf("administrative_area_level_2") != -1) {
                        jurisdiction = locs[loc].long_name;
                        break;
                    } else if (locs[loc].types.indexOf("locality") != -1)
                        jurisdiction = 'City of ' + locs[loc].long_name;
                }
                $('#jurisdiction').text(jurisdiction);
                $('#gis').prop('href', '#').addClass('disabled');

                $.get('https://script.google.com/macros/s/AKfycbzJ3lJbOwaMX7tgRV3e90fbgKccVuKWuHQJmh1twDh2RRhF9OXy/exec', function(data) {
                    for (var row = 1; row < data.length; row++)
                        if (data[row][0] == jurisdiction) {
                            $('#gis').prop('href', data[row][1] + data[row][2].replace('<lat>',center.lat).replace('<lon>',center.lon).replace('<zoom>',W.map.getZoom()+12)).removeClass('disabled');
                            break;
                        }
                });
            }
        });
    });
}

gis_bootstrap();