WME COL Basemap

adds the aerial photos from the col gis as a basemap layer

اعتبارا من 27-10-2022. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         WME COL Basemap
// @namespace    https://fxzfun.com/
// @version      1.0
// @description  adds the aerial photos from the col gis as a basemap layer
// @author       FXZFun
// @match        https://*.waze.com/*/editor*
// @match        https://*.waze.com/editor*
// @match        https://maps.cityoflewisville.com/*
// @exclude      https://*.waze.com/user/editor*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=waze.com
// @grant        GM_setValue
// @grant        GM_getValue
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @license      GNU GPLv3
// ==/UserScript==

/* global W, OL, WazeWrap */

(function() {
    'use strict';

    var errorOccurred;
    var colBasemap;

    function getTicket() {
        document.addEventListener("ticketRetrieved", (e) => {
            GM_setValue("wmecolbasemap-ticket", e.ticket);
            if (location.href.includes("wmecolbasemap")) window.close();
        });

        var script = document.createElement("script");
        script.innerHTML = `
                var ticketUpdated = false;
                const NativeImage = Image;
                const ticketRetrieved = new CustomEvent('ticketRetrieved');

                class FakeImage { constructor(w, h) {
                        const nativeImage = new NativeImage(w, h);
                        const handler = {
                            set: function (obj, prop, value) {
                                if (prop === 'src') {
                                    if (value.includes("nearmap")) {
                                        if (!ticketUpdated) {
                                            ticketUpdated = true;
                                            window.Image = NativeImage;
                                            ticketRetrieved.ticket = value.split("&ticket=")[1];
                                            document.dispatchEvent(ticketRetrieved);
                                        }
                                    }
                                }
                                nativeImage[prop] = value;
                            },
                            get: function(target, prop) {
                                return target[prop];
                            }
                        };
                        return new Proxy(nativeImage, handler);
                    }
                }
                window.Image = FakeImage;`;
        document.body.appendChild(script);
    }

    function addLayer() {
        var ticket = GM_getValue("wmecolbasemap-ticket");
        var date = "20221010"; // changes as aerials get updated

        if (ticket == null) {
            window.open("https://maps.cityoflewisville.com/?&zoom=13&center=33.043,-96.957&basemap=nearmap_"+date+"&wmecolbasemap=true","_blank");
            var ali = setInterval(() => {
                if (GM_getValue("wmecolbasemap-ticket") != null) {
                    return addLayer();
                }
            }, 1000);
        }

        if (colBasemap == null) {
            colBasemap = new OL.Layer.XYZ(
                'COL GIS Basemap',
                "https://us0.nearmap.com/maps/?z=${z}&x=${x}&y=${y}&nml=V&version=2&nmd=" + date + "&ticket=" + ticket,
                {
                    isBaseLayer: false,
                    uniqueName: 'colgis',
                    tileSize: new OL.Size(256,256),
                    transitionEffect: 'resize',
                    displayInLayerSwitcher: true,
                    opacity: 1,
                    visibility: localStorage.hasOwnProperty("wmecolbasemap-visibility") ? localStorage.getItem("wmecolbasemap-visibility") === 'true' : true,
                    tileOptions: {
                        eventListeners: {
                            'loaderror': function(evt) {
                                if (!errorOccurred) {
                                    errorOccurred = true;
                                    window.open("https://maps.cityoflewisville.com/?&zoom=13&center=33.043,-96.957&basemap=nearmap_"+date+"&wmecolbasemap=true","_blank");
                                    var ali = setInterval(() => {
                                        if (GM_getValue("wmecolbasemap-ticket") != null) {
                                            return addLayer();
                                        }
                                    }, 1000);
                                }
                            }
                        }
                    }
                });
            W.map.addLayer(colBasemap);
            W.map.setLayerIndex(colBasemap, 2);
        } else {
            colBasemap.url = "https://us0.nearmap.com/maps/?z=${z}&x=${x}&y=${y}&nml=V&version=2&nmd=" + date + "&ticket=" + ticket;
        }
    }

    function toggleBasemap(value) {
        W.map.getLayerByName("COL GIS Basemap").setVisibility(value);
        localStorage.setItem("wmecolbasemap-visibility", value);
    }

    if (location.href.includes("cityoflewisville.com")) {
        // get ticket
        console.log("WME COL Basemap: Start");
        getTicket();
    } else if (location.href.includes("waze.com")) {
        // load layer
        var wmeI = setInterval(() => {
            if (WazeWrap != null && WazeWrap.Ready) {
                clearInterval(wmeI);
                console.log("WME COL Basemap: Start");
                WazeWrap.Interface.AddLayerCheckbox(
                    "display",
                    "COL GIS Basemap",
                    localStorage.hasOwnProperty("wmecolbasemap-visibility") ? localStorage.getItem("wmecolbasemap-visibility") === 'true' : true,
                    toggleBasemap,
                    W.map.getLayerByName("WME COL Basemap"));
                addLayer();
            }
        }, 500);
    }
})();