Post by floppyrod84
I'd love if this auto-updated. It's no big deal but it'd be nice if it 'just worked'. This script has saved me a million times though, and again, thanks for keeping up with the OS Locator dataset releases :)
floppyrod84
Posts: 2569
Has thanked: 39 times
Been thanked: 40 times
Send a message

Post by gareth71
Looks like WME v2.206 has broken WME OpenData  :(
 
gareth71
Area Manager
Area Manager
Posts: 912
Has thanked: 144 times
Been thanked: 439 times
Send a message

Post by garfyville
Not sure if this helps, but I only get the issue when clicking the "OS OpenData" Link, if I just check the auto-tracking box and then scroll the problem does not present. Refreshing the OSData windows solve the problem for that editing session.
Chrome: 25.0.1364.152 m
OS: Windows 8
garfyville
Posts: 362
Has thanked: 45 times
Been thanked: 62 times
Send a message
Area Manager: East Anglia - Beta: Editor, Android Client
(OnePlus 5, Nexus 9)
https://s.waze.tools/beta.pnghttps://s.waze.tools/s0200.pnghttps://s.waze.tools/c5.png

Post by iainhouse
Twister_UK wrote:...you'd think they would at least give the beta test team a chance to break it before...
It's no different from the release of the new client and all the subsequent problems.

[my worthless opinion] I suspect it's all down to the "Apple Maps effect". People influenced by the bad publicity for Apple looking for an alternative, plus good publicity for Waze and there's suddenly a massive influx of users. I think the company feels under pressure to get the latest updates out there and they're not being careful enough to avoid mistakes - not unlike Apple themselves. [/my worthless opinion]

For what it's worth I understand the pressure. I have spent weeks working on the areas where I went on holiday and where some towns were quite un-navigable. There were practically no users at all there and it was for my own satisfaction. Lately, I've realised I'm providing the first impression for a lot of new users - and I don't want them to go away unhappy.

Good luck with your script hacking. No pressure, but we're all depending on you!
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
dmcconachie wrote:Chrome?
Edit the downloaded file with any text editor then drop it in the extensions tab.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
dmcconachie wrote:
iainhouse wrote:
dmcconachie wrote:Chrome?
Edit the downloaded file with any text editor then drop it in the extensions tab.
Too lazy for that, pretty sure the extension file itself can be edited? Just can't be bothered looking for it. Yes I'm being really lazy tonight.
That alteration works. :D

I would PM it to you except I can't seem to attach a file to a PM. Copy the code below into Notepad (or whatever equivalent you're using) and save it as anything.user.js - then drop the file into the Chrome extensions tab. Or PM me with an email address and I'll send you the file. Or if you're feeling even lazier than that I'll sort out an online support session and install it for you. ;) :ugeek:

Code: Select all

// ==UserScript==
// @name                WME to OS link
// @namespace           http://greasemonkey.chizzum.com
// @description         Integrates OS OpenData lookups into WME
// @include             https://world.waze.com/editor/*
// @include             https://world.waze.com/map-editor/*
// @include             https://descartesw.waze.com/beta/*
// @grant               none
// @version             1.5.1
// ==/UserScript==

// Contains Ordnance Survey data Crown copyright and database right 2012
// Contents of the locatorData_*.js files are derived under the Open Government Licence from the OS Locator dataset

var version = '1.5.1';

var nameAbbreviations = new Array
(
   'Avenue','Ave',
   'Boulevard','Blvd',
   'Broadway','Bdwy',
   'Circus','Cir',
   'Close','Cl',
   'Court','Ct',
   'Crescent','Cr',
   'Drive','Dr',
   'Garden','Gdn',
   'Gardens','Gdns',
   'Green','Gn',
   'Grove','Gr',
   'Lane','Ln',
   'Mount','Mt',
   'Place','Pl',
   'Park','Pk',
   'Ridge','Rdg',
   'Road','Rd',
   'Square','Sq',
   'Street','St',
   'Terrace','Ter',
   'Valley','Val',
   'By-pass','Bypass'
);

var results = -1;
var showOSLResults = false;
var advancedMode = false;
var setClickHandler = false;
var evalString = '';
var loadingMsg = false;
var beta = false;
var mlcDiv;
var oslDiv;
var bbDiv;

//-----------------------------------------------------------------------------------------------------------------------------------------
// all code between here and the next ------------- marker line provided by timbones to replace the unsafeWindow workaround
if ('undefined' == typeof __OSL_PAGE_SCOPE_RUN__)
{
   (
      function page_scope_runner()
      {
         // If we're _not_ already running in the page, grab the full source
         // of this script.
         var my_src = "(" + page_scope_runner.caller.toString() + ")();";

         // Create a script node holding this script, plus a marker that lets us
         // know we are running in the page scope (not the Greasemonkey sandbox).
         // Note that we are intentionally *not* scope-wrapping here.
         var script = document.createElement('script');
         script.setAttribute("type", "text/javascript");
         script.textContent = "var __OSL_PAGE_SCOPE_RUN__ = true;\n" + my_src;

         // Insert the script node into the page, so it will run, and immediately
         // remove it to clean up.  Use setTimeout to force execution "outside" of
         // the user script scope completely.
         setTimeout(function(){document.body.appendChild(script);document.body.removeChild(script);}, 500);
      }
   )();
   // Stop running, because we know Greasemonkey actually runs us in
   // an anonymous wrapper.
   return;
}
//-----------------------------------------------------------------------------------------------------------------------------------------


