Greasy Fork 还支持 简体中文。

mMR West Bank overlay

Adds a region overlay for the 2018 West Bank (Israel) mMR

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         mMR West Bank overlay
// @namespace    https://greasyfork.org/users/45389
// @version      2018.03.04.001
// @description  Adds a region overlay for the 2018 West Bank (Israel) mMR
// @author       MapOMatic
// @include      /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @license      None!  You may reuse this code for whatever you want.
// ==/UserScript==

(function() {
    'use strict';

    var _fillOpacity = 0.2;
    var _color = "Magenta";
    var _raid_mapLayer;

    function bootstrap() {
        if (W && W.loginManager && W.loginManager.isLoggedIn()) {
            InitMapRaidOverlay();
        } else {
            setTimeout(bootstrap, 500);
        }
    }

    bootstrap();

    function AddRaidPolygon(raidLayer,groupPoints,state1, state2){
        var mro_Map = Waze.map;
        var mro_OL = OpenLayers;

        var style = {
            strokeColor: _color,
            strokeOpacity: 0.30,
            strokeWidth: 3,
            fillColor: _color,
            fillOpacity: _fillOpacity,
            label: state1,
            labelOutlineColor: "Black",
            labelOutlineWidth: 3,
            fontSize: 14,
            fontColor: _color,
            fontOpacity: 0.85,
            fontWeight: "bold"
        };

        var attributes = {
            state1: state1,
            state2: state2
        };

        var pnt= [];
        for(let i=0;i<groupPoints.length;i++){
            let convPoint = new OpenLayers.Geometry.Point(groupPoints[i].lon,groupPoints[i].lat).transform(new OpenLayers.Projection("EPSG:4326"), mro_Map.getProjectionObject());
            pnt.push(convPoint);
        }

        var ring = new mro_OL.Geometry.LinearRing(pnt);
        var polygon = new mro_OL.Geometry.Polygon([ring]);

        var feature = new mro_OL.Feature.Vector(polygon,attributes,style);
        raidLayer.addFeatures([feature]);
    }

    function CurrentRaidLocation(raid_mapLayer){
        var mro_Map = Waze.map;

        var state1Array = [];
        var region = '';
        for(let i=0;i<raid_mapLayer.features.length;i++){
            var raidMapCenter = mro_Map.getCenter();
            var raidCenterPoint = new OpenLayers.Geometry.Point(raidMapCenter.lon,raidMapCenter.lat);
            var raidCenterCheck = raid_mapLayer.features[i].geometry.components[0].containsPoint(raidCenterPoint);

            if(raidCenterCheck === true){
                state1Array.push(raid_mapLayer.features[i].attributes.state1);
                if (!region.length) region = raid_mapLayer.features[i].attributes.state2;
            }
        }
        var label = state1Array.length ? state1Array.join(', ') + ', ' + region : '';
    }

    var _layerVisibleSetting = 'israel-mapraid-2018-visible';
    function loadLayerVisible() {
        var vis = localStorage.getItem(_layerVisibleSetting);
        return vis === null || vis === 'true';
    }
    function saveLayerVisible(value) {
        localStorage.setItem(_layerVisibleSetting, value);
    }
    function onLayerCheckboxChanged(value) {
        saveLayerVisible(value);
        _raid_mapLayer.setVisibility(value);
    }

    function InitMapRaidOverlay(){
        var mro_Map = Waze.map;
        var mro_OL = OpenLayers;
        var visible = loadLayerVisible();

        _raid_mapLayer = new mro_OL.Layer.Vector('Israel 2018 MapRaid', {
            displayInLayerSwitcher: true,
            uniqueName: "_israelMapRaid2018"
        });

        mro_Map.addLayer(_raid_mapLayer);
        _raid_mapLayer.setZIndex(100);
        _raid_mapLayer.setVisibility(visible);
        W.map.events.register("moveend",null,() => CurrentRaidLocation(_raid_mapLayer));

        a1.forEach(state => {
            AddRaidPolygon(_raid_mapLayer, state.coords, '', '');
        });

        CurrentRaidLocation(_raid_mapLayer);

        WazeWrap.Interface.AddLayerCheckbox('Display', 'mMR West Bank', visible, onLayerCheckboxChanged);
    }

    var a1 = [{"coords":[{"lon": "35.52011","lat": "32.4210"},
                         {"lon": "35.22413","lat": "32.55095"},
                         {"lon": "34.93360","lat": "31.34581"},
                         {"lon": "35.38794","lat": "31.34587"},
                         {"lon": "35.52011","lat": "32.42103"}
                        ]
              }];
    })();