WME TX FC Map

Open a TX FC map in another window, at the same location as the WME map. Keeps the location of the GIS map synced to WME.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         WME TX FC Map
// @namespace    https://greasyfork.org/users/45389
// @version      0.1
// @description  Open a TX FC  map in another window, at the same location as the WME map.  Keeps the location of the GIS map synced to WME.
// @author       MapOMatic
// @include     /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/.*$/
// @include     /^https:\/\/www\.arcgis\.com\/home\/webmap\/viewer\.html.*/
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    var debugLevel = 0;
    var mapWindow;

    function log(message, level) {
        if (message && level <= debugLevel) {
            console.log('TxDOT-FC:', message);
        }
    }

    function onButtonClick() {
        var wazeExt = W.map.getExtent();
        var url = 'https://www.arcgis.com/home/webmap/viewer.html?useExisting=1&layers=b553554a0a0842928936cf41e0721bc5';
        url += '&extent=' + wazeExt.left + '%2C' + wazeExt.bottom + '%2C' + wazeExt.right + '%2C' + wazeExt.top + '%2C102113';
        if (!mapWindow || mapWindow.closed) {
            setTimeout(function(){mapWindow = window.open(url, '_blank'); syncGISMapExtent();}, 5);
        } else {
            mapWindow.focus();
            syncGISMapExtent();
        }
    }

    function syncGISMapExtent() {
        if (mapWindow && !mapWindow.closed) {
            var wazeExt = W.map.getExtent();
            mapWindow.postMessage({xmin:wazeExt.left, xmax:wazeExt.right, ymin:wazeExt.bottom, ymax:wazeExt.top}, 'https://www.arcgis.com');
        }
    }

    function init() {
        console.log('OK!!!!!!!!!!!!!');
        $('.WazeControlPermalink').prepend(
            $('<div>').css({float:'left',display:'inline-block', padding:'0px 5px 0px 3px'}).append(
                $('<a>',{id:'gis-button',title:'Open the external map in a new window'})
                .text('TxDOT-FC').attr('href','javascript:void(0)')
                .css({float:'left',textDecoration:'none', color:'#000000', fontWeight:'bold'})
                .click(onButtonClick)
            )
        );

        setInterval(function() {
            var $btn = $('#gis-button');
            if ($btn.length > 0) {
                $btn.css('color', (mapWindow && !mapWindow.closed) ? '#1e9d12' : '#000000');
            }
        }, 500);

        /* Event listeners */
        W.map.events.register('moveend',null, syncGISMapExtent);

        log('Initialized.', 1);
    }

    function receiveMessage(event) {
        var extentData = event.data;
        var Extent = unsafeWindow.require('esri/geometry/Extent');
        var SpatialReference = unsafeWindow.require('esri/SpatialReference');
        var map = unsafeWindow.arcgisonline.map.main.map;
        var ext = new Extent({xmin:extentData.xmin, xmax:extentData.xmax, ymin:extentData.ymin, ymax:extentData.ymax, spatialReference:new SpatialReference({wkid:102113})});
        unsafeWindow.arcgisonline.map.main.map.setExtent(ext);
    }

    function bootstrap() {
        if (window.location.host.toLowerCase() === "www.arcgis.com") {
            window.addEventListener("message", receiveMessage, false);
        } else if (W && W.loginManager &&
                   W.loginManager.events.register &&
                   W.map) {
            log('Initializing...', 1);
            init();
        } else {
            log('Bootstrap failed. Trying again...', 1);
            window.setTimeout(function () {
                bootstrap();
            }, 200);
        }
    }

    log('Bootstrap...', 1);
    bootstrap();
})();