//-----------------------------------------------------------------------------------------------------------------------------------------
// all code between here and the next ------------- marker line is a stripped down version of the original from Paul Dixon
//
// * GeoTools javascript coordinate transformations
// * http://files.dixo.net/geotools.html
// *
// * This file copyright (c)2005 Paul Dixon (paul@elphin.com)
// *
// * This program is free software; you can redistribute it and/or
// * modify it under the terms of the GNU General Public License
// * as published by the Free Software Foundation; either version 2
// * of the License, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program; if not, write to the Free Software
// * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// *
// * ---------------------------------------------------------------------------
// *
// * Credits
// *
// * The algorithm used by the script for WGS84-OSGB36 conversions is derived
// * from an OSGB spreadsheet (www.gps.gov.uk) with permission. This has been
// * adapted into Perl by Ian Harris, and into PHP by Barry Hunter. Conversion
// * accuracy is in the order of 7m for 90% of Great Britain, and should be
// * be similar to the conversion made by a typical GPSr
// *
// * See accompanying documentation for more information
// * http://files.dixo.net/geotools.html

var northings;
var eastings;
var latitude;
var longitude;

var helmX, helmY, helmZ;
var Pi = 3.14159265358979;

function wgs_to_osgb()
{
	LatLon_to_HelmXYZ();
   var latitude2  = XYZ_to_Lat();
	var longitude2 = Math.atan2(helmY , helmX) * (180 / Pi);
	LatLon_to_OSGrid(latitude2,longitude2);
}

function LatLon_to_HelmXYZ()
{
   var a = 6378137.0;
   var b = 6356752.313;
   var DX = -446.448;
   var DY = 125.157;
   var DZ = -542.060;
   var rotX = -0.1502;
   var rotY = -0.2470;
   var rotZ = -0.8421;
	var sfactor = 20.4894 * 0.000001;

   // perform initial lat-lon to cartesian coordinate translation
   var RadPHI = latitude * (Pi / 180);
   var RadLAM = longitude * (Pi / 180);
   var e2 = (Math.pow(a,2) - Math.pow(b,2)) / Math.pow(a,2);
   var V = a / (Math.sqrt(1 - (e2 * (  Math.pow(Math.sin(RadPHI),2)))));
   var cartX = V * (Math.cos(RadPHI)) * (Math.cos(RadLAM));
   var cartY = V * (Math.cos(RadPHI)) * (Math.sin(RadLAM));
   var cartZ = (V * (1 - e2)) * (Math.sin(RadPHI));

   // Compute Helmert transformed coordinates
	var RadX_Rot = (rotX / 3600) * (Pi / 180);
	var RadY_Rot = (rotY / 3600) * (Pi / 180);
	var RadZ_Rot = (rotZ / 3600) * (Pi / 180);
   helmX = (cartX + (cartX * sfactor) - (cartY * RadZ_Rot) + (cartZ * RadY_Rot) + DX);
	helmY = (cartX * RadZ_Rot) + cartY + (cartY * sfactor) - (cartZ * RadX_Rot) + DY;
	helmZ = (-1 * cartX * RadY_Rot) + (cartY * RadX_Rot) + cartZ + (cartZ * sfactor) + DZ;
}

function XYZ_to_Lat()
{
   var a = 6377563.396;
   var b = 6356256.910;
   var RootXYSqr = Math.sqrt(Math.pow(helmX,2) + Math.pow(helmY,2));
   var e2 = (Math.pow(a,2) - Math.pow(b,2)) / Math.pow(a,2);
   var PHI1 = Math.atan2(helmZ , (RootXYSqr * (1 - e2)) );
   var PHI = Iterate_XYZ_to_Lat(a, e2, PHI1, helmZ, RootXYSqr);
   return PHI * (180 / Pi);
}

function Iterate_XYZ_to_Lat(a, e2, PHI1, Z, RootXYSqr)
{
   var V = a / (Math.sqrt(1 - (e2 * Math.pow(Math.sin(PHI1),2))));
   var PHI2 = Math.atan2((Z + (e2 * V * (Math.sin(PHI1)))) , RootXYSqr);
   while (Math.abs(PHI1 - PHI2) > 0.000000001)
   {
      PHI1 = PHI2;
      V = a / (Math.sqrt(1 - (e2 * Math.pow(Math.sin(PHI1),2))));
      PHI2 = Math.atan2((Z + (e2 * V * (Math.sin(PHI1)))) , RootXYSqr);
   }
   return PHI2;
}

function Marc(bf0, n, PHI0, PHI)
{
   return bf0 * (((1 + n + ((5 / 4) * Math.pow(n,2)) + ((5 / 4) * Math.pow(n,3))) * (PHI - PHI0)) - (((3 * n) + (3 * Math.pow(n,2)) +
          ((21 / 8) * Math.pow(n,3))) * (Math.sin(PHI - PHI0)) * (Math.cos(PHI + PHI0))) + ((((15 / 8) * Math.pow(n,2)) + ((15 / 8) *
          Math.pow(n,3))) * (Math.sin(2 * (PHI - PHI0))) * (Math.cos(2 * (PHI + PHI0)))) - (((35 / 24) * Math.pow(n,3)) *
          (Math.sin(3 * (PHI - PHI0))) * (Math.cos(3 * (PHI + PHI0)))));
}

