Map Editor Interface and Controls/ZoomLevel: Difference between revisions View history

imported>Deeploz
(replacing https by http in external links (to not display the lock icon))
imported>Deeploz
m (Deeploz moved page Template:ZoomLevel to Map Editor Interface and Controls/ZoomLevel without leaving a redirect: de-templatized to reduce complexity)
Line 1: Line 1:
==Best practices for development of JavaScript extensions==
{| class="wikitable" style="background:none; text-align:center; margin: 1em auto 1em auto" border="1"                                                                          
 
|-
All normal best practice guidelines apply; some references are:
! Zoom Level
* [http://www.javascripttoolbox.com/bestpractices/ JavaScript Toolbox]
! Meter Scale
* [http://sarfraznawaz.wordpress.com/2012/02/19/842/ Sarfraz Ahmed's Blog]
! Foot Scale
 
|-
Run your code through some useful analyzers to head off potential problems, like:
| 10 || 2 || 10
* [http://www.jshint.com JSHint]
|-
* [http://www.jslint.com JSLint]
| 9 || 5 || 10
* [http://developers.google.com/closure/ JavaScript Closure Tools]
|-
 
| 8 || 10 || 20
==jQuery==
|-
WME (''Waze Map Editor'') is built on jQuery. This makes it easy to access and manipulate properties and directly reference the built-in Waze objects underlying WME. Using jQuery enables tighter integration into WME, reduces code, and builds on what is already there.  WME runs jQuery 1.7 vanilla (which does not include any optional modules like jQuery UI).
| 7 || 10 || 50
 
|-
==Prefix for variables and functions==
| 6 || 20 || 100
To ensure that your code is safe from collision with other scripts and extensions, please prefix all variables and functions with a prefix of your choosing (this includes local variables and global variables, since your entire script is made public when it is loaded in WME). An example would be instead of naming a variable "version", name it "coolscript_version" instead, if your script is named "Cool Script".
|-
 
| 5 || 100 || 200
==Code encapsulation==
|-
While not technically code encapsulation in the object oriented sense, please encapsulate all code in a function, except requisite bootstrap code and initializer calls.
| 4 || 100 || 500
 
|-
==UserScript Bootstraping==
| 3 || 200 || 1000
When creating user scripts for Greasemonkey, Chrome, or TamperMonkey, use the following bootstrap at the start of your script. [[User:timbones|timbones]] did extensive research on this to make sure it is completely cross-browser compatible. Not only does it work in GreaseMonkey, Chrome, and TamperMonkey, but can also be dropped into a Safari Extension without any recoding.
|-
 
| 2 || 500 || 2000
<pre style="width:54em;margin-left:-1em;">
|-
function coolscript_bootstrap()
| 1 || 1000 || 5000
{
|-
var bGreasemonkeyServiceDefined    = false;
| 0 || 2000 || 1 mile
 
|-
try
|}
{
if ("object" === typeof Components.interfaces.gmIGreasemonkeyService)
{
bGreasemonkeyServiceDefined = true;
}
}
catch (err)
{
//Ignore.
}
if ( "undefined" === typeof unsafeWindow  || ! bGreasemonkeyServiceDefined)
{
unsafeWindow    = ( function ()
{
var dummyElem  = document.createElement('p');
dummyElem.setAttribute ('onclick', 'return window;');
return dummyElem.onclick ();
} ) ();
}
/* begin running the code! */
coolscript_init();
}
 
function coolscript_init()
{
//run your code here
}
 
// [...]
// then at the end of your script, call the bootstrap to get things started
coolscript_bootstrap();
</pre>

Revision as of 17:27, 25 March 2015

Zoom Level Meter Scale Foot Scale
10 2 10
9 5 10
8 10 20
7 10 50
6 20 100
5 100 200
4 100 500
3 200 1000
2 500 2000
1 1000 5000
0 2000 1 mile