function LatLon_to_OSGrid(PHI, LAM)
{
   var a = 6377563.396;
   var b = 6356256.910;
   var e0 = 400000;
   var n0 = -100000;
   var f0 = 0.999601272;
   var PHI0 = 49.00000;
   var LAM0 = -2.00000;

   var RadPHI = PHI * (Pi / 180);
   var RadLAM = LAM * (Pi / 180);
   var RadPHI0 = PHI0 * (Pi / 180);
   var RadLAM0 = LAM0 * (Pi / 180);
   var af0 = a * f0;
   var bf0 = b * f0;
   var e2 = (Math.pow(af0,2) - Math.pow(bf0,2)) / Math.pow(af0,2);
   var n = (af0 - bf0) / (af0 + bf0);
   var nu = af0 / (Math.sqrt(1 - (e2 * Math.pow(Math.sin(RadPHI),2) )));
   var rho = (nu * (1 - e2)) / (1 - (e2 * Math.pow(Math.sin(RadPHI),2) ));
   var eta2 = (nu / rho) - 1;
   var p = RadLAM - RadLAM0;
   var M = Marc(bf0, n, RadPHI0, RadPHI);
   var I = M + n0;
   var II = (nu / 2) * (Math.sin(RadPHI)) * (Math.cos(RadPHI));
   var III = ((nu / 24) * (Math.sin(RadPHI)) * (Math.pow(Math.cos(RadPHI),3))) * (5 - (Math.pow(Math.tan(RadPHI),2)) + (9 * eta2));
   var IIIA = ((nu / 720) * (Math.sin(RadPHI)) * (Math.pow(Math.cos(RadPHI),5))) * (61 - (58 * (Math.pow(Math.tan(RadPHI),2))) + (Math.pow(Math.tan(RadPHI),4)));
   var IV = nu * (Math.cos(RadPHI));
   var V = (nu / 6) * ( Math.pow(Math.cos(RadPHI),3)) * ((nu / rho) - (Math.pow(Math.tan(RadPHI),2)));
   var VI = (nu / 120) * (Math.pow(Math.cos(RadPHI),5)) * (5 - (18 * (Math.pow(Math.tan(RadPHI),2))) + (Math.pow(Math.tan(RadPHI),4)) + (14 * eta2) - (58 * (Math.pow(Math.tan(RadPHI),2)) * eta2));
   eastings = Math.round(e0 + (p * IV) + (Math.pow(p,3) * V) + (Math.pow(p,5) * VI));
   northings = Math.round(I + (Math.pow(p,2) * II) + (Math.pow(p,4) * III) + (Math.pow(p,6) * IIIA));
}
//-----------------------------------------------------------------------------------------------------------------------------------------

function caseCorrect(wrongcase)
{
   var loop;
   var correctedCase = '';
   for(loop=0;loop<wrongcase.length;loop++)
   {
      if
      (
         (loop == 0)||
         (wrongcase[loop-1] == ' ')||
         (wrongcase[loop-1] == '(')||
         (wrongcase.substr(loop-3,3) == '-Y-')||
         (wrongcase.substr(loop-4,4) == '-YR-')
      ) correctedCase += wrongcase[loop].toUpperCase();
      else correctedCase += wrongcase[loop].toLowerCase();
   }
   return correctedCase;
}


function wazeifyStreetName(oslName)
{
   var wazeName = '';
   var loop;

   wazeName = caseCorrect(oslName);

   var namePieces = wazeName.split(' ');
   if(namePieces.length > 1)
   {
      var roadType;
      var dirSuffix;
      var thePrefix;
      var namePrefix = '';
      if((namePieces[namePieces.length-1] == 'North')||(namePieces[namePieces.length-1] == 'South')||(namePieces[namePieces.length-1] == 'East')||(namePieces[namePieces.length-1] == 'West'))
      {
         dirSuffix = ' ' + namePieces[namePieces.length-1][0];
         roadType = namePieces[namePieces.length-2];
         if(namePieces.length > 2)
         {
            if(namePieces[namePieces.length-3] == 'The') thePrefix = true;
            else thePrefix = false;
         }
         for(loop=0;loop<namePieces.length-2;loop++) namePrefix += (namePieces[loop] + ' ');
      }
      else
      {
         dirSuffix = '';
         roadType = namePieces[namePieces.length-1];
         if(namePieces[namePieces.length-2] == 'The') thePrefix = true;
         else thePrefix = false;
         for(loop=0;loop<namePieces.length-1;loop++) namePrefix += (namePieces[loop] + ' ');

      }
      if(thePrefix == false)
      {
         // replace road type with abbreviated form
         for(loop=0;loop<nameAbbreviations.length;loop+=2)
         {
            if(roadType.indexOf(nameAbbreviations[loop]) != -1)
            {
               // make sure the type string we've found comes at the end of the name string, or is suffixed with a space.  If it
               // isn't, then we've actually found a type match within a longer string segment (e.g. The Parkside) and so we
               // should leave it alone...
               if((roadType.length == nameAbbreviations[loop].length) || (roadType[nameAbbreviations[loop].length+1] == ' '))
               {
                  roadType = roadType.replace(nameAbbreviations[loop],nameAbbreviations[loop+1]);
               }
            }
         }
      }
      wazeName = namePrefix + roadType + dirSuffix;
   }
   return wazeName;
}


function cpDistance(cpE, cpN, posE, posN)
{
   return Math.sqrt(((posE - cpE) * (posE - cpE)) + ((posN - cpN) * (posN - cpN)));
}


var vpLeft = 0;
var vpRight = 0;
var vpBottom = 0;
var vpTop = 0;

function visualiseBoundingBox(boxW, boxE, boxS, boxN)
{
   if(boxW < vpLeft) boxW = vpLeft;
   if(boxE >  vpRight) boxE = vpRight;
   if(boxS < vpBottom) boxS = vpBottom;
   if(boxN > vpTop) boxN = vpTop;

   boxE -= vpLeft;
   boxW -= vpLeft;
   boxS = vpTop - boxS;
   boxN = vpTop - boxN;

   var wmeScale = 22550 / (950 * Math.pow(2,sessionStorage.zoom));
   boxE /= wmeScale;
   boxW /= wmeScale;
   boxS /= wmeScale;
   boxN /= wmeScale;

   var boxToleranceWidth = ((boxE - boxW) * 0.05);
   var boxToleranceHeight = ((boxS - boxN) * 0.05);

   boxW -= boxToleranceWidth;
   boxE += boxToleranceWidth;
   boxS += boxToleranceHeight;
   boxN -= boxToleranceHeight;

   boxE = Math.round(boxE);
   boxW = Math.round(boxW);
   boxS = Math.round(boxS);
   boxN = Math.round(boxN);

   // extend width/height of box if the calculated dimension is too small for the box to be readily visible
   if(boxE-boxW < 20)
   {
      boxE += 10;
      boxW -= 10;
   }
   if(boxS-boxN < 20)
   {
      boxS += 10;
      boxN -= 10;
   }

   var svgSrc = '<svg xmlns="http://www.w3.org/2000/svg" width="'+document.getElementById('WazeMap').offsetWidth+'px" height="'+document.getElementById('WazeMap').offsetHeight+'px" version="1.1">';
   svgSrc += '<rect x="'+boxW+'" y="'+boxN+'" width="'+(boxE-boxW)+'" height="'+(boxS-boxN)+'" style="fill:yellow;stroke:pink;stroke-width:4;fill-opacity:0.25;stroke-opacity:0.25"/>';
   svgSrc += '</svg>';
   bbDiv.innerHTML = svgSrc;
}


function radioClick()
{
   var oslElements = document.getElementById('oslDiv');
   for(var loop=0;loop<oslElements.childNodes.length;loop++)
   {
      if(oslElements.childNodes[loop].nodeType == 1)
      {
         attr = oslElements.childNodes[loop].attributes.getNamedItem("type");
         if(attr != null)
         {
            if(attr.value == "radio")
            {
               if(oslElements.childNodes[loop].checked)
               {
                  attr = oslElements.childNodes[loop].attributes.getNamedItem("id").value;
                  if(attr.indexOf('oslID_') == 0)
                  {
                     var roadData = '';
                     oslID = attr.split('_');
                     if(oslID[1] != 'null')
                     {
                        evalstr = 'roadData = locatorData_'+oslID[1]+'_'+oslID[2]+'['+oslID[3]+']';
                        eval(evalstr);
                     }
                     else
                     {
                        roadData = "null:null";
                     }
                     var locatorElements = roadData.split(":");
                     if(locatorElements[0] != 'null')
                     {
                        visualiseBoundingBox(locatorElements[4],locatorElements[5],locatorElements[6],locatorElements[7])
                     }
                     else
                     {
                        bbDiv.innerHTML = '';
                     }
                     return;
                  }
               }
            }
         }
      }
   }
   bbDiv.innerHTML = '';
}


function oslClick()
{
   var cityName = caseCorrect(document.getElementById('myCityName').value);
   if(sessionStorage.myCity == '')
   {
      console.log('WMEOpenData: Update city name position at '+eastings+'x'+northings);
      sessionStorage.cityChangeEastings = eastings;
      sessionStorage.cityChangeNorthings = northings;
   }
   sessionStorage.myCity = cityName;
   var oslElements = document.getElementById('oslDiv');
   for(var loop=0;loop<oslElements.childNodes.length;loop++)
   {
      if(oslElements.childNodes[loop].nodeType == 1)
      {
         attr = oslElements.childNodes[loop].attributes.getNamedItem("type");
         if(attr != null)
         {
            if(attr.value == "radio")
            {
               if(oslElements.childNodes[loop].checked)
               {
                  attr = oslElements.childNodes[loop].attributes.getNamedItem("id").value;
                  if(attr.indexOf('oslID_') == 0)
                  {
                     var roadData = '';
                     oslID = attr.split('_');
                     if(oslID[1] != 'null')
                     {
                        evalstr = 'roadData = locatorData_'+oslID[1]+'_'+oslID[2]+'['+oslID[3]+']';
                        eval(evalstr);
                     }
                     else
                     {
                        roadData = ":";
                     }
                     var locatorElements = roadData.split(":");

                     // auto-click the Edit Address link...
                     if(!beta)
                     {
                        var editAddress = document.getElementById('editSegmentsApplyChanges');
                        var editButtons = editAddress.getElementsByClassName('edit-button');
                     }
                     else
                     {
                        var editAddress = document.getElementById('segment-edit-general');
                        var editButtons = editAddress.getElementsByClassName('address-edit-btn');
                     }

                     editButtons[0].click();

                     // set Country to "United Kingdom" and State to "Other" if they aren't already set to something
                     var snelms = document.getElementsByName('countryID');
                     if(snelms[0].value != 234) snelms[0].value = 234;
                     snelms = document.getElementsByName('stateID');
                     if(snelms[0].value != 99) snelms[0].value = 99;

                     // fill in the City field
                     snelms = document.getElementsByName('cityName');
                     if(document.getElementById('optUseNew').checked == true)
                     {
                        sessionStorage.cityNameRB = 'optUseNew';
                        if(cityName.length > 0)
                        {
                           if(cityName != sessionStorage.prevCityName)
                           {
                              console.log('WMEOpenData: Change of city name at '+eastings+'x'+northings);
                              sessionStorage.cityChangeEastings = eastings;
                              sessionStorage.cityChangeNorthings = northings;
                              sessionStorage.prevCityName = cityName;
                              useName = true;
                           }
                           else
                           {
                              var nameChangeDist = Math.round(cpDistance(eastings,northings,sessionStorage.cityChangeEastings,sessionStorage.cityChangeNorthings));
                              console.log('WMEOpenData: Current name was set '+nameChangeDist+'m away from segment location');
                              var useName = false;
                              if(nameChangeDist > 1000)
                              {
                                 console.log('WMEOpenData: Distance exceeds 1km threshold, name verification required...');
                                 if(confirm('Confirm continued use of this city name'))
                                 {
                                    console.log('WMEOpenData: Confirm city name at '+eastings+'x'+northings);
                                    sessionStorage.cityChangeEastings = eastings;
                                    sessionStorage.cityChangeNorthings = northings;
                                    useName = true;
                                 }
                                 else
                                 {
                                    useName = false;
                                 }
                              }
                              else
                              {
                                 useName = true;
                              }
                           }
                           if(useName)
                           {
                              snelms[0].value = cityName;
                              snelms[0].disabled = false;
                              snelms = document.getElementsByName('emptyCity');
                              snelms[0].checked = false;
                           }
                        }
                     }
                     else if(document.getElementById('optClearExisting').checked == true)
                     {
                        sessionStorage.cityNameRB = 'optClearExisting';
                        snelms[0].disabled = true;
                        snelms = document.getElementsByName('emptyCity');
                        snelms[0].checked = true;
                     }
                     else
                     {
                        sessionStorage.cityNameRB = 'optUseExisting';
                     }

                     // finally the Street field
                     var oslName = locatorElements[1];
                     if((locatorElements[0].length > 0)&&(locatorElements[1].length > 0)) oslName += ' - ';
                     if((oslName.length > 0)||(locatorElements[0].length > 0))
                     {
                        oslName += wazeifyStreetName(locatorElements[0]);
                        snelms = document.getElementsByName('streetName');
                        snelms[0].value = oslName;
                        snelms[0].disabled = false;
                        snelms = document.getElementsByName('emptyStreet');
                        snelms[0].checked = false;
                     }
                     else
                     {
                        snelms = document.getElementsByName('streetName');
                        snelms[0].value = '';
                        snelms[0].disabled = true;
                        snelms = document.getElementsByName('emptyStreet');
                        snelms[0].checked = true;
                     }

                     if(advancedMode)
                     {
                        // auto-click the Apply button...
                        if(!beta)
                        {
                           var applyAddress = document.getElementById('editSegmentsApplyChanges');
                           var applyButtons = applyAddress.getElementsByTagName('input');
                        }
                        else
                        {
                           var applyAddress = document.getElementsByClassName('address-form-actions');
                           var applyButtons = applyAddress[0].getElementsByClassName('btn-primary');
                        }
                        applyButtons[0].click();
                     }
                  }
               }
            }
         }
      }
   }
   toggleOSLPopup();
}


function oslMatch(oslLink, oslArea, oslRadioID)
{
   this.oslLink = oslLink;
   this.oslArea = oslArea;
   this.oslRadioID = oslRadioID;
}


function sortCandidates(a,b)
{
   var x = a.oslArea;
   var y = b.oslArea;
   return((x<y) ? -1 : ((x>y) ? 1 : 0));
}


function toOSGrid(lat, lon, mode)
{
   if(lat != 0)
   {
      latitude = lat;
      longitude = lon;
      wgs_to_osgb();
   }

   if(mode == 1)  // OS Locator lookup
   {
      // determine which 10km grid block contains the current mouse position
      var eBlock = (Math.floor(eastings/10000)) * 10000;
      var nBlock = (Math.floor(northings/10000)) * 10000;
      // check to see if there's a corresponding array in the osl_10km data
      evalString = 'typeof locatorData_'+eBlock+'_'+nBlock;

      if(eval(evalString) == "undefined") // Thanks to Timbones :-)
      {
         // inject 10km block data
         var script = document.createElement("script");
         script.setAttribute('type','text/javascript');
         script.src = 'https://chizzum.com/greasemonkey/osl_v1/locatorData_'+eBlock+'_'+nBlock+'.js';
         document.head.appendChild(script);
         oslDiv.innerHTML = 'Loading new OS data...';
         loadingMsg = true;
      }

      if(eval(evalString) != "undefined")
      {
         // yes...  make a local copy to avoid having an eval() in each iteration of the loop
         evalstr = 'var blockData = locatorData_'+eBlock+'_'+nBlock;
         eval(evalstr);

         var candidates = new Array();
         results = 0;

         candidates[candidates.length++] = new oslMatch('<input type="radio" name="oslChoice" id="oslID_null_null_null"></input>Un-named segment<br>',1000000000000,'oslID_null_null_null');

         for(var loop = 0;loop < blockData.length; loop++)
         {
            // for each entry in the array, test the centrepoint position to see if it lies within the bounding box for that entry
            // note that we allow a 10m tolerance on all sides of the box to allow for inaccuracies in the latlon->gridref conversion,
            // and to increase the chance of a successful match when the road runs E-W or N-S and thus has a long but narrow bounding box
            var locatorElements = blockData[loop].split(":");

            var bbW = parseInt(locatorElements[4])-10;
            var bbE = parseInt(locatorElements[5])+10;
            var bbS = parseInt(locatorElements[6])-10;
            var bbN = parseInt(locatorElements[7])+10;
            if((eastings>=bbW)&&(eastings<=bbE)&&(northings>=bbS)&&(northings<=bbN))
            {
               var radioID = 'oslID_'+eBlock+'_'+nBlock+'_'+loop;
               var oslLink = '<input type="radio" name="oslChoice" id="'+radioID+'"></input>';
               if(locatorElements[1].length > 0)
               {
                  oslLink += locatorElements[1];
                  if(locatorElements[0].length > 0)
                  {
                     oslLink += ' - ';
                  }
               }
               oslLink += wazeifyStreetName(locatorElements[0])+'<br>';
               var area = ((bbE-bbW) * (bbN-bbS));

               candidates[candidates.length++] = new oslMatch(oslLink,area,radioID);
               results++;
            }
         }

         var newHTML = '<b>' + results + ' OSL match';
         if(results != 1) newHTML += 'es';
         newHTML += ' at '+eastings+','+northings+'</b>';
         newHTML += ' <a href="#" id="_hideOSLResults">';
         if(showOSLResults) newHTML += '[hide]';
         else newHTML += '[show]';
         setClickHandler = true;
         newHTML += '</a><br><br>';
         oslDiv.innerHTML = newHTML;

         if(candidates.length > 0)
         {
            if(advancedMode) oslDiv.innerHTML += '<input id="oslSelect" type="button" value="Apply to Properties" /><br><br>';
            else oslDiv.innerHTML += '<input id="oslSelect" type="button" value="Copy to Properties" /><br><br>';
            if(candidates.length > 1) candidates.sort(sortCandidates);
            for(var loop=0;loop<candidates.length;loop++)
            {
               oslDiv.innerHTML += candidates[loop].oslLink;
            }
            oslDiv.innerHTML += '<br>City name:<br>';
            oslDiv.innerHTML += '<input type="radio" name="oslCityNameOpt" id="optUseExisting"/>Use existing name<br>';
            oslDiv.innerHTML += '<input type="radio" name="oslCityNameOpt" id="optClearExisting" />Clear existing name<br>';
            oslDiv.innerHTML += '<input type="radio" name="oslCityNameOpt" id="optUseNew" />Use new name: <input id="myCityName" type="text" value="'+sessionStorage.myCity+'"/><br>';
            document.getElementById('oslSelect').addEventListener("click", oslClick, true);
            for(var loop=0;loop<candidates.length;loop++)
            {
               document.getElementById(candidates[loop].oslRadioID).addEventListener("click", radioClick, true);
            }
            
            document.getElementById(sessionStorage.cityNameRB).checked = true;
         }
      }
   }
   else return '?e='+eastings+'&n='+northings;
}

function processPermalink()
{
   if(!advancedMode) oslEnableAdvancedOptions();

   if(beta) var mousepos = document.getElementById("OpenLayers.Control.MousePosition_27").innerHTML;
   else var mousepos = document.getElementById("OpenLayers.Control.MousePosition_26").innerHTML;

   if((mousepos != sessionStorage.mousepos) || (loadingMsg && (eval(evalString) != "undefined")))
   {
      loadingMsg = false;
      sessionStorage.mousepos = mousepos;

      if(beta) var elementRootContainer = document.getElementById("OpenLayers.Layer.Vector.RootContainer_231");
      else var elementRootContainer = document.getElementById("OpenLayers.Layer.Vector.RootContainer_221");

      a = document.getElementById("_hideOSLResults");
      if((a != null) && setClickHandler)
      {
         a.onclick = toggleOSLPopup;
         setClickHandler = false;
      }

      // no selected segments...
      if(selectionManager.selectedItems.length == 0)
      {
         if
         (
            (elementRootContainer.innerHTML.indexOf('#03b9da') != -1) || // is there a segment highlighted?
            (elementRootContainer.innerHTML.indexOf('#ff3300') != -1)
         )
         {
            // update the OS Locator matches
            mouselatlon = mousepos.split(",");
            toOSGrid(mouselatlon[1],mouselatlon[0],1);
            radioClick();
         }
      }
   }

   // get current lat/lon & zoom level directly from WME (thanks timbones!)
   var lat = sessionStorage.lat;
   var lon = sessionStorage.lon;
   var zoom = sessionStorage.zoom;
   if(wazeMap.center != null)
   {
      var mapCenter = wazeMap.center;
      var geoCenter=new OpenLayers.LonLat(mapCenter.lon,mapCenter.lat);
      geoCenter.transform(new OpenLayers.Projection("EPSG:900913"),new OpenLayers.Projection("EPSG:4326"));
      lat = geoCenter.lat;
      lon = geoCenter.lon;
      zoom = wazeMap.zoom;
   }

   // compare the new parameters against the persistent copies, and update the links to OSMC &
   // OSOD only if there's a change required - the newly-inserted <a> element can't be clicked
   // on until the insertion process is complete, and if we were to re-insert it every timeout
   // then it'd spend a lot of its time giving the appearance of being clickable but without
   // actually doing anything...
   if((zoom != sessionStorage.zoom)||(lat != sessionStorage.lat)||(lon != sessionStorage.lon))
   {
      // update the persistent vars with the new position
      sessionStorage.zoom = zoom;
      sessionStorage.lat = lat;
      sessionStorage.lon = lon;

      // translate the zoom level between WME and Musical Chairs - this gives a pretty close match
      var mczoom = zoom + 12;
      if(mczoom > 18) mczoom = 18;
      // generate the Musical Chairs URL
      var osmc_url = 'http://ris.dev.openstreetmap.org/oslmusicalchairs/map?zoom='+mczoom+'&lat='+lat+'&lon='+lon+'&layers=B0TT&view_mode=pseudorandom';

      // translate the zoom level between WME and OpenData - the match here isn't quite so good...
      var odzoom = zoom + 5;
      if(odzoom < 6) odzoom = 6;
      if(odzoom > 10) odzoom = 10;
      // generate the OpenData URL - requires the support of os_opendata_fullheight.user.js
      var osod_url = 'http://www.ordnancesurvey.co.uk/oswebsite/opendata/viewer/'+toOSGrid(lat,lon,0)+'&z='+odzoom;

      // translate the zoom level between WME and live map.  The only correlation is (WME)=[Live] (0 or 1)=[7], (2 or 3)=[8], (4 or more)=[9]
      var livemap_zoom = Math.floor(zoom/2)+7;
      if (livemap_zoom > 9 ) livemap_zoom = 9;
      var livemap_url = 'https://world.waze.com/livemap/?zoom='+livemap_zoom+'&lat='+lat+'&lon='+lon+'&layers=BTTTT';
      // Modify existing livemap link to reference current position in WME
      document.getElementById("livemap").href = livemap_url;
      document.getElementById("livemap").target = '_blank';

      // update the link URLs
      document.getElementById("_linkOSOD").href = osod_url;
      document.getElementById("_linkOSMC").href = osmc_url;

      // refresh any of the site tabs/windows we've checked for auto-tracking
      if(document.getElementById('_cbAutoTrackOSOD').checked == 1) window.open(osod_url,'_osopendata');
      if(document.getElementById('_cbAutoTrackOSMC').checked == 1) window.open(osmc_url,'_osmusicalchairs');

      // recalculate the map viewport extents in terms of eastings/northings
      var vpHalfWidth = (wazeMap.getExtent().right-wazeMap.getExtent().left) / (2 * 1.61);
      var vpHalfHeight = (wazeMap.getExtent().top-wazeMap.getExtent().bottom) / (2 * 1.61);

      vpLeft = eastings - vpHalfWidth;
      vpRight = eastings + vpHalfWidth;
      vpBottom = northings - vpHalfHeight;
      vpTop = northings + vpHalfHeight;

      radioClick();
   }
}

function minimiseOSLDiv()
{
   var divObj = document.getElementById('oslDiv');
   divObj.style.position = 'static';
   if(beta) divObj.style.height = '22px';
   else divObj.style.height = '16px';
   oslDiv.style.boxShadow = 'none';
   document.getElementById('_hideOSLResults').innerHTML = '[show]';

}

function maximiseOSLDiv()
{
   var divObj = document.getElementById('oslDiv');
   var top = divObj.getBoundingClientRect().top;
   divObj.style.height = 'auto';
   if(beta) top -= (divObj.clientHeight - 26);
   else top -= (divObj.clientHeight - 16);
   if(top < 8) top = 8;
   divObj.style.top =  top + 'px';
   divObj.style.position = 'fixed';
   oslDiv.style.boxShadow = '5px 5px 10px Silver';
   document.getElementById('_hideOSLResults').innerHTML = '[hide]';
}

function toggleOSLPopup()
{
   showOSLResults = !showOSLResults;
   if (!showOSLResults)
   {
      minimiseOSLDiv();
   }
   else
   {
      maximiseOSLDiv();
   }

   return false;
}

function oslEnableAdvancedOptions()
{
   if (advancedMode) return;
   if (loginManager !== null && loginManager.isLoggedIn)
   {
      thisUser = loginManager.user;
      if (thisUser !== null && thisUser.normalizedLevel >= 3)
      {
         advancedMode = true;
         console.log('WMEOpenData: advanced mode enabled');
      }
   }
}

function oslInitialise()
{
   console.log("WMEOpenData: initialisation");
   // initialise persistent vars
   sessionStorage.zoom = 0;
   sessionStorage.lat = '';
   sessionStorage.lon = '';
   sessionStorage.myCity = '';
   sessionStorage.prevCity = '';
   sessionStorage.cityChangeEastings = 0;
   sessionStorage.cityChangeNorthings = 0;
   sessionStorage.cityNameRB = 'optUseExisting';
   sessionStorage.oslTabCreated = 0;

   // Timbones test for new editor...
   beta = (document.getElementById('user-tabs') !== null);

   if(beta) console.log("WMEOpenData: beta editor detected");
   else console.log("WMEOpenData: standard editor detected");

   var elementMapFooter = document.getElementById('map-footer');

   // get the colour attribute for the permalink, so that our new links are visually consistent
   var pl_colour = document.defaultView.getComputedStyle(elementMapFooter,"").getPropertyValue("color");
   // create a new child div in the existing map footer div, so we don't have to borrow the bing attribution one any more...
   mlcDiv = document.createElement('div');
   mlcDiv.setAttribute('id','MapLinkControls');
   // add the anchors and auto-track checkboxes for OS OpenData and Musical Chairs.  Note that the urls are blank at this stage,
   // they'll be filled in as soon as we've done our first processPermalink() call
   if(!beta)
   {
      mlcDiv.innerHTML = '<a href="" id="_linkOSOD" target=_osopendata style="color:' + pl_colour +'">OS OpenData</a> <input type="checkbox" id="_cbAutoTrackOSOD"></input> | ';
      mlcDiv.innerHTML += '<a href="" id="_linkOSMC" target=_osmusicalchairs style="color:' + pl_colour +'">OS Musical Chairs</a> <input type="checkbox" id="_cbAutoTrackOSMC"></input> | ';
      mlcDiv.innerHTML += '<a href="http://userscripts.org/scripts/show/137249" style="color:' + pl_colour +'">WMEOpenData</a> v'+version;
      mlcDiv.innerHTML += '<br>(Checkboxes enable auto-tracking)';
      elementMapFooter.appendChild(mlcDiv);
   }
   else
   {
      mlcDiv.innerHTML = '<a href="http://userscripts.org/scripts/show/137249">WMEOpenData</a> v'+version;
      mlcDiv.innerHTML += '<br><a href="" id="_linkOSOD" target=_osopendata>OS OpenData</a> <input type="checkbox" id="_cbAutoTrackOSOD"></input> | ';
      mlcDiv.innerHTML += '<a href="" id="_linkOSMC" target=_osmusicalchairs">OS Musical Chairs</a> <input type="checkbox" id="_cbAutoTrackOSMC"></input>';
      mlcDiv.innerHTML += '<br>(Checkboxes enable auto-tracking)';
   }

   // add a new div to hold the OS Locator results
   console.log("WMEOpenData: create lookup results DIV");
   oslDiv = document.createElement('div');
   oslDiv.id = "oslDiv";
   oslDiv.style.backgroundColor = '#DDFFDD';
   oslDiv.style.padding = '4px';
   oslDiv.style.border = '1px solid #BBDDBB';
   oslDiv.style.fontSize = '14px';
   oslDiv.style.overflow = 'hidden';
   oslDiv.style.width = 'auto';
   if(beta)
   {
      oslDiv.style.height = '22px';
      document.getElementById('sidebar').appendChild(oslDiv);
      document.getElementById('sidebar').appendChild(mlcDiv);
   }
   else
   {
      oslDiv.style.height = '16px';
      document.getElementById('editPanel').appendChild(oslDiv);
   }

   // add a new div to the map viewport, to hold the bounding box SVG
   var elementWazeMap = document.getElementById('WazeMap');
   console.log("WMEOpenData: create bounding box DIV");
   bbDiv = document.createElement('div');
   bbDiv.id = "bbDiv";
   bbDiv.style.position = 'absolute';
   bbDiv.style.top = '0';
   bbDiv.style.left = '0';
   bbDiv.style.width = elementWazeMap.offsetWidth;
   bbDiv.style.height = elementWazeMap.offsetHeight;
   bbDiv.style.zIndex = 100;
   elementWazeMap.appendChild(bbDiv);

   console.log("WMEOpenData: set onload handler");
   window.addEventListener("load", function(e)
   {
      console.log("WMEOpenData: onload handling");
      oslEnableAdvancedOptions();
   });

   // set up a check for new map co-ords every 100ms
   setInterval(processPermalink,100);
}

oslInitialise();
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
I'm finding that, if I open OS Musical Chairs and check auto-tracking, then every time I pan the WME map, the Musical Chair pops up in a new Chrome window, instead of panning the existing MC tab.

The new window has no controls. I can right-click on the title bar of the window and select "Show as Tab". It then turns into a "normal" Chrome window. From there I can drag the single tab back to my original Chrome Window and it works correctly - ignoring the original MC tab that was created there.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
Twister_UK wrote:...it has now been dispatched to the depths of digital oblivion...
Good Man! I thought I saw it whistle past me on the way down. :D Working fine now.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
Timbones wrote:Bug: when the bounding box disappears, the map 'bounces' as the map briefly acquires a scroll bar (in Chrome).

I keep meaning to post about that, but I don't like to complain! I've seen this as well. When I select one of the radio buttons for a road name, I get horizontal and vertical scroll bars appear in Chrome. If I then click on the map area anywhere, it pan up slightly; then when the bounding box disappears it pans down again. That's the "bounce".

I have discovered that if I click the radio button twice, the horizontal scroll bar disappears again. After that, I don't get the bounce.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
Twister_UK wrote:Just to clarify though, when you're seeing multiple results/bounding boxes for the same stretch of road, it's because the OS data splits roads whenever they cross an administrative boundary, it's nothing to do with the way I've tiled the data into 10km chunks. Knowing when a road crosses one of these boundaries can be useful...
I knew that - and I'm going to ask for a significant editor enhancement: pull out the locality field as well as the road name. I don't necessarily think it should be used to populate the City box - I often see locality names that are meaningless even to local people. However, if I could see the locality name next to the road name in the selection dialogue, it would be very useful as an indicator of when a boundary is passed. Once you see that the locality has changed, it prompts you to check whether you're still using the right city name.

As an example, I'm currently sorting out Petts Wood. The OS locality for those roads is "Petts Wood and Knoll" - which I'm putting in as "Petts Wood" on the segments. As I work my way across the map, it changes to "Bromley Common and Keston". Not only are those 2 separate areas (or will be when I get that far!), but the first few roads in that administrative area are really Petts Wood as far as locals are concerned. Right now, I have to spend a fair amount of time browsing through the OS data to find their boundaries and deciding where the WME boundaries should lie - before switching back to WME and having to remember it.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season