Fix lots of EOL SSTyle line ending problems.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6131 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-02-08 19:51:55 +00:00
parent d555835791
commit 6f2a3598be
24 changed files with 3978 additions and 3978 deletions

View File

@@ -1,74 +1,74 @@
/**
* Jugl.js -- JavaScript Template Attribute Language
* This code is not yet licensed for release or distribution.
*
* Copyright 2007 Tim Schaub
*/
/**
* Contains portions of OpenLayers.js -- OpenLayers Map Viewer Library
*
* Copyright 2005-2006 MetaCarta, Inc., released under a modified BSD license.
* Please see http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license.
*/
/**
* Contains portions of Prototype.js:
*
* Prototype JavaScript framework, version 1.4.0
* (c) 2005 Sam Stephenson <sam@conio.net>
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://prototype.conio.net/
*/
(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl={singleFile:true};window[uri]=Jugl;})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var singleFile=(typeof window[uri]=="object"&&window[uri].singleFile);var Jugl={prefix:"jugl",namespaceURI:"http://namespace.jugl.org/",scriptName:(!singleFile)?"lib/Jugl.js":"Jugl.js",getScriptLocation:function(){var scriptLocation="";var scriptName=Jugl.scriptName;var scripts=document.getElementsByTagName('script');for(var i=0;i<scripts.length;i++){var src=scripts[i].getAttribute('src');if(src){var index=src.lastIndexOf(scriptName);if((index>-1)&&(index+scriptName.length==src.length)){scriptLocation=src.slice(0,-scriptName.length);break;}}}
return scriptLocation;}};if(!singleFile){var jsfiles=new Array("Jugl/Util.js","Jugl/Class.js","Jugl/Async.js","Jugl/Node.js","Jugl/Attribute.js","Jugl/Console.js","Jugl/Template.js");var allScriptTags="";var host=Jugl.getScriptLocation()+"lib/";for(var i=0;i<jsfiles.length;i++){if(/MSIE/.test(navigator.userAgent)||/Safari/.test(navigator.userAgent)){var currentScriptTag="<script src='"+host+jsfiles[i]+"'></script>";allScriptTags+=currentScriptTag;}else{var s=document.createElement("script");s.src=host+jsfiles[i];var h=document.getElementsByTagName("head").length?document.getElementsByTagName("head")[0]:document.body;h.appendChild(s);}}
if(allScriptTags){document.write(allScriptTags);}}
window[uri]=Jugl;})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Class=function(){var Class=function(){this.initialize.apply(this,arguments);}
var extended={};var parent;for(var i=0;i<arguments.length;++i){if(typeof arguments[i]=="function"){parent=arguments[i].prototype;}else{parent=arguments[i];}
Jugl.Util.extend(extended,parent);}
Class.prototype=extended;return Class;};})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Util=new Object();Jugl.Util.extend=function(destination,source){for(property in source){destination[property]=source[property];}
return destination;};Jugl.Util.indexOf=function(array,obj){for(var i=0;i<array.length;i++){if(array[i]==obj)return i;}
return-1;};Jugl.Util.bind=function(method,object){var args=[];for(var i=2;i<arguments.length;++i){args.push(arguments[i]);}
return function(){for(var i=0;i<arguments.length;++i){args.push(arguments[i]);}
return method.apply(object,args);}};})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Console={log:function(){},debug:function(){},info:function(){},warn:function(){},error:function(){},assert:function(){},dir:function(){},dirxml:function(){},trace:function(){},group:function(){},groupEnd:function(){},time:function(){},timeEnd:function(){},profile:function(){},profileEnd:function(){},count:function(){}};(function(){if(window.console){var scripts=document.getElementsByTagName("script");for(var i=0;i<scripts.length;++i){if(scripts[i].src.indexOf("firebug.js")!=-1){Jugl.Util.extend(Jugl.Console,console);break;}}}})();})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Attribute=Jugl.Class({node:null,element:null,type:null,nodeValue:null,template:null,initialize:function(node,element,type){this.node=node;this.element=element;this.type=type;this.nodeValue=element.nodeValue;this.nodeName=element.nodeName;this.template=node.template;},splitAttributeValue:function(value){value=(value!=null)?value:this.nodeValue;var matches=this.template.regExes.trimSpace.exec(value);var items;if(matches.length==3){items=[matches[1],matches[2]];}
return items;},getAttributeValues:function(){var trimmed=this.nodeValue.replace(/[\t\n]/g,"").replace(/;\s*$/,"");var tabbed=trimmed.replace(/;;/g,"\t");var newlined=tabbed.split(";").join("\n");return newlined.replace(/\t/g,";").split(/\n/g);},removeSelf:function(){this.node.removeAttributeNode(this);},process:function(){return this.processAttribute[this.type].apply(this,[]);},evalInScope:function(str){var expression="with(this.node.scope){"+str+"}";return eval(expression);},processAttribute:{"define":function(){var values=this.getAttributeValues();var pair;for(var i=0;i<values.length;++i){pair=this.splitAttributeValue(values[i]);this.node.scope[pair[0]]=this.evalInScope(pair[1]);}
this.removeSelf();return true;},"condition":function(){var proceed;try{proceed=!!(this.evalInScope(this.nodeValue));}catch(err){var message=err.name+": "+err.message+"\n";message+="attribute: "+this.nodeName;Jugl.Console.error(message);Jugl.Console.dirxml(this.node.element);Jugl.Console.log(this.node.scope);}
this.removeSelf();if(!proceed){this.node.removeSelf();}
return proceed;},"repeat":function(){var pair=this.splitAttributeValue();var key=pair[0];var list=this.evalInScope(pair[1]);this.removeSelf();if(!(list instanceof Array)){var items=new Array();for(var p in list){items.push(p);}
list=items;}
var node;var previousSibling=this.node;var length=list.length;for(var i=0;i<length;++i){node=this.node.clone();node.scope[key]=list[i];node.scope.repeat[key]={index:i,number:i+1,even:!(i%2),odd:!!(i%2),start:(i==0),end:(i==length-1),length:length};previousSibling.insertAfter(node);node.process();previousSibling=node;}
this.node.removeSelf();return false;},"content":function(){var str;try{str=this.evalInScope(this.nodeValue);}catch(err){Jugl.Console.error("Failed to eval in node scope: "+
this.nodeValue);throw err;}
this.removeSelf();var child=new Jugl.Node(this.template,document.createTextNode(str));this.node.removeChildNodes();this.node.appendChild(child);return true;},"replace":function(){var str;try{str=this.evalInScope(this.nodeValue);}catch(err){Jugl.Console.error("Failed to eval in node scope: "+
this.nodeValue);throw err;}
this.removeSelf();var replacement=new Jugl.Node(this.template,document.createTextNode(str));this.node.insertBefore(replacement);this.node.removeSelf();return true;},"attributes":function(){var values=this.getAttributeValues();var pair,name,value;for(var i=0;i<values.length;++i){pair=this.splitAttributeValue(values[i]);name=pair[0];value=this.evalInScope(pair[1]);if(value!==false){this.node.setAttribute(name,value);}}
this.removeSelf();return true;},"omit-tag":function(){var omit;try{omit=((this.nodeValue=="")||!!(this.evalInScope(this.nodeValue)));}catch(err){Jugl.Console.error("Failed to eval in node scope: "+
this.nodeValue);throw err;}
this.removeSelf();if(omit){var children=this.node.getChildNodes();var child;for(var i=0;i<children.length;++i){this.node.insertBefore(children[i]);}
this.node.removeSelf();}}},CLASS_NAME:"Jugl.Attribute"});})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Template=Jugl.Class({element:null,usingNS:false,xhtmlns:"http://www.w3.org/1999/xhtml",xmldom:null,regExes:null,loaded:false,loading:false,initialize:function(element,options){if(typeof(element)=="string"){element=document.getElementById(element);}
if(element){this.element=element;this.loaded=true;}
this.regExes={trimSpace:(/^\s*(\w+)\s+(.*?)\s*$/)};if(window.ActiveXObject){this.xmldom=new ActiveXObject("Microsoft.XMLDOM");}},process:function(context,clone,toString){if(this.element.getAttributeNodeNS){if(this.element.getAttributeNodeNS(Jugl.xhtmlns,Jugl.prefix)){this.usingNS=true;}}
var node=new Jugl.Node(this,this.element);if(clone){node=node.clone();}
if(context){node.scope=context;}
try{node.process();}catch(err){Jugl.Console.error("Failed to process "+
this.element+" node");}
var data;if(toString){if(node.element.innerHTML){data=node.element.innerHTML;}else{if(this.xmldom){data=node.element.xml;}else{var serializer=new XMLSerializer();data=serializer.serializeToString(node.element);}}}else{data=node.element;}
return data;},load:function(url){this.loading=true;var setElement=function(request){var doc=request.responseXML;this.element=doc.documentElement;this.loading=false;this.loaded=true;this.onLoad();}
Jugl.Async.loadUrl(url,setElement,this);},onLoad:function(){},CLASS_NAME:"Jugl.Template"});})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Node=Jugl.Class({template:null,element:null,scope:null,initialize:function(template,element){this.template=template;this.element=element;this.scope=new Object();this.scope.repeat=new Object();},clone:function(){var element=this.element.cloneNode(true);var node=new Jugl.Node(this.template,element);Jugl.Util.extend(node.scope,this.scope);return node;},getAttribute:function(localName){var element;if(this.element.nodeType==1){if(this.template.usingNS){element=this.element.getAttributeNodeNS(Jugl.namespaceURI,localName);}else{element=this.element.getAttributeNode(Jugl.prefix+":"+
localName);}
if(element&&!element.specified){element=false;}}
var attribute;if(element){attribute=new Jugl.Attribute(this,element,localName);}else{attribute=element;}
return attribute;},setAttribute:function(name,value){this.element.setAttribute(name,value);},removeAttributeNode:function(attribute){this.element.removeAttributeNode(attribute.element);},getChildNodes:function(){var children=[];var node,scope;for(var i=0;i<this.element.childNodes.length;++i){node=new Jugl.Node(this.template,this.element.childNodes[i]);node.scope=Jugl.Util.extend({},this.scope);children.push(node);}
return children;},removeChildNodes:function(){while(this.element.hasChildNodes()){this.element.removeChild(this.element.firstChild);}},removeChild:function(node){this.element.removeChild(node.element);return node;},removeSelf:function(){this.element.parentNode.removeChild(this.element);},appendChild:function(node){this.element.appendChild(node.element);},insertAfter:function(node){var parent=this.element.parentNode;var sibling=this.element.nextSibling;if(sibling){parent.insertBefore(node.element,sibling);}else{parent.appendChild(node.element);}},insertBefore:function(node){var parent=this.element.parentNode;parent.insertBefore(node.element,this.element);},process:function(){var attribute;var keepProcessing=true;var series=["define","condition","repeat"];for(var i=0;i<series.length;++i){attribute=this.getAttribute(series[i]);if(attribute){try{keepProcessing=attribute.process();}catch(err){Jugl.Console.error("Failed to process "+
series[i]+" attribute");throw err;}
if(!keepProcessing){return;}}}
var content=this.getAttribute("content");if(content){try{content.process();}catch(err){Jugl.Console.error("Failed to process content attribute");throw err;}}else{var replace=this.getAttribute("replace");if(replace){try{replace.process();}catch(err){Jugl.Console.error("Failed to process replace attribute");throw err;}}}
var attributes=this.getAttribute("attributes");if(attributes){try{attributes.process();}catch(err){Jugl.Console.error("Failed to process attributes attribute");throw err;}}
if(!content&&!replace){this.processChildNodes();}
var omit=this.getAttribute("omit-tag");if(omit){try{omit.process();}catch(err){Jugl.Console.error("Failed to process omit-tag attribute");throw err;}}},processChildNodes:function(){var element,child;var children=this.getChildNodes();for(var i=0;i<children.length;++i){try{children[i].process();}catch(err){Jugl.Console.error("Failed to process "+
children[i]+" node");throw err;}}},CLASS_NAME:"Jugl.Node"});})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Async={loadTemplate:function(url,onComplete,caller){var createTemplate=function(request){var doc=request.responseXML;var template=new Jugl.Template(doc.documentElement);var complete=Jugl.Util.bind(onComplete,caller);complete(template);}
Jugl.Async.loadUrl(url,createTemplate);},loadUrl:function(url,onComplete,caller){var complete=(caller)?Jugl.Util.bind(onComplete,caller):onComplete;var request=Jugl.Async.createXMLHttpRequest();request.open("GET",url);request.onreadystatechange=function(){if(request.readyState==4){complete(request);}}
/**
* Jugl.js -- JavaScript Template Attribute Language
* This code is not yet licensed for release or distribution.
*
* Copyright 2007 Tim Schaub
*/
/**
* Contains portions of OpenLayers.js -- OpenLayers Map Viewer Library
*
* Copyright 2005-2006 MetaCarta, Inc., released under a modified BSD license.
* Please see http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license.
*/
/**
* Contains portions of Prototype.js:
*
* Prototype JavaScript framework, version 1.4.0
* (c) 2005 Sam Stephenson <sam@conio.net>
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://prototype.conio.net/
*/
(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl={singleFile:true};window[uri]=Jugl;})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var singleFile=(typeof window[uri]=="object"&&window[uri].singleFile);var Jugl={prefix:"jugl",namespaceURI:"http://namespace.jugl.org/",scriptName:(!singleFile)?"lib/Jugl.js":"Jugl.js",getScriptLocation:function(){var scriptLocation="";var scriptName=Jugl.scriptName;var scripts=document.getElementsByTagName('script');for(var i=0;i<scripts.length;i++){var src=scripts[i].getAttribute('src');if(src){var index=src.lastIndexOf(scriptName);if((index>-1)&&(index+scriptName.length==src.length)){scriptLocation=src.slice(0,-scriptName.length);break;}}}
return scriptLocation;}};if(!singleFile){var jsfiles=new Array("Jugl/Util.js","Jugl/Class.js","Jugl/Async.js","Jugl/Node.js","Jugl/Attribute.js","Jugl/Console.js","Jugl/Template.js");var allScriptTags="";var host=Jugl.getScriptLocation()+"lib/";for(var i=0;i<jsfiles.length;i++){if(/MSIE/.test(navigator.userAgent)||/Safari/.test(navigator.userAgent)){var currentScriptTag="<script src='"+host+jsfiles[i]+"'></script>";allScriptTags+=currentScriptTag;}else{var s=document.createElement("script");s.src=host+jsfiles[i];var h=document.getElementsByTagName("head").length?document.getElementsByTagName("head")[0]:document.body;h.appendChild(s);}}
if(allScriptTags){document.write(allScriptTags);}}
window[uri]=Jugl;})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Class=function(){var Class=function(){this.initialize.apply(this,arguments);}
var extended={};var parent;for(var i=0;i<arguments.length;++i){if(typeof arguments[i]=="function"){parent=arguments[i].prototype;}else{parent=arguments[i];}
Jugl.Util.extend(extended,parent);}
Class.prototype=extended;return Class;};})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Util=new Object();Jugl.Util.extend=function(destination,source){for(property in source){destination[property]=source[property];}
return destination;};Jugl.Util.indexOf=function(array,obj){for(var i=0;i<array.length;i++){if(array[i]==obj)return i;}
return-1;};Jugl.Util.bind=function(method,object){var args=[];for(var i=2;i<arguments.length;++i){args.push(arguments[i]);}
return function(){for(var i=0;i<arguments.length;++i){args.push(arguments[i]);}
return method.apply(object,args);}};})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Console={log:function(){},debug:function(){},info:function(){},warn:function(){},error:function(){},assert:function(){},dir:function(){},dirxml:function(){},trace:function(){},group:function(){},groupEnd:function(){},time:function(){},timeEnd:function(){},profile:function(){},profileEnd:function(){},count:function(){}};(function(){if(window.console){var scripts=document.getElementsByTagName("script");for(var i=0;i<scripts.length;++i){if(scripts[i].src.indexOf("firebug.js")!=-1){Jugl.Util.extend(Jugl.Console,console);break;}}}})();})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Attribute=Jugl.Class({node:null,element:null,type:null,nodeValue:null,template:null,initialize:function(node,element,type){this.node=node;this.element=element;this.type=type;this.nodeValue=element.nodeValue;this.nodeName=element.nodeName;this.template=node.template;},splitAttributeValue:function(value){value=(value!=null)?value:this.nodeValue;var matches=this.template.regExes.trimSpace.exec(value);var items;if(matches.length==3){items=[matches[1],matches[2]];}
return items;},getAttributeValues:function(){var trimmed=this.nodeValue.replace(/[\t\n]/g,"").replace(/;\s*$/,"");var tabbed=trimmed.replace(/;;/g,"\t");var newlined=tabbed.split(";").join("\n");return newlined.replace(/\t/g,";").split(/\n/g);},removeSelf:function(){this.node.removeAttributeNode(this);},process:function(){return this.processAttribute[this.type].apply(this,[]);},evalInScope:function(str){var expression="with(this.node.scope){"+str+"}";return eval(expression);},processAttribute:{"define":function(){var values=this.getAttributeValues();var pair;for(var i=0;i<values.length;++i){pair=this.splitAttributeValue(values[i]);this.node.scope[pair[0]]=this.evalInScope(pair[1]);}
this.removeSelf();return true;},"condition":function(){var proceed;try{proceed=!!(this.evalInScope(this.nodeValue));}catch(err){var message=err.name+": "+err.message+"\n";message+="attribute: "+this.nodeName;Jugl.Console.error(message);Jugl.Console.dirxml(this.node.element);Jugl.Console.log(this.node.scope);}
this.removeSelf();if(!proceed){this.node.removeSelf();}
return proceed;},"repeat":function(){var pair=this.splitAttributeValue();var key=pair[0];var list=this.evalInScope(pair[1]);this.removeSelf();if(!(list instanceof Array)){var items=new Array();for(var p in list){items.push(p);}
list=items;}
var node;var previousSibling=this.node;var length=list.length;for(var i=0;i<length;++i){node=this.node.clone();node.scope[key]=list[i];node.scope.repeat[key]={index:i,number:i+1,even:!(i%2),odd:!!(i%2),start:(i==0),end:(i==length-1),length:length};previousSibling.insertAfter(node);node.process();previousSibling=node;}
this.node.removeSelf();return false;},"content":function(){var str;try{str=this.evalInScope(this.nodeValue);}catch(err){Jugl.Console.error("Failed to eval in node scope: "+
this.nodeValue);throw err;}
this.removeSelf();var child=new Jugl.Node(this.template,document.createTextNode(str));this.node.removeChildNodes();this.node.appendChild(child);return true;},"replace":function(){var str;try{str=this.evalInScope(this.nodeValue);}catch(err){Jugl.Console.error("Failed to eval in node scope: "+
this.nodeValue);throw err;}
this.removeSelf();var replacement=new Jugl.Node(this.template,document.createTextNode(str));this.node.insertBefore(replacement);this.node.removeSelf();return true;},"attributes":function(){var values=this.getAttributeValues();var pair,name,value;for(var i=0;i<values.length;++i){pair=this.splitAttributeValue(values[i]);name=pair[0];value=this.evalInScope(pair[1]);if(value!==false){this.node.setAttribute(name,value);}}
this.removeSelf();return true;},"omit-tag":function(){var omit;try{omit=((this.nodeValue=="")||!!(this.evalInScope(this.nodeValue)));}catch(err){Jugl.Console.error("Failed to eval in node scope: "+
this.nodeValue);throw err;}
this.removeSelf();if(omit){var children=this.node.getChildNodes();var child;for(var i=0;i<children.length;++i){this.node.insertBefore(children[i]);}
this.node.removeSelf();}}},CLASS_NAME:"Jugl.Attribute"});})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Template=Jugl.Class({element:null,usingNS:false,xhtmlns:"http://www.w3.org/1999/xhtml",xmldom:null,regExes:null,loaded:false,loading:false,initialize:function(element,options){if(typeof(element)=="string"){element=document.getElementById(element);}
if(element){this.element=element;this.loaded=true;}
this.regExes={trimSpace:(/^\s*(\w+)\s+(.*?)\s*$/)};if(window.ActiveXObject){this.xmldom=new ActiveXObject("Microsoft.XMLDOM");}},process:function(context,clone,toString){if(this.element.getAttributeNodeNS){if(this.element.getAttributeNodeNS(Jugl.xhtmlns,Jugl.prefix)){this.usingNS=true;}}
var node=new Jugl.Node(this,this.element);if(clone){node=node.clone();}
if(context){node.scope=context;}
try{node.process();}catch(err){Jugl.Console.error("Failed to process "+
this.element+" node");}
var data;if(toString){if(node.element.innerHTML){data=node.element.innerHTML;}else{if(this.xmldom){data=node.element.xml;}else{var serializer=new XMLSerializer();data=serializer.serializeToString(node.element);}}}else{data=node.element;}
return data;},load:function(url){this.loading=true;var setElement=function(request){var doc=request.responseXML;this.element=doc.documentElement;this.loading=false;this.loaded=true;this.onLoad();}
Jugl.Async.loadUrl(url,setElement,this);},onLoad:function(){},CLASS_NAME:"Jugl.Template"});})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Node=Jugl.Class({template:null,element:null,scope:null,initialize:function(template,element){this.template=template;this.element=element;this.scope=new Object();this.scope.repeat=new Object();},clone:function(){var element=this.element.cloneNode(true);var node=new Jugl.Node(this.template,element);Jugl.Util.extend(node.scope,this.scope);return node;},getAttribute:function(localName){var element;if(this.element.nodeType==1){if(this.template.usingNS){element=this.element.getAttributeNodeNS(Jugl.namespaceURI,localName);}else{element=this.element.getAttributeNode(Jugl.prefix+":"+
localName);}
if(element&&!element.specified){element=false;}}
var attribute;if(element){attribute=new Jugl.Attribute(this,element,localName);}else{attribute=element;}
return attribute;},setAttribute:function(name,value){this.element.setAttribute(name,value);},removeAttributeNode:function(attribute){this.element.removeAttributeNode(attribute.element);},getChildNodes:function(){var children=[];var node,scope;for(var i=0;i<this.element.childNodes.length;++i){node=new Jugl.Node(this.template,this.element.childNodes[i]);node.scope=Jugl.Util.extend({},this.scope);children.push(node);}
return children;},removeChildNodes:function(){while(this.element.hasChildNodes()){this.element.removeChild(this.element.firstChild);}},removeChild:function(node){this.element.removeChild(node.element);return node;},removeSelf:function(){this.element.parentNode.removeChild(this.element);},appendChild:function(node){this.element.appendChild(node.element);},insertAfter:function(node){var parent=this.element.parentNode;var sibling=this.element.nextSibling;if(sibling){parent.insertBefore(node.element,sibling);}else{parent.appendChild(node.element);}},insertBefore:function(node){var parent=this.element.parentNode;parent.insertBefore(node.element,this.element);},process:function(){var attribute;var keepProcessing=true;var series=["define","condition","repeat"];for(var i=0;i<series.length;++i){attribute=this.getAttribute(series[i]);if(attribute){try{keepProcessing=attribute.process();}catch(err){Jugl.Console.error("Failed to process "+
series[i]+" attribute");throw err;}
if(!keepProcessing){return;}}}
var content=this.getAttribute("content");if(content){try{content.process();}catch(err){Jugl.Console.error("Failed to process content attribute");throw err;}}else{var replace=this.getAttribute("replace");if(replace){try{replace.process();}catch(err){Jugl.Console.error("Failed to process replace attribute");throw err;}}}
var attributes=this.getAttribute("attributes");if(attributes){try{attributes.process();}catch(err){Jugl.Console.error("Failed to process attributes attribute");throw err;}}
if(!content&&!replace){this.processChildNodes();}
var omit=this.getAttribute("omit-tag");if(omit){try{omit.process();}catch(err){Jugl.Console.error("Failed to process omit-tag attribute");throw err;}}},processChildNodes:function(){var element,child;var children=this.getChildNodes();for(var i=0;i<children.length;++i){try{children[i].process();}catch(err){Jugl.Console.error("Failed to process "+
children[i]+" node");throw err;}}},CLASS_NAME:"Jugl.Node"});})();(function(){var uri="http://jugl.tschaub.net/trunk/lib/Jugl.js";var Jugl=window[uri];Jugl.Async={loadTemplate:function(url,onComplete,caller){var createTemplate=function(request){var doc=request.responseXML;var template=new Jugl.Template(doc.documentElement);var complete=Jugl.Util.bind(onComplete,caller);complete(template);}
Jugl.Async.loadUrl(url,createTemplate);},loadUrl:function(url,onComplete,caller){var complete=(caller)?Jugl.Util.bind(onComplete,caller):onComplete;var request=Jugl.Async.createXMLHttpRequest();request.open("GET",url);request.onreadystatechange=function(){if(request.readyState==4){complete(request);}}
request.send(null);},createXMLHttpRequest:function(){if(typeof XMLHttpRequest!="undefined"){return new XMLHttpRequest();}else if(typeof ActiveXObject!="undefined"){return new ActiveXObject("Microsoft.XMLHTTP");}else{throw new Error("XMLHttpRequest not supported");}}};})();

View File

@@ -1,225 +1,225 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Click Handler Example</title>
<style type="text/css">
#map {
width: 340px;
height: 170px;
border: 1px solid gray;
}
#west {
width: 350px;
}
#east {
position: absolute;
left: 370px;
top: 3em;
}
table td {
text-align: center;
margin: 0;
border: 1px solid gray;
}
textarea.output {
text-align: left;
font-size: 0.9em;
width: 250px;
height: 65px;
overflow: auto;
}
</style>
<script src="../lib/Firebug/firebug.js"></script>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.onClick,
'dblclick': this.onDblclick
}, this.handlerOptions
);
},
onClick: function(evt) {
var output = document.getElementById(this.key + "Output");
var msg = "click " + evt.xy;
output.value = output.value + msg + "\r\n";
},
onDblclick: function(evt) {
var output = document.getElementById(this.key + "Output");
var msg = "dblclick " + evt.xy;
output.value = output.value + msg + "\n";
}
});
var map, controls;
function init(){
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}
);
map.addLayers([layer]);
controls = {
"single": new OpenLayers.Control.Click({
hanlerOptions: {
"single": true
}
}),
"double": new OpenLayers.Control.Click({
handlerOptions: {
"single": false,
"double": true
}
}),
"both": new OpenLayers.Control.Click({
handlerOptions: {
"single": true,
"double": true
}
}),
"drag": new OpenLayers.Control.Click({
handlerOptions: {
"single": true,
"pixelTolerance": null
}
}),
"stopsingle": new OpenLayers.Control.Click({
handlerOptions: {
"single": true,
"stopSingle": true
}
}),
"stopdouble": new OpenLayers.Control.Click({
handlerOptions: {
"single": false,
"double": true,
"stopDouble": true
}
})
};
var props = document.getElementById("props");
var control;
for(var key in controls) {
control = controls[key];
// only to route output here
control.key = key;
map.addControl(control);
}
map.zoomToMaxExtent();
}
function toggle(key) {
var control = controls[key];
if(control.active) {
control.deactivate();
} else {
control.activate();
}
var status = document.getElementById(key + "Status");
status.innerHTML = control.active ? "on" : "off";
var output = document.getElementById(key + "Output");
output.value = "";
}
</script>
</head>
<body onload="init()">
<h1 id="title">Click Handler Example</h1>
<div id="west">
<div id="tags">
</div>
<p id="shortdesc">
This example shows the use of the click handler.
</p>
<div id="map"></div>
<p>
The click handler can be used to gain more flexibility over handling
click events. The handler can be constructed with options to handle
only single click events, to handle single and double-click events,
to ignore clicks that include a drag, and to stop propagation of
single and/or double-click events. A single click is a click that
is not followed by another click for more than 300ms. This delay
is configured with the delay property.
</p>
<p>
The options to stop single and double clicks have to do with
stopping event propagation on the map events listener queue
(not stopping events from cascading to other elements). The
ability to stop an event from propagating has to do with the
order in which listeners are registered. With stopSingle or
stopDouble true, a click handler will stop propagation to all
listeners that were registered (or all handlers that were
activated) before the click handler was activated. So, for
example, activating a click handler with stopDouble true after
the navigation control is active will stop double-clicks from
zooming in.
</p>
</div>
<div id="east">
<table>
<caption>Controls with click handlers (toggle on/off to clear output)</caption>
<tbody>
<tr>
<td>single only</td>
<td><button id="singleStatus" onclick="toggle('single')">off</button></td>
<td><textarea class="output" id="singleOutput"></textarea></td>
</tr>
<tr>
<td>double only</td>
<td><button id="doubleStatus" onclick="toggle('double')">off</button></td>
<td><textarea class="output" id="doubleOutput"></textarea></td>
</tr>
<tr>
<td>both</td>
<td><button id="bothStatus" onclick="toggle('both')">off</button></td>
<td><textarea class="output" id="bothOutput"></textarea></td>
</tr>
<tr>
<td>single with drag</td>
<td><button id="dragStatus" onclick="toggle('drag')">off</button></td>
<td><textarea class="output" id="dragOutput"></textarea></td>
</tr>
<tr>
<td>single with stop</td>
<td><button id="stopsingleStatus" onclick="toggle('stopsingle')">off</button></td>
<td><textarea class="output" id="stopsingleOutput"></textarea></td>
</tr>
<tr>
<td>double with stop</td>
<td><button id="stopdoubleStatus" onclick="toggle('stopdouble')">off</button></td>
<td><textarea class="output" id="stopdoubleOutput"></textarea></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Click Handler Example</title>
<style type="text/css">
#map {
width: 340px;
height: 170px;
border: 1px solid gray;
}
#west {
width: 350px;
}
#east {
position: absolute;
left: 370px;
top: 3em;
}
table td {
text-align: center;
margin: 0;
border: 1px solid gray;
}
textarea.output {
text-align: left;
font-size: 0.9em;
width: 250px;
height: 65px;
overflow: auto;
}
</style>
<script src="../lib/Firebug/firebug.js"></script>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.onClick,
'dblclick': this.onDblclick
}, this.handlerOptions
);
},
onClick: function(evt) {
var output = document.getElementById(this.key + "Output");
var msg = "click " + evt.xy;
output.value = output.value + msg + "\r\n";
},
onDblclick: function(evt) {
var output = document.getElementById(this.key + "Output");
var msg = "dblclick " + evt.xy;
output.value = output.value + msg + "\n";
}
});
var map, controls;
function init(){
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}
);
map.addLayers([layer]);
controls = {
"single": new OpenLayers.Control.Click({
hanlerOptions: {
"single": true
}
}),
"double": new OpenLayers.Control.Click({
handlerOptions: {
"single": false,
"double": true
}
}),
"both": new OpenLayers.Control.Click({
handlerOptions: {
"single": true,
"double": true
}
}),
"drag": new OpenLayers.Control.Click({
handlerOptions: {
"single": true,
"pixelTolerance": null
}
}),
"stopsingle": new OpenLayers.Control.Click({
handlerOptions: {
"single": true,
"stopSingle": true
}
}),
"stopdouble": new OpenLayers.Control.Click({
handlerOptions: {
"single": false,
"double": true,
"stopDouble": true
}
})
};
var props = document.getElementById("props");
var control;
for(var key in controls) {
control = controls[key];
// only to route output here
control.key = key;
map.addControl(control);
}
map.zoomToMaxExtent();
}
function toggle(key) {
var control = controls[key];
if(control.active) {
control.deactivate();
} else {
control.activate();
}
var status = document.getElementById(key + "Status");
status.innerHTML = control.active ? "on" : "off";
var output = document.getElementById(key + "Output");
output.value = "";
}
</script>
</head>
<body onload="init()">
<h1 id="title">Click Handler Example</h1>
<div id="west">
<div id="tags">
</div>
<p id="shortdesc">
This example shows the use of the click handler.
</p>
<div id="map"></div>
<p>
The click handler can be used to gain more flexibility over handling
click events. The handler can be constructed with options to handle
only single click events, to handle single and double-click events,
to ignore clicks that include a drag, and to stop propagation of
single and/or double-click events. A single click is a click that
is not followed by another click for more than 300ms. This delay
is configured with the delay property.
</p>
<p>
The options to stop single and double clicks have to do with
stopping event propagation on the map events listener queue
(not stopping events from cascading to other elements). The
ability to stop an event from propagating has to do with the
order in which listeners are registered. With stopSingle or
stopDouble true, a click handler will stop propagation to all
listeners that were registered (or all handlers that were
activated) before the click handler was activated. So, for
example, activating a click handler with stopDouble true after
the navigation control is active will stop double-clicks from
zooming in.
</p>
</div>
<div id="east">
<table>
<caption>Controls with click handlers (toggle on/off to clear output)</caption>
<tbody>
<tr>
<td>single only</td>
<td><button id="singleStatus" onclick="toggle('single')">off</button></td>
<td><textarea class="output" id="singleOutput"></textarea></td>
</tr>
<tr>
<td>double only</td>
<td><button id="doubleStatus" onclick="toggle('double')">off</button></td>
<td><textarea class="output" id="doubleOutput"></textarea></td>
</tr>
<tr>
<td>both</td>
<td><button id="bothStatus" onclick="toggle('both')">off</button></td>
<td><textarea class="output" id="bothOutput"></textarea></td>
</tr>
<tr>
<td>single with drag</td>
<td><button id="dragStatus" onclick="toggle('drag')">off</button></td>
<td><textarea class="output" id="dragOutput"></textarea></td>
</tr>
<tr>
<td>single with stop</td>
<td><button id="stopsingleStatus" onclick="toggle('stopsingle')">off</button></td>
<td><textarea class="output" id="stopsingleOutput"></textarea></td>
</tr>
<tr>
<td>double with stop</td>
<td><button id="stopdoubleStatus" onclick="toggle('stopdouble')">off</button></td>
<td><textarea class="output" id="stopdoubleOutput"></textarea></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

View File

@@ -1,105 +1,105 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Drag Feature Example</title>
<style type="text/css">
#map {
width: 512px;
height: 512px;
border: 1px solid gray;
}
#controls {
width: 512px;
}
#controlToggle {
padding-left: 1em;
}
#controlToggle li {
list-style: none;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wms, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
controls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
line: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Path),
polygon: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Polygon),
drag: new OpenLayers.Control.DragFeature(vectors)
};
for(var key in controls) {
map.addControl(controls[key]);
}
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
}
function toggleControl(element) {
for(key in controls) {
var control = controls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
</script>
</head>
<body onload="init()">
<h1 id="title">Drag Feature Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrates point, line and polygon creation and editing.
</p>
<style type="text/css">
#map {
width: 512px;
height: 512px;
border: 1px solid gray;
}
#controls {
width: 512px;
}
#controlToggle {
padding-left: 1em;
}
#controlToggle li {
list-style: none;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wms, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
controls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
line: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Path),
polygon: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Polygon),
drag: new OpenLayers.Control.DragFeature(vectors)
};
for(var key in controls) {
map.addControl(controls[key]);
}
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
}
function toggleControl(element) {
for(key in controls) {
var control = controls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
</script>
</head>
<body onload="init()">
<h1 id="title">Drag Feature Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrates point, line and polygon creation and editing.
</p>
<div id="map"></div>
<div id="controls">
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="none" id="noneToggle"
onclick="toggleControl(this);" checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" />
<label for="pointToggle">draw point</label>
</li>
<li>
<input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" />
<label for="lineToggle">draw line</label>
</li>
<li>
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
<li>
<input type="radio" name="type" value="drag" id="dragToggle"
onclick="toggleControl(this);" />
<label for="dragToggle">drag feature</label>
</li>
</ul>
</div>
<div id="docs"></div>
</body>
</html>
<div id="controls">
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="none" id="noneToggle"
onclick="toggleControl(this);" checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" />
<label for="pointToggle">draw point</label>
</li>
<li>
<input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" />
<label for="lineToggle">draw line</label>
</li>
<li>
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
<li>
<input type="radio" name="type" value="drag" id="dragToggle"
onclick="toggleControl(this);" />
<label for="dragToggle">drag feature</label>
</li>
</ul>
</div>
<div id="docs"></div>
</body>
</html>

View File

@@ -1,51 +1,51 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Full Screen Example 2</title>
<style type="text/css">
#map {
width: 100%;
height: 100%;
border: 1px solid black;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
map = new OpenLayers.Map('map');
var options = {numZoomLevels: 3};
var docImage = new OpenLayers.Layer.Image(
'Full Screen',
'fullscreen.jpg',
new OpenLayers.Bounds(-156, -90, 156, 90),
new OpenLayers.Size(1121, 650),
options);
map.addLayers([docImage]);
// map.setCenter(new OpenLayers.LonLat(0, 0), 0);
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
<div id="text">
<h1 id="title">Full Screen Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrate a map that fill the entire browser window.
</p>
<div id="docs">
This example uses CSS to define the dimensions of the map element in order to fill the screen.
When the user resizes the window, the map size changes correspondingly. No scroll bars!
</div>
</div>
</body>
</html>
<style type="text/css">
#map {
width: 100%;
height: 100%;
border: 1px solid black;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
map = new OpenLayers.Map('map');
var options = {numZoomLevels: 3};
var docImage = new OpenLayers.Layer.Image(
'Full Screen',
'fullscreen.jpg',
new OpenLayers.Bounds(-156, -90, 156, 90),
new OpenLayers.Size(1121, 650),
options);
map.addLayers([docImage]);
// map.setCenter(new OpenLayers.LonLat(0, 0), 0);
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
<div id="text">
<h1 id="title">Full Screen Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Demonstrate a map that fill the entire browser window.
</p>
<div id="docs">
This example uses CSS to define the dimensions of the map element in order to fill the screen.
When the user resizes the window, the map size changes correspondingly. No scroll bars!
</div>
</div>
</body>
</html>

View File

@@ -1,173 +1,173 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Modify Feature</title>
<style type="text/css">
#map {
width: 512px;
height: 350px;
border: 1px solid gray;
}
#controls {
width: 512px;
}
#controlToggle {
padding-left: 1em;
}
#controlToggle li {
list-style: none;
}
</style>
<script src="../lib/Firebug/firebug.js"></script>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wms, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
var modifyOptions = {
onModificationStart: function(feature) {
OpenLayers.Console.log("start modifying", feature.id);
},
onModification: function(feature) {
OpenLayers.Console.log("modified", feature.id);
},
onModificationEnd: function(feature) {
OpenLayers.Console.log("end modifying", feature.id);
},
onDelete: function(feature) {
OpenLayers.Console.log("delete", feature.id);
}
};
controls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
line: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Path),
polygon: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Polygon),
regular: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.RegularPolygon,
{handlerOptions: {sides: 5}}),
modify: new OpenLayers.Control.ModifyFeature(vectors,
modifyOptions)
};
for(var key in controls) {
map.addControl(controls[key]);
}
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
}
function update() {
// reset modification mode
controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
var rotate = document.getElementById("rotate").checked;
if(rotate) {
controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE;
}
var resize = document.getElementById("resize").checked;
if(resize) {
controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE;
}
var drag = document.getElementById("drag").checked;
if(drag) {
controls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG;
}
// disable reshape mode if at least one of modes rotate, resize,
// drag is enabled
if (rotate || resize || drag) {
controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
}
var sides = parseInt(document.getElementById("sides").value);
sides = Math.max(3, isNaN(sides) ? 0 : sides);
controls.regular.handler.sides = sides;
var irregular = document.getElementById("irregular").checked;
controls.regular.handler.irregular = irregular;
}
function toggleControl(element) {
for(key in controls) {
var control = controls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
</script>
</head>
<body onload="init()">
<h3 id="title">OpenLayers Modify Feature Example</h3>
<div id="shortdesc">A demonstration of the ModifyFeature control for editing vector features.</div>
<div id="map"></div>
<div id="controls">
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="none" id="noneToggle"
onclick="toggleControl(this);" checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" />
<label for="pointToggle">draw point</label>
</li>
<li>
<input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" />
<label for="lineToggle">draw line</label>
</li>
<li>
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
<li>
<input type="radio" name="type" value="regular" id="regularToggle" onclick="toggleControl(this);" />
<label for="regularToggle">draw regular polygon</label>
<label for="sides"> - sides</label>
<input id="sides" type="text" size="2" maxlength="2"
name="sides" value="5" onchange="update()" />
<ul>
<li>
<input id="irregular" type="checkbox"
name="irregular" onchange="update()" />
<label for="irregular">irregular</label>
</li>
</ul>
</li>
<li>
<input type="radio" name="type" value="modify" id="modifyToggle"
onclick="toggleControl(this);" />
<label for="modifyToggle">modify feature</label>
<ul>
<li>
<input id="rotate" type="checkbox"
name="rotate" onchange="update()" />
<label for="rotate">allow rotation</label>
</li>
<li>
<input id="resize" type="checkbox"
name="resize" onchange="update()" />
<label for="resize">allow resizing</label>
</li>
<li>
<input id="drag" type="checkbox"
name="drag" onchange="update()" />
<label for="drag">allow dragging</label>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Modify Feature</title>
<style type="text/css">
#map {
width: 512px;
height: 350px;
border: 1px solid gray;
}
#controls {
width: 512px;
}
#controlToggle {
padding-left: 1em;
}
#controlToggle li {
list-style: none;
}
</style>
<script src="../lib/Firebug/firebug.js"></script>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wms, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
var modifyOptions = {
onModificationStart: function(feature) {
OpenLayers.Console.log("start modifying", feature.id);
},
onModification: function(feature) {
OpenLayers.Console.log("modified", feature.id);
},
onModificationEnd: function(feature) {
OpenLayers.Console.log("end modifying", feature.id);
},
onDelete: function(feature) {
OpenLayers.Console.log("delete", feature.id);
}
};
controls = {
point: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Point),
line: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Path),
polygon: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Polygon),
regular: new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.RegularPolygon,
{handlerOptions: {sides: 5}}),
modify: new OpenLayers.Control.ModifyFeature(vectors,
modifyOptions)
};
for(var key in controls) {
map.addControl(controls[key]);
}
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
}
function update() {
// reset modification mode
controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
var rotate = document.getElementById("rotate").checked;
if(rotate) {
controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE;
}
var resize = document.getElementById("resize").checked;
if(resize) {
controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE;
}
var drag = document.getElementById("drag").checked;
if(drag) {
controls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG;
}
// disable reshape mode if at least one of modes rotate, resize,
// drag is enabled
if (rotate || resize || drag) {
controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
}
var sides = parseInt(document.getElementById("sides").value);
sides = Math.max(3, isNaN(sides) ? 0 : sides);
controls.regular.handler.sides = sides;
var irregular = document.getElementById("irregular").checked;
controls.regular.handler.irregular = irregular;
}
function toggleControl(element) {
for(key in controls) {
var control = controls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
</script>
</head>
<body onload="init()">
<h3 id="title">OpenLayers Modify Feature Example</h3>
<div id="shortdesc">A demonstration of the ModifyFeature control for editing vector features.</div>
<div id="map"></div>
<div id="controls">
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="none" id="noneToggle"
onclick="toggleControl(this);" checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" />
<label for="pointToggle">draw point</label>
</li>
<li>
<input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" />
<label for="lineToggle">draw line</label>
</li>
<li>
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
<li>
<input type="radio" name="type" value="regular" id="regularToggle" onclick="toggleControl(this);" />
<label for="regularToggle">draw regular polygon</label>
<label for="sides"> - sides</label>
<input id="sides" type="text" size="2" maxlength="2"
name="sides" value="5" onchange="update()" />
<ul>
<li>
<input id="irregular" type="checkbox"
name="irregular" onchange="update()" />
<label for="irregular">irregular</label>
</li>
</ul>
</li>
<li>
<input type="radio" name="type" value="modify" id="modifyToggle"
onclick="toggleControl(this);" />
<label for="modifyToggle">modify feature</label>
<ul>
<li>
<input id="rotate" type="checkbox"
name="rotate" onchange="update()" />
<label for="rotate">allow rotation</label>
</li>
<li>
<input id="resize" type="checkbox"
name="resize" onchange="update()" />
<label for="resize">allow resizing</label>
</li>
<li>
<input id="drag" type="checkbox"
name="drag" onchange="update()" />
<label for="drag">allow dragging</label>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>

View File

@@ -1,177 +1,177 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Regular Polygon Example</title>
<style type="text/css">
html, body {
margin: 0;
padding: 1em;
font: 0.9em Verdana, Arial, sans serif;
}
input, select, textarea {
font: 1em Verdana, Arial, sans serif;
}
#map {
width: 512px;
height: 350px;
border: 1px solid gray;
}
p {
width: 512px;
}
#config {
margin-top: 1em;
width: 512px;
position: relative;
height: 8em;
}
#controls {
padding-left: 2em;
margin-left: 0;
width: 12em;
}
#controls li {
padding-top: 0.5em;
list-style: none;
}
#options {
font-size: 1em;
top: 0;
margin-left: 15em;
position: absolute;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, polygonControl;
OpenLayers.Util.onImageLoadErrorColor = "transparent";
function init(){
map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
map.addLayers([wmsLayer, polygonLayer]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
polyOptions = {sides: 4};
polygonControl = new OpenLayers.Control.DrawFeature(polygonLayer,
OpenLayers.Handler.RegularPolygon,
{handlerOptions: polyOptions});
map.addControl(polygonControl);
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
document.getElementById('irregularToggle').checked = false;
}
function setOptions(options) {
polygonControl.handler.setOptions(options);
}
function setSize(fraction) {
var radius = fraction * map.getExtent().getHeight();
polygonControl.handler.setOptions({radius: radius,
angle: 0});
}
</script>
</head>
<body onload="init()">
<h2 id="title">OpenLayers Regular Polygon Example</h2>
<p id="shortdesc">
Shows how to use the RegularPolygon handler to draw features with
different numbers of sides.
</p>
<div id="map"></div>
<div id="config">
<ul id="controls"><b>Map Controls</b>
<li>
<input type="radio" name="type"
value="none" id="noneToggle"
onclick="polygonControl.deactivate()"
checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type"
value="polygon" id="polygonToggle"
onclick="polygonControl.activate()" />
<label for="polygonToggle">draw polygon</label>
</li>
</ul>
<table id="options">
<tbody>
<tr>
<th>Draw Option</th>
<th>Value</th>
</tr>
<tr>
<td>
shape
</td>
<td>
<select name="sides"
onchange="setOptions({sides: parseInt(this.value)})">
<option value="3">triangle</option>
<option value="4" selected="selected">square</option>
<option value="5">pentagon</option>
<option value="6">hexagon</option>
<option value="40">circle</option>
</select>
</td>
</tr>
<tr>
<td>
snap angle
</td>
<td>
<select name="angle"
onchange="setOptions({snapAngle: parseFloat(this.value)})">
<option value="" selected="selected">no snap</option>
<option value="15">15&deg;</option>
<option value="45">45&deg;</option>
<option value="90">90&deg;</option>
</select>
</td>
</tr>
<tr>
<td>
size
</td>
<td>
<select name="size"
onchange="setSize(parseFloat(this.value))">
<option value="" selected="selected">variable</option>
<option value="0.1">small</option>
<option value="0.2">medium</option>
<option value="0.4">large</option>
</select>
</td>
</tr>
<tr>
<td>
irregular
</td>
<td>
<input id="irregularToggle" name="irregular"
type="checkbox"
onchange="setOptions({irregular: this.checked})") />
</td>
</tr>
</tbody>
</table>
</div>
<p>
Regular polygons can be drawn by pointing a DrawFeature control to the
RegularPolygon handler class. The options above demonstrate how the
handler can be configured. Note if you are in angle snapping mode (if
the snap angle is non-null) and you hold down the <b>Shift</b> key, you
will toggle to non-snapping mode.
</p>
<p>
The <i>irregular</i> option allows drawing of irregular polygons. With this option, the fixed radius option is ignored.
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers Regular Polygon Example</title>
<style type="text/css">
html, body {
margin: 0;
padding: 1em;
font: 0.9em Verdana, Arial, sans serif;
}
input, select, textarea {
font: 1em Verdana, Arial, sans serif;
}
#map {
width: 512px;
height: 350px;
border: 1px solid gray;
}
p {
width: 512px;
}
#config {
margin-top: 1em;
width: 512px;
position: relative;
height: 8em;
}
#controls {
padding-left: 2em;
margin-left: 0;
width: 12em;
}
#controls li {
padding-top: 0.5em;
list-style: none;
}
#options {
font-size: 1em;
top: 0;
margin-left: 15em;
position: absolute;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, polygonControl;
OpenLayers.Util.onImageLoadErrorColor = "transparent";
function init(){
map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
map.addLayers([wmsLayer, polygonLayer]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
polyOptions = {sides: 4};
polygonControl = new OpenLayers.Control.DrawFeature(polygonLayer,
OpenLayers.Handler.RegularPolygon,
{handlerOptions: polyOptions});
map.addControl(polygonControl);
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
document.getElementById('noneToggle').checked = true;
document.getElementById('irregularToggle').checked = false;
}
function setOptions(options) {
polygonControl.handler.setOptions(options);
}
function setSize(fraction) {
var radius = fraction * map.getExtent().getHeight();
polygonControl.handler.setOptions({radius: radius,
angle: 0});
}
</script>
</head>
<body onload="init()">
<h2 id="title">OpenLayers Regular Polygon Example</h2>
<p id="shortdesc">
Shows how to use the RegularPolygon handler to draw features with
different numbers of sides.
</p>
<div id="map"></div>
<div id="config">
<ul id="controls"><b>Map Controls</b>
<li>
<input type="radio" name="type"
value="none" id="noneToggle"
onclick="polygonControl.deactivate()"
checked="checked" />
<label for="noneToggle">navigate</label>
</li>
<li>
<input type="radio" name="type"
value="polygon" id="polygonToggle"
onclick="polygonControl.activate()" />
<label for="polygonToggle">draw polygon</label>
</li>
</ul>
<table id="options">
<tbody>
<tr>
<th>Draw Option</th>
<th>Value</th>
</tr>
<tr>
<td>
shape
</td>
<td>
<select name="sides"
onchange="setOptions({sides: parseInt(this.value)})">
<option value="3">triangle</option>
<option value="4" selected="selected">square</option>
<option value="5">pentagon</option>
<option value="6">hexagon</option>
<option value="40">circle</option>
</select>
</td>
</tr>
<tr>
<td>
snap angle
</td>
<td>
<select name="angle"
onchange="setOptions({snapAngle: parseFloat(this.value)})">
<option value="" selected="selected">no snap</option>
<option value="15">15&deg;</option>
<option value="45">45&deg;</option>
<option value="90">90&deg;</option>
</select>
</td>
</tr>
<tr>
<td>
size
</td>
<td>
<select name="size"
onchange="setSize(parseFloat(this.value))">
<option value="" selected="selected">variable</option>
<option value="0.1">small</option>
<option value="0.2">medium</option>
<option value="0.4">large</option>
</select>
</td>
</tr>
<tr>
<td>
irregular
</td>
<td>
<input id="irregularToggle" name="irregular"
type="checkbox"
onchange="setOptions({irregular: this.checked})") />
</td>
</tr>
</tbody>
</table>
</div>
<p>
Regular polygons can be drawn by pointing a DrawFeature control to the
RegularPolygon handler class. The options above demonstrate how the
handler can be configured. Note if you are in angle snapping mode (if
the snap angle is non-null) and you hold down the <b>Shift</b> key, you
will toggle to non-snapping mode.
</p>
<p>
The <i>irregular</i> option allows drawing of irregular polygons. With this option, the fixed radius option is ignored.
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -1,238 +1,238 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt
* for the full text of the license. */
/**
* @requires OpenLayers/Handler.js
*/
/**
* Class: OpenLayers.Handler.Click
* A handler for mouse clicks. The intention of this handler is to give
* controls more flexibility with handling clicks. Browsers trigger
* click events twice for a double-click. In addition, the mousedown,
* mousemove, mouseup sequence fires a click event. With this handler,
* controls can decide whether to ignore clicks associated with a double
* click. By setting a <pixelTolerance>, controls can also ignore clicks
* that include a drag. Create a new instance with the
* <OpenLayers.Handler.Click> constructor.
*
* Inherits from:
* - <OpenLayers.Handler>
*/
OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
/**
* APIProperty: delay
* {Number} Number of milliseconds between clicks before the event is
* considered a double-click.
*/
delay: 300,
/**
* APIProperty: single
* {Boolean} Handle single clicks. Default is true. If false, clicks
* will not be reported. If true, single-clicks will be reported.
*/
single: true,
/**
* APIProperty: double
* {Boolean} Handle double-clicks. Default is false.
*/
'double': false,
/**
* APIProperty: pixelTolerance
* {Number} Maximum number of pixels between mouseup and mousedown for an
* event to be considered a click. Default is 0. If set to an
* integer value, clicks with a drag greater than the value will be
* ignored. This property can only be set when the handler is
* constructed.
*/
pixelTolerance: 0,
/**
* APIProperty: stopSingle
* {Boolean} Stop other listeners from being notified of clicks. Default
* is false. If true, any click listeners registered before this one
* will not be notified of *any* click event (associated with double
* or single clicks).
*/
stopSingle: false,
/**
* APIProperty: stopDouble
* {Boolean} Stop other listeners from being notified of double-clicks.
* Default is false. If true, any click listeners registered before
* this one will not be notified of *any* double-click events.
*
* The one caveat with stopDouble is that given a map with two click
* handlers, one with stopDouble true and the other with stopSingle
* true, the stopSingle handler should be activated last to get
* uniform cross-browser performance. Since IE triggers one click
* with a dblclick and FF triggers two, if a stopSingle handler is
* activated first, all it gets in IE is a single click when the
* second handler stops propagation on the dblclick.
*/
stopDouble: false,
/**
* Property: timerId
* {Number} The id of the timeout waiting to clear the <delayedEvent>.
*/
timerId: null,
/**
* Property: down
* {<OpenLayers.Pixel>} The pixel location of the last mousedown.
*/
down: null,
/**
* Constructor: OpenLayers.Handler.Click
* Create a new click handler.
*
* Parameters:
* control - {<OpenLayers.Control>} The control that is making use of
* this handler. If a handler is being used without a control, the
* handler's setMap method must be overridden to deal properly with
* the map.
* callbacks - {Object} An object with keys corresponding to callbacks
* that will be called by the handler. The callbacks should
* expect to recieve a single argument, the click event.
* Callbacks for 'click' and 'dblclick' are supported.
* options - {Object} Optional object whose properties will be set on the
* handler.
*/
initialize: function(control, callbacks, options) {
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
// optionally register for mouseup and mousedown
if(this.pixelTolerance != null) {
this.mousedown = function(evt) {
this.down = evt.xy;
return true;
};
}
},
/**
* Method: mousedown
* Handle mousedown. Only registered as a listener if pixelTolerance is
* a non-zero value at construction.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
mousedown: null,
/**
* Method: dblclick
* Handle dblclick. For a dblclick, we get two clicks in some browsers
* (FF) and one in others (IE). So we need to always register for
* dblclick to properly handle single clicks.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
dblclick: function(evt) {
if(this.passesTolerance(evt)) {
if(this["double"]) {
this.callback('dblclick', [evt]);
}
this.clearTimer();
}
return !this.stopDouble;
},
/**
* Method: click
* Handle click.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
click: function(evt) {
if(this.passesTolerance(evt)) {
if(this.timerId != null) {
// already received a click
this.clearTimer();
} else {
// set the timer, send evt only if single is true
var clickEvent = this.single ? evt : null;
this.timerId = window.setTimeout(
OpenLayers.Function.bind(this.delayedCall, this, clickEvent),
this.delay
);
}
}
return !this.stopSingle;
},
/**
* Method: passesTolerance
* Determine whether the event is within the optional pixel tolerance. Note
* that the pixel tolerance check only works if mousedown events get to
* the listeners registered here. If they are stopped by other elements,
* the <pixelTolerance> will have no effect here (this method will always
* return true).
*
* Returns:
* {Boolean} The click is within the pixel tolerance (if specified).
*/
passesTolerance: function(evt) {
var passes = true;
if(this.pixelTolerance != null && this.down) {
var dpx = Math.sqrt(
Math.pow(this.down.x - evt.xy.x, 2) +
Math.pow(this.down.y - evt.xy.y, 2)
);
if(dpx > this.pixelTolerance) {
passes = false;
}
}
return passes;
},
/**
* Method: clearTimer
* Clear the timer and set <timerId> to null.
*/
clearTimer: function() {
if(this.timerId != null) {
window.clearTimeout(this.timerId);
this.timerId = null;
}
},
/**
* Method: delayedCall
* Sets <timerId> to null. And optionally triggers the click callback if
* evt is set.
*/
delayedCall: function(evt) {
this.timerId = null;
if(evt) {
this.callback('click', [evt]);
}
},
/**
* APIMethod: deactivate
* Deactivate the handler.
*
* Returns:
* {Boolean} The handler was successfully deactivated.
*/
deactivate: function() {
var deactivated = false;
if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
this.clearTimer();
this.down = null;
deactivated = true;
}
return deactivated;
},
CLASS_NAME: "OpenLayers.Handler.Click"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt
* for the full text of the license. */
/**
* @requires OpenLayers/Handler.js
*/
/**
* Class: OpenLayers.Handler.Click
* A handler for mouse clicks. The intention of this handler is to give
* controls more flexibility with handling clicks. Browsers trigger
* click events twice for a double-click. In addition, the mousedown,
* mousemove, mouseup sequence fires a click event. With this handler,
* controls can decide whether to ignore clicks associated with a double
* click. By setting a <pixelTolerance>, controls can also ignore clicks
* that include a drag. Create a new instance with the
* <OpenLayers.Handler.Click> constructor.
*
* Inherits from:
* - <OpenLayers.Handler>
*/
OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
/**
* APIProperty: delay
* {Number} Number of milliseconds between clicks before the event is
* considered a double-click.
*/
delay: 300,
/**
* APIProperty: single
* {Boolean} Handle single clicks. Default is true. If false, clicks
* will not be reported. If true, single-clicks will be reported.
*/
single: true,
/**
* APIProperty: double
* {Boolean} Handle double-clicks. Default is false.
*/
'double': false,
/**
* APIProperty: pixelTolerance
* {Number} Maximum number of pixels between mouseup and mousedown for an
* event to be considered a click. Default is 0. If set to an
* integer value, clicks with a drag greater than the value will be
* ignored. This property can only be set when the handler is
* constructed.
*/
pixelTolerance: 0,
/**
* APIProperty: stopSingle
* {Boolean} Stop other listeners from being notified of clicks. Default
* is false. If true, any click listeners registered before this one
* will not be notified of *any* click event (associated with double
* or single clicks).
*/
stopSingle: false,
/**
* APIProperty: stopDouble
* {Boolean} Stop other listeners from being notified of double-clicks.
* Default is false. If true, any click listeners registered before
* this one will not be notified of *any* double-click events.
*
* The one caveat with stopDouble is that given a map with two click
* handlers, one with stopDouble true and the other with stopSingle
* true, the stopSingle handler should be activated last to get
* uniform cross-browser performance. Since IE triggers one click
* with a dblclick and FF triggers two, if a stopSingle handler is
* activated first, all it gets in IE is a single click when the
* second handler stops propagation on the dblclick.
*/
stopDouble: false,
/**
* Property: timerId
* {Number} The id of the timeout waiting to clear the <delayedEvent>.
*/
timerId: null,
/**
* Property: down
* {<OpenLayers.Pixel>} The pixel location of the last mousedown.
*/
down: null,
/**
* Constructor: OpenLayers.Handler.Click
* Create a new click handler.
*
* Parameters:
* control - {<OpenLayers.Control>} The control that is making use of
* this handler. If a handler is being used without a control, the
* handler's setMap method must be overridden to deal properly with
* the map.
* callbacks - {Object} An object with keys corresponding to callbacks
* that will be called by the handler. The callbacks should
* expect to recieve a single argument, the click event.
* Callbacks for 'click' and 'dblclick' are supported.
* options - {Object} Optional object whose properties will be set on the
* handler.
*/
initialize: function(control, callbacks, options) {
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
// optionally register for mouseup and mousedown
if(this.pixelTolerance != null) {
this.mousedown = function(evt) {
this.down = evt.xy;
return true;
};
}
},
/**
* Method: mousedown
* Handle mousedown. Only registered as a listener if pixelTolerance is
* a non-zero value at construction.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
mousedown: null,
/**
* Method: dblclick
* Handle dblclick. For a dblclick, we get two clicks in some browsers
* (FF) and one in others (IE). So we need to always register for
* dblclick to properly handle single clicks.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
dblclick: function(evt) {
if(this.passesTolerance(evt)) {
if(this["double"]) {
this.callback('dblclick', [evt]);
}
this.clearTimer();
}
return !this.stopDouble;
},
/**
* Method: click
* Handle click.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
click: function(evt) {
if(this.passesTolerance(evt)) {
if(this.timerId != null) {
// already received a click
this.clearTimer();
} else {
// set the timer, send evt only if single is true
var clickEvent = this.single ? evt : null;
this.timerId = window.setTimeout(
OpenLayers.Function.bind(this.delayedCall, this, clickEvent),
this.delay
);
}
}
return !this.stopSingle;
},
/**
* Method: passesTolerance
* Determine whether the event is within the optional pixel tolerance. Note
* that the pixel tolerance check only works if mousedown events get to
* the listeners registered here. If they are stopped by other elements,
* the <pixelTolerance> will have no effect here (this method will always
* return true).
*
* Returns:
* {Boolean} The click is within the pixel tolerance (if specified).
*/
passesTolerance: function(evt) {
var passes = true;
if(this.pixelTolerance != null && this.down) {
var dpx = Math.sqrt(
Math.pow(this.down.x - evt.xy.x, 2) +
Math.pow(this.down.y - evt.xy.y, 2)
);
if(dpx > this.pixelTolerance) {
passes = false;
}
}
return passes;
},
/**
* Method: clearTimer
* Clear the timer and set <timerId> to null.
*/
clearTimer: function() {
if(this.timerId != null) {
window.clearTimeout(this.timerId);
this.timerId = null;
}
},
/**
* Method: delayedCall
* Sets <timerId> to null. And optionally triggers the click callback if
* evt is set.
*/
delayedCall: function(evt) {
this.timerId = null;
if(evt) {
this.callback('click', [evt]);
}
},
/**
* APIMethod: deactivate
* Deactivate the handler.
*
* Returns:
* {Boolean} The handler was successfully deactivated.
*/
deactivate: function() {
var deactivated = false;
if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
this.clearTimer();
this.down = null;
deactivated = true;
}
return deactivated;
},
CLASS_NAME: "OpenLayers.Handler.Click"
});

View File

@@ -1,393 +1,393 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Handler/Drag.js
*/
/**
* Class: OpenLayers.Handler.RegularPolygon
* Handler to draw a regular polygon on the map. Polygon is displayed on mouse
* down, moves or is modified on mouse move, and is finished on mouse up.
* The handler triggers callbacks for 'done' and 'cancel'. Create a new
* instance with the <OpenLayers.Handler.RegularPolygon> constructor.
*
* Inherits from:
* - <OpenLayers.Handler>
*/
OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
/**
* APIProperty: sides
* {Integer} Number of sides for the regular polygon. Needs to be greater
* than 2. Defaults to 4.
*/
sides: 4,
/**
* APIProperty: radius
* {Float} Optional radius in map units of the regular polygon. If this is
* set to some non-zero value, a polygon with a fixed radius will be
* drawn and dragged with mose movements. If this property is not
* set, dragging changes the radius of the polygon. Set to null by
* default.
*/
radius: null,
/**
* APIProperty: snapAngle
* {Float} If set to a non-zero value, the handler will snap the polygon
* rotation to multiples of the snapAngle. Value is an angle measured
* in degrees counterclockwise from the positive x-axis.
*/
snapAngle: null,
/**
* APIProperty: snapToggle
* {String} If set, snapToggle is checked on mouse events and will set
* the snap mode to the opposite of what it currently is. To disallow
* toggling between snap and non-snap mode, set freehandToggle to
* null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and
* 'altKey'. Snap mode is only possible if this.snapAngle is set to a
* non-zero value.
*/
snapToggle: 'shiftKey',
/**
* APIProperty: persist
* {Boolean} Leave the feature rendered until clear is called. Default
* is false. If set to true, the feature remains rendered until
* clear is called, typically by deactivating the handler or starting
* another drawing.
*/
persist: false,
/**
* APIProperty: irregular
* {Boolean} Draw an irregular polygon instead of a regular polygon.
* Default is false. If true, the initial mouse down will represent
* one corner of the polygon bounds and with each mouse movement, the
* polygon will be stretched so the opposite corner of its bounds
* follows the mouse position. This property takes precedence over
* the radius property. If set to true, the radius property will
* be ignored.
*/
irregular: false,
/**
* Property: angle
* {Float} The angle from the origin (mouse down) to the current mouse
* position, in radians. This is measured counterclockwise from the
* positive x-axis.
*/
angle: null,
/**
* Property: fixedRadius
* {Boolean} The polygon has a fixed radius. True if a radius is set before
* drawing begins. False otherwise.
*/
fixedRadius: false,
/**
* Property: feature
* {<OpenLayers.Feature.Vector>} The currently drawn polygon feature
*/
feature: null,
/**
* Property: layer
* {<OpenLayers.Layer.Vector>} The temporary drawing layer
*/
layer: null,
/**
* Property: origin
* {<OpenLayers.Geometry.Point>} Location of the first mouse down
*/
origin: null,
/**
* Constructor: OpenLayers.Handler.RegularPolygon
* Create a new regular polygon handler.
*
* Parameters:
* control - {<OpenLayers.Control>} The control that owns this handler
* callbacks - {Array} An object with a 'done' property whos value is a
* function to be called when the polygon drawing is finished.
* The callback should expect to recieve a single argument,
* the polygon geometry. If the callbacks object contains a
* 'cancel' property, this function will be called when the
* handler is deactivated while drawing. The cancel should
* expect to receive a geometry.
* options - {Object} An object with properties to be set on the handler.
* If the options.sides property is not specified, the number of sides
* will default to 4.
*/
initialize: function(control, callbacks, options) {
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
OpenLayers.Handler.prototype.initialize.apply(this,
[control, callbacks, options]);
this.options = (options) ? options : new Object();
},
/**
* APIMethod: setOptions
*
* Parameters:
* newOptions - {Object}
*/
setOptions: function (newOptions) {
OpenLayers.Util.extend(this.options, newOptions);
OpenLayers.Util.extend(this, newOptions);
},
/**
* APIMethod: activate
* Turn on the handler.
*
* Return:
* {Boolean} The handler was successfully activated
*/
activate: function() {
var activated = false;
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
// create temporary vector layer for rendering geometry sketch
var options = {displayInLayerSwitcher: false};
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
this.map.addLayer(this.layer);
activated = true;
}
return activated;
},
/**
* APIMethod: deactivate
* Turn off the handler.
*
* Return:
* {Boolean} The handler was successfully deactivated
*/
deactivate: function() {
var deactivated = false;
if(OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) {
// call the cancel callback if mid-drawing
if(this.dragging) {
this.cancel();
}
// If a layer's map property is set to null, it means that that
// layer isn't added to the map. Since we ourself added the layer
// to the map in activate(), we can assume that if this.layer.map
// is null it means that the layer has been destroyed (as a result
// of map.destroy() for example.
if (this.layer.map != null) {
this.layer.destroy(false);
if (this.feature) {
this.feature.destroy();
}
}
this.layer = null;
this.feature = null;
deactivated = true;
}
return deactivated;
},
/**
* Method: downFeature
* Start drawing a new feature
*
* Parameters:
* evt - {Event} The drag start event
*/
down: function(evt) {
this.fixedRadius = !!(this.radius);
var maploc = this.map.getLonLatFromPixel(evt.xy);
this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
// create the new polygon
if(!this.fixedRadius || this.irregular) {
// smallest radius should not be less one pixel in map units
// VML doesn't behave well with smaller
this.radius = this.map.getResolution();
}
if(this.persist) {
this.clear();
}
this.feature = new OpenLayers.Feature.Vector();
this.createGeometry();
this.layer.addFeatures([this.feature], {silent: true});
this.layer.drawFeature(this.feature, this.style);
},
/**
* Method: move
* Respond to drag move events
*
* Parameters:
* evt - {Evt} The move event
*/
move: function(evt) {
var maploc = this.map.getLonLatFromPixel(evt.xy);
var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
if(this.irregular) {
var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2;
this.radius = Math.max(this.map.getResolution() / 2, ry);
} else if(this.fixedRadius) {
this.origin = point;
} else {
this.calculateAngle(point, evt);
this.radius = Math.max(this.map.getResolution() / 2,
point.distanceTo(this.origin));
}
this.modifyGeometry();
if(this.irregular) {
var dx = point.x - this.origin.x;
var dy = point.y - this.origin.y;
var ratio;
if(dy == 0) {
ratio = dx / (this.radius * Math.sqrt(2));
} else {
ratio = dx / dy;
}
this.feature.geometry.resize(1, this.origin, ratio);
this.feature.geometry.move(dx / 2, dy / 2);
}
this.layer.drawFeature(this.feature, this.style);
},
/**
* Method: up
* Finish drawing the feature
*
* Parameters:
* evt - {Event} The mouse up event
*/
up: function(evt) {
this.finalize();
},
/**
* Method: out
* Finish drawing the feature.
*
* Parameters:
* evt - {Event} The mouse out event
*/
out: function(evt) {
this.finalize();
},
/**
* Method: createGeometry
* Create the new polygon geometry. This is called at the start of the
* drag and at any point during the drag if the number of sides
* changes.
*/
createGeometry: function() {
this.angle = Math.PI * ((1/this.sides) - (1/2));
if(this.snapAngle) {
this.angle += this.snapAngle * (Math.PI / 180);
}
this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
this.origin, this.radius, this.sides, this.snapAngle
);
},
/**
* Method: modifyGeometry
* Modify the polygon geometry in place.
*/
modifyGeometry: function() {
var angle, dx, dy, point;
var ring = this.feature.geometry.components[0];
// if the number of sides ever changes, create a new geometry
if(ring.components.length != (this.sides + 1)) {
this.createGeometry();
ring = this.feature.geometry.components[0];
}
for(var i=0; i<this.sides; ++i) {
point = ring.components[i];
angle = this.angle + (i * 2 * Math.PI / this.sides);
point.x = this.origin.x + (this.radius * Math.cos(angle));
point.y = this.origin.y + (this.radius * Math.sin(angle));
point.clearBounds();
}
},
/**
* Method: calculateAngle
* Calculate the angle based on settings.
*
* Parameters:
* point - {<OpenLayers.Geometry.Point>}
* evt - {Event}
*/
calculateAngle: function(point, evt) {
var alpha = Math.atan2(point.y - this.origin.y,
point.x - this.origin.x);
if(this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) {
var snapAngleRad = (Math.PI / 180) * this.snapAngle;
this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad;
} else {
this.angle = alpha;
}
},
/**
* APIMethod: cancel
* Finish the geometry and call the "cancel" callback.
*/
cancel: function() {
// the polygon geometry gets cloned in the callback method
this.callback("cancel", null);
this.finalize();
},
/**
* Method: finalize
* Finish the geometry and call the "done" callback.
*/
finalize: function() {
this.origin = null;
this.radius = this.options.radius;
},
/**
* APIMethod: clear
* Clear any rendered features on the temporary layer. This is called
* when the handler is deactivated, canceled, or done (unless persist
* is true).
*/
clear: function() {
this.layer.renderer.clear();
this.layer.destroyFeatures();
},
/**
* Method: callback
* Trigger the control's named callback with the given arguments
*
* Parameters:
* name - {String} The key for the callback that is one of the properties
* of the handler's callbacks object.
* args - {Array} An array of arguments with which to call the callback
* (defined by the control).
*/
callback: function (name, args) {
// override the callback method to always send the polygon geometry
if (this.callbacks[name]) {
this.callbacks[name].apply(this.control,
[this.feature.geometry.clone()]);
}
// since sketch features are added to the temporary layer
// they must be cleared here if done or cancel
if(!this.persist && (name == "done" || name == "cancel")) {
this.clear();
}
},
CLASS_NAME: "OpenLayers.Handler.RegularPolygon"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Handler/Drag.js
*/
/**
* Class: OpenLayers.Handler.RegularPolygon
* Handler to draw a regular polygon on the map. Polygon is displayed on mouse
* down, moves or is modified on mouse move, and is finished on mouse up.
* The handler triggers callbacks for 'done' and 'cancel'. Create a new
* instance with the <OpenLayers.Handler.RegularPolygon> constructor.
*
* Inherits from:
* - <OpenLayers.Handler>
*/
OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
/**
* APIProperty: sides
* {Integer} Number of sides for the regular polygon. Needs to be greater
* than 2. Defaults to 4.
*/
sides: 4,
/**
* APIProperty: radius
* {Float} Optional radius in map units of the regular polygon. If this is
* set to some non-zero value, a polygon with a fixed radius will be
* drawn and dragged with mose movements. If this property is not
* set, dragging changes the radius of the polygon. Set to null by
* default.
*/
radius: null,
/**
* APIProperty: snapAngle
* {Float} If set to a non-zero value, the handler will snap the polygon
* rotation to multiples of the snapAngle. Value is an angle measured
* in degrees counterclockwise from the positive x-axis.
*/
snapAngle: null,
/**
* APIProperty: snapToggle
* {String} If set, snapToggle is checked on mouse events and will set
* the snap mode to the opposite of what it currently is. To disallow
* toggling between snap and non-snap mode, set freehandToggle to
* null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and
* 'altKey'. Snap mode is only possible if this.snapAngle is set to a
* non-zero value.
*/
snapToggle: 'shiftKey',
/**
* APIProperty: persist
* {Boolean} Leave the feature rendered until clear is called. Default
* is false. If set to true, the feature remains rendered until
* clear is called, typically by deactivating the handler or starting
* another drawing.
*/
persist: false,
/**
* APIProperty: irregular
* {Boolean} Draw an irregular polygon instead of a regular polygon.
* Default is false. If true, the initial mouse down will represent
* one corner of the polygon bounds and with each mouse movement, the
* polygon will be stretched so the opposite corner of its bounds
* follows the mouse position. This property takes precedence over
* the radius property. If set to true, the radius property will
* be ignored.
*/
irregular: false,
/**
* Property: angle
* {Float} The angle from the origin (mouse down) to the current mouse
* position, in radians. This is measured counterclockwise from the
* positive x-axis.
*/
angle: null,
/**
* Property: fixedRadius
* {Boolean} The polygon has a fixed radius. True if a radius is set before
* drawing begins. False otherwise.
*/
fixedRadius: false,
/**
* Property: feature
* {<OpenLayers.Feature.Vector>} The currently drawn polygon feature
*/
feature: null,
/**
* Property: layer
* {<OpenLayers.Layer.Vector>} The temporary drawing layer
*/
layer: null,
/**
* Property: origin
* {<OpenLayers.Geometry.Point>} Location of the first mouse down
*/
origin: null,
/**
* Constructor: OpenLayers.Handler.RegularPolygon
* Create a new regular polygon handler.
*
* Parameters:
* control - {<OpenLayers.Control>} The control that owns this handler
* callbacks - {Array} An object with a 'done' property whos value is a
* function to be called when the polygon drawing is finished.
* The callback should expect to recieve a single argument,
* the polygon geometry. If the callbacks object contains a
* 'cancel' property, this function will be called when the
* handler is deactivated while drawing. The cancel should
* expect to receive a geometry.
* options - {Object} An object with properties to be set on the handler.
* If the options.sides property is not specified, the number of sides
* will default to 4.
*/
initialize: function(control, callbacks, options) {
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
OpenLayers.Handler.prototype.initialize.apply(this,
[control, callbacks, options]);
this.options = (options) ? options : new Object();
},
/**
* APIMethod: setOptions
*
* Parameters:
* newOptions - {Object}
*/
setOptions: function (newOptions) {
OpenLayers.Util.extend(this.options, newOptions);
OpenLayers.Util.extend(this, newOptions);
},
/**
* APIMethod: activate
* Turn on the handler.
*
* Return:
* {Boolean} The handler was successfully activated
*/
activate: function() {
var activated = false;
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
// create temporary vector layer for rendering geometry sketch
var options = {displayInLayerSwitcher: false};
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
this.map.addLayer(this.layer);
activated = true;
}
return activated;
},
/**
* APIMethod: deactivate
* Turn off the handler.
*
* Return:
* {Boolean} The handler was successfully deactivated
*/
deactivate: function() {
var deactivated = false;
if(OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) {
// call the cancel callback if mid-drawing
if(this.dragging) {
this.cancel();
}
// If a layer's map property is set to null, it means that that
// layer isn't added to the map. Since we ourself added the layer
// to the map in activate(), we can assume that if this.layer.map
// is null it means that the layer has been destroyed (as a result
// of map.destroy() for example.
if (this.layer.map != null) {
this.layer.destroy(false);
if (this.feature) {
this.feature.destroy();
}
}
this.layer = null;
this.feature = null;
deactivated = true;
}
return deactivated;
},
/**
* Method: downFeature
* Start drawing a new feature
*
* Parameters:
* evt - {Event} The drag start event
*/
down: function(evt) {
this.fixedRadius = !!(this.radius);
var maploc = this.map.getLonLatFromPixel(evt.xy);
this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
// create the new polygon
if(!this.fixedRadius || this.irregular) {
// smallest radius should not be less one pixel in map units
// VML doesn't behave well with smaller
this.radius = this.map.getResolution();
}
if(this.persist) {
this.clear();
}
this.feature = new OpenLayers.Feature.Vector();
this.createGeometry();
this.layer.addFeatures([this.feature], {silent: true});
this.layer.drawFeature(this.feature, this.style);
},
/**
* Method: move
* Respond to drag move events
*
* Parameters:
* evt - {Evt} The move event
*/
move: function(evt) {
var maploc = this.map.getLonLatFromPixel(evt.xy);
var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
if(this.irregular) {
var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2;
this.radius = Math.max(this.map.getResolution() / 2, ry);
} else if(this.fixedRadius) {
this.origin = point;
} else {
this.calculateAngle(point, evt);
this.radius = Math.max(this.map.getResolution() / 2,
point.distanceTo(this.origin));
}
this.modifyGeometry();
if(this.irregular) {
var dx = point.x - this.origin.x;
var dy = point.y - this.origin.y;
var ratio;
if(dy == 0) {
ratio = dx / (this.radius * Math.sqrt(2));
} else {
ratio = dx / dy;
}
this.feature.geometry.resize(1, this.origin, ratio);
this.feature.geometry.move(dx / 2, dy / 2);
}
this.layer.drawFeature(this.feature, this.style);
},
/**
* Method: up
* Finish drawing the feature
*
* Parameters:
* evt - {Event} The mouse up event
*/
up: function(evt) {
this.finalize();
},
/**
* Method: out
* Finish drawing the feature.
*
* Parameters:
* evt - {Event} The mouse out event
*/
out: function(evt) {
this.finalize();
},
/**
* Method: createGeometry
* Create the new polygon geometry. This is called at the start of the
* drag and at any point during the drag if the number of sides
* changes.
*/
createGeometry: function() {
this.angle = Math.PI * ((1/this.sides) - (1/2));
if(this.snapAngle) {
this.angle += this.snapAngle * (Math.PI / 180);
}
this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
this.origin, this.radius, this.sides, this.snapAngle
);
},
/**
* Method: modifyGeometry
* Modify the polygon geometry in place.
*/
modifyGeometry: function() {
var angle, dx, dy, point;
var ring = this.feature.geometry.components[0];
// if the number of sides ever changes, create a new geometry
if(ring.components.length != (this.sides + 1)) {
this.createGeometry();
ring = this.feature.geometry.components[0];
}
for(var i=0; i<this.sides; ++i) {
point = ring.components[i];
angle = this.angle + (i * 2 * Math.PI / this.sides);
point.x = this.origin.x + (this.radius * Math.cos(angle));
point.y = this.origin.y + (this.radius * Math.sin(angle));
point.clearBounds();
}
},
/**
* Method: calculateAngle
* Calculate the angle based on settings.
*
* Parameters:
* point - {<OpenLayers.Geometry.Point>}
* evt - {Event}
*/
calculateAngle: function(point, evt) {
var alpha = Math.atan2(point.y - this.origin.y,
point.x - this.origin.x);
if(this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) {
var snapAngleRad = (Math.PI / 180) * this.snapAngle;
this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad;
} else {
this.angle = alpha;
}
},
/**
* APIMethod: cancel
* Finish the geometry and call the "cancel" callback.
*/
cancel: function() {
// the polygon geometry gets cloned in the callback method
this.callback("cancel", null);
this.finalize();
},
/**
* Method: finalize
* Finish the geometry and call the "done" callback.
*/
finalize: function() {
this.origin = null;
this.radius = this.options.radius;
},
/**
* APIMethod: clear
* Clear any rendered features on the temporary layer. This is called
* when the handler is deactivated, canceled, or done (unless persist
* is true).
*/
clear: function() {
this.layer.renderer.clear();
this.layer.destroyFeatures();
},
/**
* Method: callback
* Trigger the control's named callback with the given arguments
*
* Parameters:
* name - {String} The key for the callback that is one of the properties
* of the handler's callbacks object.
* args - {Array} An array of arguments with which to call the callback
* (defined by the control).
*/
callback: function (name, args) {
// override the callback method to always send the polygon geometry
if (this.callbacks[name]) {
this.callbacks[name].apply(this.control,
[this.feature.geometry.clone()]);
}
// since sketch features are added to the temporary layer
// they must be cleared here if done or cancel
if(!this.persist && (name == "done" || name == "cancel")) {
this.clear();
}
},
CLASS_NAME: "OpenLayers.Handler.RegularPolygon"
});

View File

@@ -1,141 +1,141 @@
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license. */
/**
* @requires OpenLayers/Util.js
* @requires OpenLayers/Style.js
*/
/**
* Class: OpenLayers.Rule
* This class represents a OGC Rule, as being used for rule-based SLD styling.
*/
OpenLayers.Rule = OpenLayers.Class({
/**
* APIProperty: name
* {String} name of this rule
*/
name: 'default',
/**
* Property: context
* {Object} An optional object with properties that the rule and its
* symbolizers' property values should be evaluatad against. If no
* context is specified, feature.attributes will be used
*/
context: null,
/**
* Property: elseFilter
* {Boolean} Determines whether this rule is only to be applied only if
* no other rules match (ElseFilter according to the SLD specification).
* Default is false. For instances of OpenLayers.Rule, if elseFilter is
* false, the rule will always apply. For subclasses, the else property is
* ignored.
*/
elseFilter: false,
/**
* Property: symbolizer
* {Object} Hash of styles for this rule. Contains hashes of feature
* styles. Keys are one or more of ["Point", "Line", "Polygon"]
*/
symbolizer: null,
/**
* APIProperty: minScaleDenominator
* {Number} or {String} minimum scale at which to draw the feature.
* In the case of a String, this can be a combination of text and
* propertyNames in the form "literal ${propertyName}"
*/
minScaleDenominator: null,
/**
* APIProperty: maxScaleDenominator
* {Number} or {String} maximum scale at which to draw the feature.
* In the case of a String, this can be a combination of text and
* propertyNames in the form "literal ${propertyName}"
*/
maxScaleDenominator: null,
/**
* Constructor: OpenLayers.Rule
* Creates a Rule.
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule>}
*/
initialize: function(options) {
this.symbolizer = {};
OpenLayers.Util.extend(this, options);
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
for (var i in this.symbolizer) {
this.symbolizer[i] = null;
}
this.symbolizer = null;
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific feature
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
*
* Returns:
* {boolean} true if the rule applies, false if it does not.
* This rule is the default rule and always returns true.
*/
evaluate: function(feature) {
var context = this.getContext(feature);
var applies = true;
if (this.minScaleDenominator || this.maxScaleDenominator) {
var scale = feature.layer.map.getScale();
}
// check if within minScale/maxScale bounds
if (this.minScaleDenominator) {
applies = scale >= OpenLayers.Style.createLiteral(
this.minScaleDenominator, context);
}
if (applies && this.maxScaleDenominator) {
applies = scale < OpenLayers.Style.createLiteral(
this.maxScaleDenominator, context);
}
return applies;
},
/**
* Method: getContext
* Gets the context for evaluating this rule
*
* Paramters:
* feature - {<OpenLayers.Feature>} feature to take the context from if
* none is specified.
*/
getContext: function(feature) {
var context = this.context;
if (!context) {
context = feature.attributes || feature.data;
}
return context;
},
CLASS_NAME: "OpenLayers.Rule"
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license. */
/**
* @requires OpenLayers/Util.js
* @requires OpenLayers/Style.js
*/
/**
* Class: OpenLayers.Rule
* This class represents a OGC Rule, as being used for rule-based SLD styling.
*/
OpenLayers.Rule = OpenLayers.Class({
/**
* APIProperty: name
* {String} name of this rule
*/
name: 'default',
/**
* Property: context
* {Object} An optional object with properties that the rule and its
* symbolizers' property values should be evaluatad against. If no
* context is specified, feature.attributes will be used
*/
context: null,
/**
* Property: elseFilter
* {Boolean} Determines whether this rule is only to be applied only if
* no other rules match (ElseFilter according to the SLD specification).
* Default is false. For instances of OpenLayers.Rule, if elseFilter is
* false, the rule will always apply. For subclasses, the else property is
* ignored.
*/
elseFilter: false,
/**
* Property: symbolizer
* {Object} Hash of styles for this rule. Contains hashes of feature
* styles. Keys are one or more of ["Point", "Line", "Polygon"]
*/
symbolizer: null,
/**
* APIProperty: minScaleDenominator
* {Number} or {String} minimum scale at which to draw the feature.
* In the case of a String, this can be a combination of text and
* propertyNames in the form "literal ${propertyName}"
*/
minScaleDenominator: null,
/**
* APIProperty: maxScaleDenominator
* {Number} or {String} maximum scale at which to draw the feature.
* In the case of a String, this can be a combination of text and
* propertyNames in the form "literal ${propertyName}"
*/
maxScaleDenominator: null,
/**
* Constructor: OpenLayers.Rule
* Creates a Rule.
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule>}
*/
initialize: function(options) {
this.symbolizer = {};
OpenLayers.Util.extend(this, options);
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
for (var i in this.symbolizer) {
this.symbolizer[i] = null;
}
this.symbolizer = null;
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific feature
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
*
* Returns:
* {boolean} true if the rule applies, false if it does not.
* This rule is the default rule and always returns true.
*/
evaluate: function(feature) {
var context = this.getContext(feature);
var applies = true;
if (this.minScaleDenominator || this.maxScaleDenominator) {
var scale = feature.layer.map.getScale();
}
// check if within minScale/maxScale bounds
if (this.minScaleDenominator) {
applies = scale >= OpenLayers.Style.createLiteral(
this.minScaleDenominator, context);
}
if (applies && this.maxScaleDenominator) {
applies = scale < OpenLayers.Style.createLiteral(
this.maxScaleDenominator, context);
}
return applies;
},
/**
* Method: getContext
* Gets the context for evaluating this rule
*
* Paramters:
* feature - {<OpenLayers.Feature>} feature to take the context from if
* none is specified.
*/
getContext: function(feature) {
var context = this.context;
if (!context) {
context = feature.attributes || feature.data;
}
return context;
},
CLASS_NAME: "OpenLayers.Rule"
});

View File

@@ -1,206 +1,206 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Rule.js
*/
/**
* Class: OpenLayers.Rule.Comparison
* This class represents the comparison rules, as being used for rule-based
* SLD styling
*
* Inherits from
* - <OpenLayers.Rule>
*/
OpenLayers.Rule.Comparison = OpenLayers.Class(OpenLayers.Rule, {
/**
* APIProperty: type
* {String} type: type of the comparison. This is one of
* - OpenLayers.Rule.Comparison.EQUAL_TO = "==";
* - OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
* - OpenLayers.Rule.Comparison.LESS_THAN = "<";
* - OpenLayers.Rule.Comparison.GREATER_THAN = ">";
* - OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
* - OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
* - OpenLayers.Rule.Comparison.BETWEEN = "..";
* - OpenLayers.Rule.Comparison.LIKE = "~";
*/
type: null,
/**
* APIProperty: property
* {String}
* name of the context property to compare
*/
property: null,
/**
* APIProperty: value
* {Number} or {String}
* comparison value for binary comparisons. In the case of a String, this
* can be a combination of text and propertyNames in the form
* "literal ${propertyName}"
*/
value: null,
/**
* APIProperty: lowerBoundary
* {Number} or {String}
* lower boundary for between comparisons. In the case of a String, this
* can be a combination of text and propertyNames in the form
* "literal ${propertyName}"
*/
lowerBoundary: null,
/**
* APIProperty: upperBoundary
* {Number} or {String}
* upper boundary for between comparisons. In the case of a String, this
* can be a combination of text and propertyNames in the form
* "literal ${propertyName}"
*/
upperBoundary: null,
/**
* Constructor: OpenLayers.Rule.Comparison
* Creates a comparison rule.
*
* Parameters:
* params - {Object} Hash of parameters for this rule:
* -
* - value:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule.Comparison>}
*/
initialize: function(options) {
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific context
*
* Parameters:
* context - {Object} context to apply the rule to.
*
* Returns:
* {boolean} true if the rule applies, false if it does not
*/
evaluate: function(feature) {
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
return false;
}
var context = this.getContext(feature);
switch(this.type) {
case OpenLayers.Rule.Comparison.EQUAL_TO:
case OpenLayers.Rule.Comparison.LESS_THAN:
case OpenLayers.Rule.Comparison.GREATER_THAN:
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
return this.binaryCompare(context, this.property, this.value);
case OpenLayers.Rule.Comparison.BETWEEN:
var result =
context[this.property] > this.lowerBoundary;
result = result &&
context[this.property] < this.upperBoundary;
return result;
case OpenLayers.Rule.Comparison.LIKE:
var regexp = new RegExp(this.value,
"gi");
return regexp.test(context[this.property]);
}
},
/**
* APIMethod: value2regex
* Converts the value of this rule into a regular expression string,
* according to the wildcard characters specified. This method has to
* be called after instantiation of this class, if the value is not a
* regular expression already.
*
* Parameters:
* wildCard - {<Char>} wildcard character in the above value, default
* is "*"
* singleChar - {<Char>) single-character wildcard in the above value
* default is "."
* escape - {<Char>) escape character in the above value, default is
* "!"
*
* Returns:
* {String} regular expression string
*/
value2regex: function(wildCard, singleChar, escapeChar) {
if (wildCard == ".") {
var msg = "'.' is an unsupported wildCard character for "+
"OpenLayers.Rule.Comparison";
OpenLayers.Console.error(msg);
return null;
}
// set UMN MapServer defaults for unspecified parameters
wildCard = wildCard ? wildCard : "*";
singleChar = singleChar ? singleChar : ".";
escapeChar = escapeChar ? escapeChar : "!";
this.value = this.value.replace(
new RegExp("\\"+escapeChar, "g"), "\\");
this.value = this.value.replace(
new RegExp("\\"+singleChar, "g"), ".");
this.value = this.value.replace(
new RegExp("\\"+wildCard, "g"), ".*");
this.value = this.value.replace(
new RegExp("\\\\.\\*", "g"), "\\"+wildCard);
this.value = this.value.replace(
new RegExp("\\\\\\.", "g"), "\\"+singleChar);
return this.value;
},
/**
* Function: binaryCompare
* Compares a feature property to a rule value
*
* Parameters:
* context - {Object}
* property - {String} or {Number}
* value - {String} or {Number}, same as property
*
* Returns:
* {boolean}
*/
binaryCompare: function(context, property, value) {
switch (this.type) {
case OpenLayers.Rule.Comparison.EQUAL_TO:
return context[property] == value;
case OpenLayers.Rule.Comparison.NOT_EQUAL_TO:
return context[property] != value;
case OpenLayers.Rule.Comparison.LESS_THAN:
return context[property] < value;
case OpenLayers.Rule.Comparison.GREATER_THAN:
return context[property] > value;
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
return context[property] <= value;
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
return context[property] >= value;
}
},
CLASS_NAME: "OpenLayers.Rule.Comparison"
});
OpenLayers.Rule.Comparison.EQUAL_TO = "==";
OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
OpenLayers.Rule.Comparison.LESS_THAN = "<";
OpenLayers.Rule.Comparison.GREATER_THAN = ">";
OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
OpenLayers.Rule.Comparison.BETWEEN = "..";
OpenLayers.Rule.Comparison.LIKE = "~";
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Rule.js
*/
/**
* Class: OpenLayers.Rule.Comparison
* This class represents the comparison rules, as being used for rule-based
* SLD styling
*
* Inherits from
* - <OpenLayers.Rule>
*/
OpenLayers.Rule.Comparison = OpenLayers.Class(OpenLayers.Rule, {
/**
* APIProperty: type
* {String} type: type of the comparison. This is one of
* - OpenLayers.Rule.Comparison.EQUAL_TO = "==";
* - OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
* - OpenLayers.Rule.Comparison.LESS_THAN = "<";
* - OpenLayers.Rule.Comparison.GREATER_THAN = ">";
* - OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
* - OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
* - OpenLayers.Rule.Comparison.BETWEEN = "..";
* - OpenLayers.Rule.Comparison.LIKE = "~";
*/
type: null,
/**
* APIProperty: property
* {String}
* name of the context property to compare
*/
property: null,
/**
* APIProperty: value
* {Number} or {String}
* comparison value for binary comparisons. In the case of a String, this
* can be a combination of text and propertyNames in the form
* "literal ${propertyName}"
*/
value: null,
/**
* APIProperty: lowerBoundary
* {Number} or {String}
* lower boundary for between comparisons. In the case of a String, this
* can be a combination of text and propertyNames in the form
* "literal ${propertyName}"
*/
lowerBoundary: null,
/**
* APIProperty: upperBoundary
* {Number} or {String}
* upper boundary for between comparisons. In the case of a String, this
* can be a combination of text and propertyNames in the form
* "literal ${propertyName}"
*/
upperBoundary: null,
/**
* Constructor: OpenLayers.Rule.Comparison
* Creates a comparison rule.
*
* Parameters:
* params - {Object} Hash of parameters for this rule:
* -
* - value:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule.Comparison>}
*/
initialize: function(options) {
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific context
*
* Parameters:
* context - {Object} context to apply the rule to.
*
* Returns:
* {boolean} true if the rule applies, false if it does not
*/
evaluate: function(feature) {
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
return false;
}
var context = this.getContext(feature);
switch(this.type) {
case OpenLayers.Rule.Comparison.EQUAL_TO:
case OpenLayers.Rule.Comparison.LESS_THAN:
case OpenLayers.Rule.Comparison.GREATER_THAN:
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
return this.binaryCompare(context, this.property, this.value);
case OpenLayers.Rule.Comparison.BETWEEN:
var result =
context[this.property] > this.lowerBoundary;
result = result &&
context[this.property] < this.upperBoundary;
return result;
case OpenLayers.Rule.Comparison.LIKE:
var regexp = new RegExp(this.value,
"gi");
return regexp.test(context[this.property]);
}
},
/**
* APIMethod: value2regex
* Converts the value of this rule into a regular expression string,
* according to the wildcard characters specified. This method has to
* be called after instantiation of this class, if the value is not a
* regular expression already.
*
* Parameters:
* wildCard - {<Char>} wildcard character in the above value, default
* is "*"
* singleChar - {<Char>) single-character wildcard in the above value
* default is "."
* escape - {<Char>) escape character in the above value, default is
* "!"
*
* Returns:
* {String} regular expression string
*/
value2regex: function(wildCard, singleChar, escapeChar) {
if (wildCard == ".") {
var msg = "'.' is an unsupported wildCard character for "+
"OpenLayers.Rule.Comparison";
OpenLayers.Console.error(msg);
return null;
}
// set UMN MapServer defaults for unspecified parameters
wildCard = wildCard ? wildCard : "*";
singleChar = singleChar ? singleChar : ".";
escapeChar = escapeChar ? escapeChar : "!";
this.value = this.value.replace(
new RegExp("\\"+escapeChar, "g"), "\\");
this.value = this.value.replace(
new RegExp("\\"+singleChar, "g"), ".");
this.value = this.value.replace(
new RegExp("\\"+wildCard, "g"), ".*");
this.value = this.value.replace(
new RegExp("\\\\.\\*", "g"), "\\"+wildCard);
this.value = this.value.replace(
new RegExp("\\\\\\.", "g"), "\\"+singleChar);
return this.value;
},
/**
* Function: binaryCompare
* Compares a feature property to a rule value
*
* Parameters:
* context - {Object}
* property - {String} or {Number}
* value - {String} or {Number}, same as property
*
* Returns:
* {boolean}
*/
binaryCompare: function(context, property, value) {
switch (this.type) {
case OpenLayers.Rule.Comparison.EQUAL_TO:
return context[property] == value;
case OpenLayers.Rule.Comparison.NOT_EQUAL_TO:
return context[property] != value;
case OpenLayers.Rule.Comparison.LESS_THAN:
return context[property] < value;
case OpenLayers.Rule.Comparison.GREATER_THAN:
return context[property] > value;
case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO:
return context[property] <= value;
case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO:
return context[property] >= value;
}
},
CLASS_NAME: "OpenLayers.Rule.Comparison"
});
OpenLayers.Rule.Comparison.EQUAL_TO = "==";
OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!=";
OpenLayers.Rule.Comparison.LESS_THAN = "<";
OpenLayers.Rule.Comparison.GREATER_THAN = ">";
OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<=";
OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">=";
OpenLayers.Rule.Comparison.BETWEEN = "..";
OpenLayers.Rule.Comparison.LIKE = "~";

View File

@@ -1,69 +1,69 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Rule.js
*/
/**
* Class: OpenLayers.Rule.FeatureId
* This class represents a ogc:FeatureId Rule, as being used for rule-based SLD
* styling
*
* Inherits from
* - <OpenLayers.Rule>
*/
OpenLayers.Rule.FeatureId = OpenLayers.Class(OpenLayers.Rule, {
/**
* APIProperty: fids
* {Array(<String>)} Feature Ids to evaluate this rule against. To be passed
* To be passed inside the params object.
*/
fids: null,
/**
* Constructor: OpenLayers.Rule.FeatureId
* Creates an ogc:FeatureId rule.
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule.FeatureId>}
*/
initialize: function(options) {
this.fids = [];
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific feature
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
* For vector features, the check is run against the fid,
* for plain features against the id.
*
* Returns:
* {boolean} true if the rule applies, false if it does not
*/
evaluate: function(feature) {
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
return false;
}
for (var i=0; i<this.fids.length; i++) {
var fid = feature.fid || feature.id;
if (fid == this.fids[i]) {
return true;
}
}
return false;
},
CLASS_NAME: "OpenLayers.Rule.FeatureId"
});
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Rule.js
*/
/**
* Class: OpenLayers.Rule.FeatureId
* This class represents a ogc:FeatureId Rule, as being used for rule-based SLD
* styling
*
* Inherits from
* - <OpenLayers.Rule>
*/
OpenLayers.Rule.FeatureId = OpenLayers.Class(OpenLayers.Rule, {
/**
* APIProperty: fids
* {Array(<String>)} Feature Ids to evaluate this rule against. To be passed
* To be passed inside the params object.
*/
fids: null,
/**
* Constructor: OpenLayers.Rule.FeatureId
* Creates an ogc:FeatureId rule.
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule.FeatureId>}
*/
initialize: function(options) {
this.fids = [];
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific feature
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
* For vector features, the check is run against the fid,
* for plain features against the id.
*
* Returns:
* {boolean} true if the rule applies, false if it does not
*/
evaluate: function(feature) {
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
return false;
}
for (var i=0; i<this.fids.length; i++) {
var fid = feature.fid || feature.id;
if (fid == this.fids[i]) {
return true;
}
}
return false;
},
CLASS_NAME: "OpenLayers.Rule.FeatureId"
});

View File

@@ -1,104 +1,104 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Rule.js
*/
/**
* Class: OpenLayers.Rule.Logical
* This class represents ogc:And, ogc:Or and ogc:Not rules.
*
* Inherits from
* - <OpenLayers.Rule>
*/
OpenLayers.Rule.Logical = OpenLayers.Class(OpenLayers.Rule, {
/**
* APIProperty: children
* {Array(<OpenLayers.Rule>)} child rules for this rule
*/
rules: null,
/**
* APIProperty: type
* {String} type of logical operator. Available types are:
* - OpenLayers.Rule.Locical.AND = "&&";
* - OpenLayers.Rule.Logical.OR = "||";
* - OpenLayers.Rule.Logical.NOT = "!";
*/
type: null,
/**
* Constructor: OpenLayers.Rule.Logical
* Creates a logical rule (And, Or, Not).
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule.Logical>}
*/
initialize: function(options) {
this.rules = [];
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
for (var i=0; i<this.rules.length; i++) {
this.rules[i].destroy();
}
this.rules = null;
OpenLayers.Rule.prototype.destroy.apply(this, arguments);
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific feature
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
*
* Returns:
* {boolean} true if the rule applies, false if it does not
*/
evaluate: function(feature) {
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
return false;
}
switch(this.type) {
case OpenLayers.Rule.Logical.AND:
for (var i=0; i<this.rules.length; i++) {
if (this.rules[i].evaluate(feature) == false) {
return false;
}
}
return true;
case OpenLayers.Rule.Logical.OR:
for (var i=0; i<this.rules.length; i++) {
if (this.rules[i].evaluate(feature) == true) {
return true;
}
}
return false;
case OpenLayers.Rule.Logical.NOT:
return (!this.rules[0].evaluate(feature));
}
},
CLASS_NAME: "OpenLayers.Rule.Logical"
});
OpenLayers.Rule.Logical.AND = "&&";
OpenLayers.Rule.Logical.OR = "||";
OpenLayers.Rule.Logical.NOT = "!";
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Rule.js
*/
/**
* Class: OpenLayers.Rule.Logical
* This class represents ogc:And, ogc:Or and ogc:Not rules.
*
* Inherits from
* - <OpenLayers.Rule>
*/
OpenLayers.Rule.Logical = OpenLayers.Class(OpenLayers.Rule, {
/**
* APIProperty: children
* {Array(<OpenLayers.Rule>)} child rules for this rule
*/
rules: null,
/**
* APIProperty: type
* {String} type of logical operator. Available types are:
* - OpenLayers.Rule.Locical.AND = "&&";
* - OpenLayers.Rule.Logical.OR = "||";
* - OpenLayers.Rule.Logical.NOT = "!";
*/
type: null,
/**
* Constructor: OpenLayers.Rule.Logical
* Creates a logical rule (And, Or, Not).
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* rule
*
* Returns:
* {<OpenLayers.Rule.Logical>}
*/
initialize: function(options) {
this.rules = [];
OpenLayers.Rule.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
for (var i=0; i<this.rules.length; i++) {
this.rules[i].destroy();
}
this.rules = null;
OpenLayers.Rule.prototype.destroy.apply(this, arguments);
},
/**
* APIMethod: evaluate
* evaluates this rule for a specific feature
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to apply the rule to.
*
* Returns:
* {boolean} true if the rule applies, false if it does not
*/
evaluate: function(feature) {
if (!OpenLayers.Rule.prototype.evaluate.apply(this, arguments)) {
return false;
}
switch(this.type) {
case OpenLayers.Rule.Logical.AND:
for (var i=0; i<this.rules.length; i++) {
if (this.rules[i].evaluate(feature) == false) {
return false;
}
}
return true;
case OpenLayers.Rule.Logical.OR:
for (var i=0; i<this.rules.length; i++) {
if (this.rules[i].evaluate(feature) == true) {
return true;
}
}
return false;
case OpenLayers.Rule.Logical.NOT:
return (!this.rules[0].evaluate(feature));
}
},
CLASS_NAME: "OpenLayers.Rule.Logical"
});
OpenLayers.Rule.Logical.AND = "&&";
OpenLayers.Rule.Logical.OR = "||";
OpenLayers.Rule.Logical.NOT = "!";

View File

@@ -1,317 +1,317 @@
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Util.js
* @requires OpenLayers/Feature/Vector.js
*/
/**
* Class: OpenLayers.Style
* This class represents a UserStyle obtained
* from a SLD, containing styling rules.
*/
OpenLayers.Style = OpenLayers.Class({
/**
* APIProperty: name
* {String}
*/
name: null,
/**
* APIProperty: layerName
* {<String>} name of the layer that this style belongs to, usually
* according to the NamedLayer attribute of an SLD document.
*/
layerName: null,
/**
* APIProperty: isDefault
* {Boolean}
*/
isDefault: false,
/**
* Property: rules
* Array({<OpenLayers.Rule>})
*/
rules: null,
/**
* Property: defaultStyle
* {Object} hash of style properties to use as default for merging
* rule-based style symbolizers onto. If no rules are defined, createStyle
* will return this style.
*/
defaultStyle: null,
/**
* Property: propertyStyles
* {Hash of Boolean} cache of style properties that need to be parsed for
* propertyNames. Property names are keys, values won't be used.
*/
propertyStyles: null,
/**
* Constructor: OpenLayers.Style
* Creates a UserStyle.
*
* Parameters:
* style - {Object} Optional hash of style properties that will be
* used as default style for this style object. This style
* applies if no rules are specified. Symbolizers defined in
* rules will extend this default style.
* options - {Object} An optional object with properties to set on the
* userStyle
*
* Return:
* {<OpenLayers.Style>}
*/
initialize: function(style, options) {
this.rules = [];
// use the default style from OpenLayers.Feature.Vector if no style
// was given in the constructor
this.setDefaultStyle(style ||
OpenLayers.Feature.Vector.style["default"]);
OpenLayers.Util.extend(this, options);
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
for (var i=0; i<this.rules.length; i++) {
this.rules[i].destroy();
this.rules[i] = null;
}
this.rules = null;
this.defaultStyle = null;
},
/**
* APIMethod: createStyle
* creates a style by applying all feature-dependent rules to the base
* style.
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to evaluate rules for
* baseStyle - {Object} hash of styles feature styles to extend
*
* Returns:
* {<OpenLayers.Feature.Vector.style>} hash of feature styles
*/
createStyle: function(feature) {
var style = OpenLayers.Util.extend({}, this.defaultStyle);
var rules = this.rules;
var rule, context;
var elseRules = [];
var appliedRules = false;
for(var i=0; i<rules.length; i++) {
rule = rules[i];
context = rule.context;
if (!context) {
context = feature.attributes || feature.data;
}
// does the rule apply?
var applies = rule.evaluate(feature);
if(applies) {
if(rule instanceof OpenLayers.Rule && rule.elseFilter) {
elseRules.push(rule);
} else {
appliedRules = true;
this.applySymbolizer(rule, style, feature, context);
}
}
}
// if no other rules apply, apply the rules with else filters
if(appliedRules == false && elseRules.length > 0) {
appliedRules = true;
for(var i=0; i<elseRules.length; i++) {
this.applySymbolizer(elseRules[i], style, feature, context);
}
}
// don't display if there were rules but none applied
if(rules.length > 0 && appliedRules == false) {
style.display = "none";
} else {
style.display = "";
}
return style;
},
/**
* Method: applySymbolizer
*
* Parameters:
* rule - {OpenLayers.Rule}
* style - {Object}
* feature - {<OpenLayer.Feature.Vector>}
* context - {Object}
*
* Returns:
* {Object} A style with new symbolizer applied.
*/
applySymbolizer: function(rule, style, feature, context) {
var symbolizerPrefix = feature.geometry ?
this.getSymbolizerPrefix(feature.geometry) :
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
var symbolizer = rule.symbolizer[symbolizerPrefix];
// merge the style with the current style
return this.createLiterals(
OpenLayers.Util.extend(style, symbolizer), context);
},
/**
* Method: createLiterals
* creates literals for all style properties that have an entry in
* <this.propertyStyles>.
*
* Parameters:
* style - {Object} style to create literals for. Will be modified
* inline.
* context - {Object} context to take property values from. Defaults to
* feature.attributes (or feature.data, if attributes are not
* available)
*
* Returns;
* {Object} the modified style
*/
createLiterals: function(style, context) {
for (var i in this.propertyStyles) {
style[i] = OpenLayers.Style.createLiteral(style[i], context);
}
return style;
},
/**
* Method: findPropertyStyles
* Looks into all rules for this style and the defaultStyle to collect
* all the style hash property names containing ${...} strings that have
* to be replaced using the createLiteral method before returning them.
*
* Returns:
* {Object} hash of property names that need createLiteral parsing. The
* name of the property is the key, and the value is true;
*/
findPropertyStyles: function() {
var propertyStyles = {};
// check the default style
var style = this.defaultStyle;
for (var i in style) {
if (typeof style[i] == "string" && style[i].match(/\$\{\w+\}/)) {
propertyStyles[i] = true;
}
}
// walk through all rules to check for properties in their symbolizer
var rules = this.rules;
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
for (var i in rules) {
for (var s=0; s<prefixes.length; s++) {
style = rules[i].symbolizer[prefixes[s]];
for (var j in style) {
if (typeof style[j] == "string" &&
style[j].match(/\$\{\w+\}/)) {
propertyStyles[j] = true;
}
}
}
}
return propertyStyles;
},
/**
* APIMethod: addRules
* Adds rules to this style.
*
* Parameters:
* rules - {Array(<OpenLayers.Rule>)}
*/
addRules: function(rules) {
this.rules = this.rules.concat(rules);
this.propertyStyles = this.findPropertyStyles();
},
/**
* APIMethod: setDefaultStyle
* Sets the default style for this style object.
*
* Parameters:
* style - {Object} Hash of style properties
*/
setDefaultStyle: function(style) {
this.defaultStyle = style;
this.propertyStyles = this.findPropertyStyles();
},
/**
* Method: getSymbolizerPrefix
* Returns the correct symbolizer prefix according to the
* geometry type of the passed geometry
*
* Parameters:
* geometry {<OpenLayers.Geometry>}
*
* Returns:
* {String} key of the according symbolizer
*/
getSymbolizerPrefix: function(geometry) {
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
for (var i=0; i<prefixes.length; i++) {
if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) {
return prefixes[i];
}
}
},
CLASS_NAME: "OpenLayers.Style"
});
/**
* Function: createLiteral
* converts a style value holding a combination of PropertyName and Literal
* into a Literal, taking the property values from the passed features.
*
* Parameters:
* value {String} value to parse. If this string contains a construct like
* "foo ${bar}", then "foo " will be taken as literal, and "${bar}"
* will be replaced by the value of the "bar" attribute of the passed
* feature.
* context {Object} context to take attribute values from
*
* Returns:
* {String} the parsed value. In the example of the value parameter above, the
* result would be "foo valueOfBar", assuming that the passed feature has an
* attribute named "bar" with the value "valueOfBar".
*/
OpenLayers.Style.createLiteral = function(value, context) {
if (typeof value == "string" && value.indexOf("${") != -1) {
value = OpenLayers.String.format(value, context)
value = isNaN(value) ? value : parseFloat(value);
}
return value;
}
/**
* Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES
* {Array} prefixes of the sld symbolizers. These are the
* same as the main geometry types
*/
OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon'];
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Util.js
* @requires OpenLayers/Feature/Vector.js
*/
/**
* Class: OpenLayers.Style
* This class represents a UserStyle obtained
* from a SLD, containing styling rules.
*/
OpenLayers.Style = OpenLayers.Class({
/**
* APIProperty: name
* {String}
*/
name: null,
/**
* APIProperty: layerName
* {<String>} name of the layer that this style belongs to, usually
* according to the NamedLayer attribute of an SLD document.
*/
layerName: null,
/**
* APIProperty: isDefault
* {Boolean}
*/
isDefault: false,
/**
* Property: rules
* Array({<OpenLayers.Rule>})
*/
rules: null,
/**
* Property: defaultStyle
* {Object} hash of style properties to use as default for merging
* rule-based style symbolizers onto. If no rules are defined, createStyle
* will return this style.
*/
defaultStyle: null,
/**
* Property: propertyStyles
* {Hash of Boolean} cache of style properties that need to be parsed for
* propertyNames. Property names are keys, values won't be used.
*/
propertyStyles: null,
/**
* Constructor: OpenLayers.Style
* Creates a UserStyle.
*
* Parameters:
* style - {Object} Optional hash of style properties that will be
* used as default style for this style object. This style
* applies if no rules are specified. Symbolizers defined in
* rules will extend this default style.
* options - {Object} An optional object with properties to set on the
* userStyle
*
* Return:
* {<OpenLayers.Style>}
*/
initialize: function(style, options) {
this.rules = [];
// use the default style from OpenLayers.Feature.Vector if no style
// was given in the constructor
this.setDefaultStyle(style ||
OpenLayers.Feature.Vector.style["default"]);
OpenLayers.Util.extend(this, options);
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
for (var i=0; i<this.rules.length; i++) {
this.rules[i].destroy();
this.rules[i] = null;
}
this.rules = null;
this.defaultStyle = null;
},
/**
* APIMethod: createStyle
* creates a style by applying all feature-dependent rules to the base
* style.
*
* Parameters:
* feature - {<OpenLayers.Feature>} feature to evaluate rules for
* baseStyle - {Object} hash of styles feature styles to extend
*
* Returns:
* {<OpenLayers.Feature.Vector.style>} hash of feature styles
*/
createStyle: function(feature) {
var style = OpenLayers.Util.extend({}, this.defaultStyle);
var rules = this.rules;
var rule, context;
var elseRules = [];
var appliedRules = false;
for(var i=0; i<rules.length; i++) {
rule = rules[i];
context = rule.context;
if (!context) {
context = feature.attributes || feature.data;
}
// does the rule apply?
var applies = rule.evaluate(feature);
if(applies) {
if(rule instanceof OpenLayers.Rule && rule.elseFilter) {
elseRules.push(rule);
} else {
appliedRules = true;
this.applySymbolizer(rule, style, feature, context);
}
}
}
// if no other rules apply, apply the rules with else filters
if(appliedRules == false && elseRules.length > 0) {
appliedRules = true;
for(var i=0; i<elseRules.length; i++) {
this.applySymbolizer(elseRules[i], style, feature, context);
}
}
// don't display if there were rules but none applied
if(rules.length > 0 && appliedRules == false) {
style.display = "none";
} else {
style.display = "";
}
return style;
},
/**
* Method: applySymbolizer
*
* Parameters:
* rule - {OpenLayers.Rule}
* style - {Object}
* feature - {<OpenLayer.Feature.Vector>}
* context - {Object}
*
* Returns:
* {Object} A style with new symbolizer applied.
*/
applySymbolizer: function(rule, style, feature, context) {
var symbolizerPrefix = feature.geometry ?
this.getSymbolizerPrefix(feature.geometry) :
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
var symbolizer = rule.symbolizer[symbolizerPrefix];
// merge the style with the current style
return this.createLiterals(
OpenLayers.Util.extend(style, symbolizer), context);
},
/**
* Method: createLiterals
* creates literals for all style properties that have an entry in
* <this.propertyStyles>.
*
* Parameters:
* style - {Object} style to create literals for. Will be modified
* inline.
* context - {Object} context to take property values from. Defaults to
* feature.attributes (or feature.data, if attributes are not
* available)
*
* Returns;
* {Object} the modified style
*/
createLiterals: function(style, context) {
for (var i in this.propertyStyles) {
style[i] = OpenLayers.Style.createLiteral(style[i], context);
}
return style;
},
/**
* Method: findPropertyStyles
* Looks into all rules for this style and the defaultStyle to collect
* all the style hash property names containing ${...} strings that have
* to be replaced using the createLiteral method before returning them.
*
* Returns:
* {Object} hash of property names that need createLiteral parsing. The
* name of the property is the key, and the value is true;
*/
findPropertyStyles: function() {
var propertyStyles = {};
// check the default style
var style = this.defaultStyle;
for (var i in style) {
if (typeof style[i] == "string" && style[i].match(/\$\{\w+\}/)) {
propertyStyles[i] = true;
}
}
// walk through all rules to check for properties in their symbolizer
var rules = this.rules;
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
for (var i in rules) {
for (var s=0; s<prefixes.length; s++) {
style = rules[i].symbolizer[prefixes[s]];
for (var j in style) {
if (typeof style[j] == "string" &&
style[j].match(/\$\{\w+\}/)) {
propertyStyles[j] = true;
}
}
}
}
return propertyStyles;
},
/**
* APIMethod: addRules
* Adds rules to this style.
*
* Parameters:
* rules - {Array(<OpenLayers.Rule>)}
*/
addRules: function(rules) {
this.rules = this.rules.concat(rules);
this.propertyStyles = this.findPropertyStyles();
},
/**
* APIMethod: setDefaultStyle
* Sets the default style for this style object.
*
* Parameters:
* style - {Object} Hash of style properties
*/
setDefaultStyle: function(style) {
this.defaultStyle = style;
this.propertyStyles = this.findPropertyStyles();
},
/**
* Method: getSymbolizerPrefix
* Returns the correct symbolizer prefix according to the
* geometry type of the passed geometry
*
* Parameters:
* geometry {<OpenLayers.Geometry>}
*
* Returns:
* {String} key of the according symbolizer
*/
getSymbolizerPrefix: function(geometry) {
var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
for (var i=0; i<prefixes.length; i++) {
if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) {
return prefixes[i];
}
}
},
CLASS_NAME: "OpenLayers.Style"
});
/**
* Function: createLiteral
* converts a style value holding a combination of PropertyName and Literal
* into a Literal, taking the property values from the passed features.
*
* Parameters:
* value {String} value to parse. If this string contains a construct like
* "foo ${bar}", then "foo " will be taken as literal, and "${bar}"
* will be replaced by the value of the "bar" attribute of the passed
* feature.
* context {Object} context to take attribute values from
*
* Returns:
* {String} the parsed value. In the example of the value parameter above, the
* result would be "foo valueOfBar", assuming that the passed feature has an
* attribute named "bar" with the value "valueOfBar".
*/
OpenLayers.Style.createLiteral = function(value, context) {
if (typeof value == "string" && value.indexOf("${") != -1) {
value = OpenLayers.String.format(value, context)
value = isNaN(value) ? value : parseFloat(value);
}
return value;
}
/**
* Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES
* {Array} prefixes of the sld symbolizers. These are the
* same as the main geometry types
*/
OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon'];

View File

@@ -1,180 +1,180 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_01_Element_visible(t) {
t.plan(3);
var elem = {
style: {
'display': ""
}
};
elem.style.display = "";
t.ok(OpenLayers.Element.visible(elem), "element with style.display == '' is visible");
elem.style.display = "block";
t.ok(OpenLayers.Element.visible(elem), "element with style.display == block is visible");
elem.style.display = "none";
t.ok(!OpenLayers.Element.visible(elem), "element with style.display == none is not visible");
}
function test_02_Element_toggle(t) {
t.plan(2);
var elem1 = {
style: {
'display': "none"
}
};
var elem2 = {
style: {
'display': ""
}
};
OpenLayers.Element.toggle(elem1, elem2);
t.eq(elem1.style.display, "", "hidden element toggled to display");
t.eq(elem2.style.display, "none", "shown element toggled to hidden");
}
function test_03_Element_hide(t) {
t.plan(2);
var elem1 = {
style: {
'display': "none"
}
};
var elem2 = {
style: {
'display': ""
}
};
OpenLayers.Element.hide(elem1, elem2);
t.eq(elem1.style.display, "none", "hidden element stays hidden");
t.eq(elem2.style.display, "none", "shown element hidden");
}
function test_04_Element_show(t) {
t.plan(2);
var elem1 = {
style: {
'display': "none"
}
};
var elem2 = {
style: {
'display': ""
}
};
OpenLayers.Element.show(elem1, elem2);
t.eq(elem1.style.display, "", "hidden element shown");
t.eq(elem2.style.display, "", "shown element stays shown");
}
function test_05_Element_remove(t) {
t.plan(1);
var elem = {
parentNode: {
'removeChild': function(elem) {
t.ok(true, "removeChild called");
}
}
};
OpenLayers.Element.remove(elem);
}
function test_06_Element_getHeight(t) {
t.plan(1);
var elem = {
'offsetHeight': {}
};
t.ok(OpenLayers.Element.getHeight(elem) == elem.offsetHeight, "offsetHeight returned");
}
function test_07_Element_getDimensions(t) {
t.plan(4);
//shown
t.open_window( "BaseTypes/test_Element.html", function( wnd ) {
t.delay_call( 0.5, function() {
var elem = wnd.document.getElementById("elemID");
var dims = OpenLayers.Element.getDimensions(elem);
t.eq(dims.width, 50, "width correct when displayed");
t.eq(dims.height, 100, "height correct when displayed")
elem.style.display = "none";
dims = OpenLayers.Element.getDimensions(elem);
t.eq(dims.width, 50, "width correct when hidden");
t.eq(dims.height, 100, "height correct when hidden")
});
});
//hidden
}
function test_08_Element_getStyle(t) {
t.plan(4);
//tests for this function are not 100% complete... there is some funky
// business going on in there with
// * document.defaultView (moz/ff I believe)
// but I cant seem to find a good way to test them.
//
var elem = document.getElementById("elemID");
elem.style.chickenHead = {}
var style = "chickenHead";
t.ok(OpenLayers.Element.getStyle(elem, style) == elem.style.chickenHead, "get style on basic stylename returns correctly");
elem.style.chickenHead = "auto";
style = "chickenHead";
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "get style on 'auto' style returns null");
if (OpenLayers.Util.getBrowserName() == "opera") {
elem.style.top = "15px";
style = "top";
elem.style.position = "static";
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position == 'static' returns null");
elem.style.position = "";
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position != 'static', gets computedStyle as static and returns null");
} else {
t.ok(true, "browser is not opera.");
t.ok(true, "trust me. browser is not opera.");
}
}
</script>
</head>
<body>
<div id="elemID" style="width:50px; height:100px; background-color:red">test</div>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_01_Element_visible(t) {
t.plan(3);
var elem = {
style: {
'display': ""
}
};
elem.style.display = "";
t.ok(OpenLayers.Element.visible(elem), "element with style.display == '' is visible");
elem.style.display = "block";
t.ok(OpenLayers.Element.visible(elem), "element with style.display == block is visible");
elem.style.display = "none";
t.ok(!OpenLayers.Element.visible(elem), "element with style.display == none is not visible");
}
function test_02_Element_toggle(t) {
t.plan(2);
var elem1 = {
style: {
'display': "none"
}
};
var elem2 = {
style: {
'display': ""
}
};
OpenLayers.Element.toggle(elem1, elem2);
t.eq(elem1.style.display, "", "hidden element toggled to display");
t.eq(elem2.style.display, "none", "shown element toggled to hidden");
}
function test_03_Element_hide(t) {
t.plan(2);
var elem1 = {
style: {
'display': "none"
}
};
var elem2 = {
style: {
'display': ""
}
};
OpenLayers.Element.hide(elem1, elem2);
t.eq(elem1.style.display, "none", "hidden element stays hidden");
t.eq(elem2.style.display, "none", "shown element hidden");
}
function test_04_Element_show(t) {
t.plan(2);
var elem1 = {
style: {
'display': "none"
}
};
var elem2 = {
style: {
'display': ""
}
};
OpenLayers.Element.show(elem1, elem2);
t.eq(elem1.style.display, "", "hidden element shown");
t.eq(elem2.style.display, "", "shown element stays shown");
}
function test_05_Element_remove(t) {
t.plan(1);
var elem = {
parentNode: {
'removeChild': function(elem) {
t.ok(true, "removeChild called");
}
}
};
OpenLayers.Element.remove(elem);
}
function test_06_Element_getHeight(t) {
t.plan(1);
var elem = {
'offsetHeight': {}
};
t.ok(OpenLayers.Element.getHeight(elem) == elem.offsetHeight, "offsetHeight returned");
}
function test_07_Element_getDimensions(t) {
t.plan(4);
//shown
t.open_window( "BaseTypes/test_Element.html", function( wnd ) {
t.delay_call( 0.5, function() {
var elem = wnd.document.getElementById("elemID");
var dims = OpenLayers.Element.getDimensions(elem);
t.eq(dims.width, 50, "width correct when displayed");
t.eq(dims.height, 100, "height correct when displayed")
elem.style.display = "none";
dims = OpenLayers.Element.getDimensions(elem);
t.eq(dims.width, 50, "width correct when hidden");
t.eq(dims.height, 100, "height correct when hidden")
});
});
//hidden
}
function test_08_Element_getStyle(t) {
t.plan(4);
//tests for this function are not 100% complete... there is some funky
// business going on in there with
// * document.defaultView (moz/ff I believe)
// but I cant seem to find a good way to test them.
//
var elem = document.getElementById("elemID");
elem.style.chickenHead = {}
var style = "chickenHead";
t.ok(OpenLayers.Element.getStyle(elem, style) == elem.style.chickenHead, "get style on basic stylename returns correctly");
elem.style.chickenHead = "auto";
style = "chickenHead";
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "get style on 'auto' style returns null");
if (OpenLayers.Util.getBrowserName() == "opera") {
elem.style.top = "15px";
style = "top";
elem.style.position = "static";
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position == 'static' returns null");
elem.style.position = "";
t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position != 'static', gets computedStyle as static and returns null");
} else {
t.ok(true, "browser is not opera.");
t.ok(true, "trust me. browser is not opera.");
}
}
</script>
</head>
<body>
<div id="elemID" style="width:50px; height:100px; background-color:red">test</div>
</body>
</html>

View File

@@ -157,173 +157,173 @@
data = parser.read(test_content[0]);
t.eq(data[0].attributes['NAME'], "WY", "Simple Attribute data is read correctly.");
t.eq(data[0].attributes['LONGNAME'], "Wyoming", "Attribute data is read from CDATA node correctly.");
}
function test_Format_GML_read_envelope_geom(t) {
t.plan(13);
var envelope = shell_start + geoms['envelope'] + shell_end;
var parser = new OpenLayers.Format.GML();
data = parser.read(envelope);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Envelope GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 0, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 1, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 20, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 1, "second y coord correct");
t.eq(data[0].geometry.components[0].components[2].x, 20, "third x coord correct");
t.eq(data[0].geometry.components[0].components[2].y, 21, "third y coord correct");
t.eq(data[0].geometry.components[0].components[3].x, 0, "fouth x coord correct");
t.eq(data[0].geometry.components[0].components[3].y, 21, "fourth y coord correct");
t.eq(data[0].geometry.components[0].components[4].x, 0, "fifth x coord correct");
t.eq(data[0].geometry.components[0].components[4].y, 1, "fifth y coord correct");
t.eq(data[0].geometry.components[0].components.length, 5, "coords length correct");
t.eq(data[0].geometry.components.length, 1, "rings length correct");
}
///////////////////////////////////////////////////////////////
// tests the y x order of gml point
/////////////////////////////////////////////////////////////
function test_Format_GML_read_point_geom_yx(t) {
t.plan(3);
var point = shell_start + geoms_yx['point'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(point);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "Point GML returns correct classname");
t.eq(data[0].geometry.x, 1, "x coord correct");
t.eq(data[0].geometry.y, 2, "y coord correct");
}
function test_Format_GML_read_linestring_geom_yx(t) {
t.plan(5);
var line = shell_start + geoms_yx['linestring'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(line);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "LineString GML returns correct classname");
t.eq(data[0].geometry.components[0].x, 1, "first x coord correct");
t.eq(data[0].geometry.components[0].y, 2, "first y coord correct");
t.eq(data[0].geometry.components[1].x, 4, "second x coord correct");
t.eq(data[0].geometry.components[1].y, 5, "second y coord correct");
}
function test_Format_GML_read_polygon_geom_yx(t) {
t.plan(7);
var polygon = shell_start + geoms_yx['polygon'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(polygon);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct");
t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct");
t.eq(data[0].geometry.components.length, 1, "rings length correct");
}
function test_Format_GML_read_multipoint_geom_yx(t) {
t.plan(6);
var multipoint = shell_start + geoms_yx['multipoint'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(multipoint);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "MultiPoint GML returns correct classname");
t.eq(data[0].geometry.components[0].x, 1, "x coord correct");
t.eq(data[0].geometry.components[0].y, 2, "y coord correct");
t.eq(data[0].geometry.components.length, 2, "length correct");
t.eq(data[0].geometry.components[1].x, 4, "x coord correct");
t.eq(data[0].geometry.components[1].y, 5, "y coord correct");
}
function test_Format_GML_read_multilinestring_geom_yx(t) {
t.plan(6);
var multilinestring = shell_start + geoms_yx['multilinestring'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(multilinestring);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "MultiLineString GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 1, "x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 2, "y coord correct");
t.eq(data[0].geometry.components[0].components.length, 2, "length correct");
t.eq(data[0].geometry.components[0].components[1].x, 4, "x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 5, "y coord correct");
}
function test_Format_GML_read_polygon_with_holes_geom_yx(t) {
t.plan(12);
var polygon_with_holes = shell_start + geoms_yx['polygon_with_holes'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(polygon_with_holes);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct");
t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct");
t.eq(data[0].geometry.components[1].components[0].x, 11, "first x coord correct");
t.eq(data[0].geometry.components[1].components[0].y, 12, "first y coord correct");
t.eq(data[0].geometry.components[1].components[1].x, 14, "second x coord correct");
t.eq(data[0].geometry.components[1].components[1].y, 15, "second y coord correct");
t.eq(data[0].geometry.components[1].components.length, 4, "coords length correct");
t.eq(data[0].geometry.components.length, 2, "rings length correct");
}
function test_Format_GML_read_envelope_geom_yx(t) {
t.plan(13);
var envelope = shell_start + geoms_yx['envelope'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(envelope);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Envelope GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 0, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 1, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 20, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 1, "second y coord correct");
t.eq(data[0].geometry.components[0].components[2].x, 20, "third x coord correct");
t.eq(data[0].geometry.components[0].components[2].y, 21, "third y coord correct");
t.eq(data[0].geometry.components[0].components[3].x, 0, "fouth x coord correct");
t.eq(data[0].geometry.components[0].components[3].y, 21, "fourth y coord correct");
t.eq(data[0].geometry.components[0].components[4].x, 0, "fifth x coord correct");
t.eq(data[0].geometry.components[0].components[4].y, 1, "fifth y coord correct");
t.eq(data[0].geometry.components[0].components.length, 5, "coords length correct");
t.eq(data[0].geometry.components.length, 1, "rings length correct");
}
function test_Format_GML_write_geoms_yx(t) {
t.plan(5);
var parser = new OpenLayers.Format.GML({'xy':false});
var point_xy = shell_start + serialize_geoms['point'] + shell_end;
var point = shell_start + serialize_geoms_yx['point'] + shell_end;
data = parser.read(point);
var output = parser.write(data);
}
function test_Format_GML_read_envelope_geom(t) {
t.plan(13);
var envelope = shell_start + geoms['envelope'] + shell_end;
var parser = new OpenLayers.Format.GML();
data = parser.read(envelope);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Envelope GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 0, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 1, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 20, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 1, "second y coord correct");
t.eq(data[0].geometry.components[0].components[2].x, 20, "third x coord correct");
t.eq(data[0].geometry.components[0].components[2].y, 21, "third y coord correct");
t.eq(data[0].geometry.components[0].components[3].x, 0, "fouth x coord correct");
t.eq(data[0].geometry.components[0].components[3].y, 21, "fourth y coord correct");
t.eq(data[0].geometry.components[0].components[4].x, 0, "fifth x coord correct");
t.eq(data[0].geometry.components[0].components[4].y, 1, "fifth y coord correct");
t.eq(data[0].geometry.components[0].components.length, 5, "coords length correct");
t.eq(data[0].geometry.components.length, 1, "rings length correct");
}
///////////////////////////////////////////////////////////////
// tests the y x order of gml point
/////////////////////////////////////////////////////////////
function test_Format_GML_read_point_geom_yx(t) {
t.plan(3);
var point = shell_start + geoms_yx['point'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(point);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Point", "Point GML returns correct classname");
t.eq(data[0].geometry.x, 1, "x coord correct");
t.eq(data[0].geometry.y, 2, "y coord correct");
}
function test_Format_GML_read_linestring_geom_yx(t) {
t.plan(5);
var line = shell_start + geoms_yx['linestring'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(line);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "LineString GML returns correct classname");
t.eq(data[0].geometry.components[0].x, 1, "first x coord correct");
t.eq(data[0].geometry.components[0].y, 2, "first y coord correct");
t.eq(data[0].geometry.components[1].x, 4, "second x coord correct");
t.eq(data[0].geometry.components[1].y, 5, "second y coord correct");
}
function test_Format_GML_read_polygon_geom_yx(t) {
t.plan(7);
var polygon = shell_start + geoms_yx['polygon'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(polygon);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct");
t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct");
t.eq(data[0].geometry.components.length, 1, "rings length correct");
}
function test_Format_GML_read_multipoint_geom_yx(t) {
t.plan(6);
var multipoint = shell_start + geoms_yx['multipoint'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(multipoint);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "MultiPoint GML returns correct classname");
t.eq(data[0].geometry.components[0].x, 1, "x coord correct");
t.eq(data[0].geometry.components[0].y, 2, "y coord correct");
t.eq(data[0].geometry.components.length, 2, "length correct");
t.eq(data[0].geometry.components[1].x, 4, "x coord correct");
t.eq(data[0].geometry.components[1].y, 5, "y coord correct");
}
function test_Format_GML_read_multilinestring_geom_yx(t) {
t.plan(6);
var multilinestring = shell_start + geoms_yx['multilinestring'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(multilinestring);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "MultiLineString GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 1, "x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 2, "y coord correct");
t.eq(data[0].geometry.components[0].components.length, 2, "length correct");
t.eq(data[0].geometry.components[0].components[1].x, 4, "x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 5, "y coord correct");
}
function test_Format_GML_read_polygon_with_holes_geom_yx(t) {
t.plan(12);
var polygon_with_holes = shell_start + geoms_yx['polygon_with_holes'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(polygon_with_holes);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Polygon GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 1, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 2, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 4, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 5, "second y coord correct");
t.eq(data[0].geometry.components[0].components.length, 4, "coords length correct");
t.eq(data[0].geometry.components[1].components[0].x, 11, "first x coord correct");
t.eq(data[0].geometry.components[1].components[0].y, 12, "first y coord correct");
t.eq(data[0].geometry.components[1].components[1].x, 14, "second x coord correct");
t.eq(data[0].geometry.components[1].components[1].y, 15, "second y coord correct");
t.eq(data[0].geometry.components[1].components.length, 4, "coords length correct");
t.eq(data[0].geometry.components.length, 2, "rings length correct");
}
function test_Format_GML_read_envelope_geom_yx(t) {
t.plan(13);
var envelope = shell_start + geoms_yx['envelope'] + shell_end;
var parser = new OpenLayers.Format.GML({'xy':false});
data = parser.read(envelope);
t.eq(data[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "Envelope GML returns correct classname");
t.eq(data[0].geometry.components[0].components[0].x, 0, "first x coord correct");
t.eq(data[0].geometry.components[0].components[0].y, 1, "first y coord correct");
t.eq(data[0].geometry.components[0].components[1].x, 20, "second x coord correct");
t.eq(data[0].geometry.components[0].components[1].y, 1, "second y coord correct");
t.eq(data[0].geometry.components[0].components[2].x, 20, "third x coord correct");
t.eq(data[0].geometry.components[0].components[2].y, 21, "third y coord correct");
t.eq(data[0].geometry.components[0].components[3].x, 0, "fouth x coord correct");
t.eq(data[0].geometry.components[0].components[3].y, 21, "fourth y coord correct");
t.eq(data[0].geometry.components[0].components[4].x, 0, "fifth x coord correct");
t.eq(data[0].geometry.components[0].components[4].y, 1, "fifth y coord correct");
t.eq(data[0].geometry.components[0].components.length, 5, "coords length correct");
t.eq(data[0].geometry.components.length, 1, "rings length correct");
}
function test_Format_GML_write_geoms_yx(t) {
t.plan(5);
var parser = new OpenLayers.Format.GML({'xy':false});
var point_xy = shell_start + serialize_geoms['point'] + shell_end;
var point = shell_start + serialize_geoms_yx['point'] + shell_end;
data = parser.read(point);
var output = parser.write(data);
var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(output, point_xy, "Point geometry round trips correctly.");
var linestring_xy = shell_start + serialize_geoms['linestring'] + shell_end;
var linestring = shell_start + serialize_geoms_yx['linestring'] + shell_end;
data = parser.read(linestring);
var output = parser.write(data);
t.eq(output, point_xy, "Point geometry round trips correctly.");
var linestring_xy = shell_start + serialize_geoms['linestring'] + shell_end;
var linestring = shell_start + serialize_geoms_yx['linestring'] + shell_end;
data = parser.read(linestring);
var output = parser.write(data);
var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(output, linestring_xy, "Line geometry round trips correctly.");
var polygon_xy = shell_start + serialize_geoms['polygon'] + shell_end;
var polygon = shell_start + serialize_geoms_yx['polygon'] + shell_end;
data = parser.read(polygon);
var output = parser.write(data);
t.eq(output, linestring_xy, "Line geometry round trips correctly.");
var polygon_xy = shell_start + serialize_geoms['polygon'] + shell_end;
var polygon = shell_start + serialize_geoms_yx['polygon'] + shell_end;
data = parser.read(polygon);
var output = parser.write(data);
output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(output, polygon_xy, "Poly geometry round trips correctly.");
var multipoint_xy = shell_start + serialize_geoms['multipoint'] + shell_end;
var multipoint = shell_start + serialize_geoms_yx['multipoint'] + shell_end;
data = parser.read(multipoint);
var output = parser.write(data);
t.eq(output, polygon_xy, "Poly geometry round trips correctly.");
var multipoint_xy = shell_start + serialize_geoms['multipoint'] + shell_end;
var multipoint = shell_start + serialize_geoms_yx['multipoint'] + shell_end;
data = parser.read(multipoint);
var output = parser.write(data);
var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(output, multipoint_xy, "MultiPoint geometry round trips correctly.");
var multilinestring_xy = shell_start + serialize_geoms['multilinestring'] + shell_end;
var multilinestring = shell_start + serialize_geoms_yx['multilinestring'] + shell_end;
data = parser.read(multilinestring);
var output = parser.write(data);
t.eq(output, multipoint_xy, "MultiPoint geometry round trips correctly.");
var multilinestring_xy = shell_start + serialize_geoms['multilinestring'] + shell_end;
var multilinestring = shell_start + serialize_geoms_yx['multilinestring'] + shell_end;
data = parser.read(multilinestring);
var output = parser.write(data);
var output = output.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(output, multilinestring_xy, "MultiLine geometry round trips correctly.");
}
t.eq(output, multilinestring_xy, "MultiLine geometry round trips correctly.");
}
var test_content = ['<?xml version="1.0" encoding="utf-8" ?>\n<ogr:FeatureCollection\n xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="http://ogr.maptools.org/ testoutput.xsd"\n xmlns:ogr="http://ogr.maptools.org/"\n xmlns:gml="http://www.opengis.net/gml">\n <gml:boundedBy>\n <gml:Box>\n <gml:coord><gml:X>-1254041.389711702</gml:X><gml:Y>250906.9515983529</gml:Y></gml:coord>\n <gml:coord><gml:X>-634517.1199908922</gml:X><gml:Y>762236.2940800377</gml:Y></gml:coord>\n </gml:Box>\n </gml:boundedBy> \n <gml:featureMember>\n <ogr:states fid="F0">\n <ogr:geometryProperty><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>\n <ogr:NAME>WY</ogr:NAME>\n <ogr:LONGNAME><![CDATA[Wyoming]]></ogr:LONGNAME>\n </ogr:states>\n </gml:featureMember>\n</ogr:FeatureCollection>\n',
@@ -373,32 +373,32 @@
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>',
'polygon_with_holes': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,2 4,5 3,6 1,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>11,12 14,15 13,16 11,12</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>',
'multipoint': '<gml:MultiPoint><gml:Point><gml:coordinates>1,2,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>4,5,6</gml:coordinates></gml:Point></gml:MultiPoint>',
'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>1,2,3 4,5,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>11,12,13 14,15,16</gml:coordinates></gml:LineString></gml:MultiLineString>',
'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>1,2,3 4,5,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>11,12,13 14,15,16</gml:coordinates></gml:LineString></gml:MultiLineString>',
'envelope': '<gml:Envelope><gml:lowerCorner>0 1</gml:lowerCorner><gml:upperCorner>20 21</gml:upperCorner></gml:Envelope>' // ,
// 'multipolygon_with_holes': '<gml:MultiPolygon><gml:Polygon><gml:outerBoundaryIs>1,2 4,5 3,6 1,2</gml:outerBoundaryIs><gml:innerBoundaryIs>11,12 14,15 13,16 11,12</gml:innerBoundaryIs></gml:Polygon><gml:Polygon><gml:outerBoundaryIs>101,102 104,105 103,106 101,102</gml:outerBoundaryIs><gml:innerBoundaryIs>111,112 114,115 113,116 111,112</gml:innerBoundaryIs></gml:Polygon></gml:MultiPolygon>'
};
//
// The following data has the (x y) reordered to (y x), in 3 dimensions it goes from (x y z) to (y x z)
//
var serialize_geoms_yx = {
'point': '<gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point>',
'linestring': '<gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString>',
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>',
'multipoint': '<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">5,4</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>',
'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">12,11 15,14</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>'
};
var geoms_yx = {
'point': '<gml:Point><gml:coordinates>2,1,3</gml:coordinates></gml:Point>',
'linestring': '<gml:LineString><gml:coordinates>2,1,3 5,4,6</gml:coordinates></gml:LineString>',
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>',
'polygon_with_holes': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>12,11 15,14 16,13 12,11</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>',
'multipoint': '<gml:MultiPoint><gml:Point><gml:coordinates>2,1,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>5,4,6</gml:coordinates></gml:Point></gml:MultiPoint>',
'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>2,1,3 5,4,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>12,11,13 15,14,16</gml:coordinates></gml:LineString></gml:MultiLineString>',
'envelope': '<gml:Envelope><gml:lowerCorner>1 0</gml:lowerCorner><gml:upperCorner>21 20</gml:upperCorner></gml:Envelope>'
};
};
//
// The following data has the (x y) reordered to (y x), in 3 dimensions it goes from (x y z) to (y x z)
//
var serialize_geoms_yx = {
'point': '<gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point>',
'linestring': '<gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString>',
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>',
'multipoint': '<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">2,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates decimal="." cs="," ts=" ">5,4</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>',
'multilinestring': '<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">2,1 5,4</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates decimal="." cs="," ts=" ">12,11 15,14</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>'
};
var geoms_yx = {
'point': '<gml:Point><gml:coordinates>2,1,3</gml:coordinates></gml:Point>',
'linestring': '<gml:LineString><gml:coordinates>2,1,3 5,4,6</gml:coordinates></gml:LineString>',
'polygon': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>',
'polygon_with_holes': '<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,1 5,4 6,3 2,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>12,11 15,14 16,13 12,11</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>',
'multipoint': '<gml:MultiPoint><gml:Point><gml:coordinates>2,1,3</gml:coordinates></gml:Point><gml:Point><gml:coordinates>5,4,6</gml:coordinates></gml:Point></gml:MultiPoint>',
'multilinestring': '<gml:MultiLineString><gml:LineString><gml:coordinates>2,1,3 5,4,6</gml:coordinates></gml:LineString><gml:LineString><gml:coordinates>12,11,13 15,14,16</gml:coordinates></gml:LineString></gml:MultiLineString>',
'envelope': '<gml:Envelope><gml:lowerCorner>1 0</gml:lowerCorner><gml:upperCorner>21 20</gml:upperCorner></gml:Envelope>'
};
</script>
</head>

View File

@@ -56,21 +56,21 @@
var out = out.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(out, expected_result, "Output gave expected value");
}
}
function test_Format_GeoRSS_gml_roundtrip(t) {
t.plan(input_gml.length);
var parser = new OpenLayers.Format.GeoRSS();
for(var i=0; i < input_gml.length; i++) {
var feed = shell_start_gml+input_gml[i]+shell_end_gml;
var data = parser.read(feed);
var out = parser.write(data);
}
function test_Format_GeoRSS_gml_roundtrip(t) {
t.plan(input_gml.length);
var parser = new OpenLayers.Format.GeoRSS();
for(var i=0; i < input_gml.length; i++) {
var feed = shell_start_gml+input_gml[i]+shell_end_gml;
var data = parser.read(feed);
var out = parser.write(data);
var expected_result = output_gml[i];
if (OpenLayers.Util.getBrowserName() == "opera") {
expected_result = expected_result.replace(/&gt;/g, ">");
}
var out = out.replace(/<\?[^>]*\?>/, ''); // Remove XML Prolog
t.eq(out, expected_result, "Output gave expected value");
}
}
}
var shell_start = '<feed xmlns="http://www.w3.org/2005/Atom" \n xmlns:georss="http://www.georss.org/georss">\n <title>scribble</title>\n <id>http://featureserver.org/featureserver.cgi/scribble?format=atom</id>\n <author><name>FeatureServer</name></author>\n';
@@ -81,21 +81,21 @@
];
var output= ['<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/562.atom</link><georss:polygon xmlns:georss="http://www.georss.org/georss">-5.9765625 -131.484375 -58.0078125 -112.5 -50.2734375 -32.34375 52.3828125 -114.609375 -35.5078125 -167.34375 -57.3046875 -146.953125 -34.1015625 -139.921875 -5.9765625 -131.484375</georss:polygon></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: 00ccff&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/796.atom</link><georss:point xmlns:georss="http://www.georss.org/georss">75.5859375 15.46875</georss:point></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 5</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 5&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/794.atom</link><georss:line xmlns:georss="http://www.georss.org/georss">28.828125 32.6953125 49.921875 34.8046875 39.375 58.0078125 39.375 58.0078125 40.078125 58.0078125 41.484375 58.0078125 43.59375 58.0078125 45.703125 58.7109375 47.8125 58.7109375 49.21875 58.7109375 51.328125 59.4140625 52.03125 59.4140625 54.140625 60.8203125 56.25 61.5234375 56.25 62.2265625 57.65625 62.2265625 57.65625 62.9296875 58.359375 63.6328125 58.359375 65.0390625 58.359375 65.7421875 59.0625 66.4453125 59.0625 67.1484375 59.0625 68.5546875 59.765625 69.9609375 59.765625 72.0703125 59.765625 73.4765625 59.765625 76.2890625 59.765625 78.3984375 59.765625 79.8046875 59.765625 81.9140625 59.765625 83.3203125 59.0625 84.7265625 59.0625 86.8359375 58.359375 87.5390625 58.359375 88.2421875 56.953125 89.6484375 56.25 91.0546875 54.84375 93.8671875 52.03125 96.6796875 51.328125 98.7890625 50.625 100.1953125 49.21875 102.3046875 48.515625 103.7109375 47.8125 104.4140625 47.109375 105.8203125 46.40625 106.5234375 46.40625 107.9296875 45.703125 109.3359375 45 110.7421875 43.59375 112.8515625 43.59375 114.2578125 43.59375 114.9609375 42.890625 117.0703125 42.890625 117.7734375 42.1875 118.4765625 42.1875 119.1796875 42.1875 119.8828125</georss:line></item></rss>'
];
var shell_start_gml = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:gml="http://www.opengis.net/gml" xmlns:georss="http://www.georss.org/georss"> <title>scribble</title><id>http://featureserver.org/featureserver.cgi/scribble?format=atom</id><author><name>FeatureServer</name></author>';
var shell_end_gml = '</feed>';
var input_gml = ['<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:Point><gml:pos>0 10</gml:pos></gml:Point></georss:where></entry>',
'<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>110,-50 110,-10 155,-10 155,-50 110,-50</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></georss:where></entry>',
'<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:LineString><gml:coordinates>0,10 10,20</gml:coordinates></gml:LineString></georss:where></entry>',
'<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:Envelope><gml:lowerCorner>0 1</gml:lowerCorner><gml:upperCorner>20 21</gml:upperCorner></gml:Envelope></georss:where></entry>'
];
var output_gml = ['<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:point xmlns:georss="http://www.georss.org/georss">0 10</georss:point></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:polygon xmlns:georss="http://www.georss.org/georss">110 -50 110 -10 155 -10 155 -50 110 -50</georss:polygon></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:line xmlns:georss="http://www.georss.org/georss">0 10 10 20</georss:line></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:polygon xmlns:georss="http://www.georss.org/georss">0 1 0 21 20 21 20 1 0 1</georss:polygon></item></rss>'
];
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 5</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 5&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/794.atom</link><georss:line xmlns:georss="http://www.georss.org/georss">28.828125 32.6953125 49.921875 34.8046875 39.375 58.0078125 39.375 58.0078125 40.078125 58.0078125 41.484375 58.0078125 43.59375 58.0078125 45.703125 58.7109375 47.8125 58.7109375 49.21875 58.7109375 51.328125 59.4140625 52.03125 59.4140625 54.140625 60.8203125 56.25 61.5234375 56.25 62.2265625 57.65625 62.2265625 57.65625 62.9296875 58.359375 63.6328125 58.359375 65.0390625 58.359375 65.7421875 59.0625 66.4453125 59.0625 67.1484375 59.0625 68.5546875 59.765625 69.9609375 59.765625 72.0703125 59.765625 73.4765625 59.765625 76.2890625 59.765625 78.3984375 59.765625 79.8046875 59.765625 81.9140625 59.765625 83.3203125 59.0625 84.7265625 59.0625 86.8359375 58.359375 87.5390625 58.359375 88.2421875 56.953125 89.6484375 56.25 91.0546875 54.84375 93.8671875 52.03125 96.6796875 51.328125 98.7890625 50.625 100.1953125 49.21875 102.3046875 48.515625 103.7109375 47.8125 104.4140625 47.109375 105.8203125 46.40625 106.5234375 46.40625 107.9296875 45.703125 109.3359375 45 110.7421875 43.59375 112.8515625 43.59375 114.2578125 43.59375 114.9609375 42.890625 117.0703125 42.890625 117.7734375 42.1875 118.4765625 42.1875 119.1796875 42.1875 119.8828125</georss:line></item></rss>'
];
var shell_start_gml = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:gml="http://www.opengis.net/gml" xmlns:georss="http://www.georss.org/georss"> <title>scribble</title><id>http://featureserver.org/featureserver.cgi/scribble?format=atom</id><author><name>FeatureServer</name></author>';
var shell_end_gml = '</feed>';
var input_gml = ['<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:Point><gml:pos>0 10</gml:pos></gml:Point></georss:where></entry>',
'<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>110,-50 110,-10 155,-10 155,-50 110,-50</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></georss:where></entry>',
'<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:LineString><gml:coordinates>0,10 10,20</gml:coordinates></gml:LineString></georss:where></entry>',
'<entry><id>http://featureserver.org/featureserver.cgi/scribble/111.atom</id><link href="http://featureserver.org/featureserver.cgi/scribble/111.atom"/><title>Feature 2</title><content type="html">&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</content><georss:where><gml:Envelope><gml:lowerCorner>0 1</gml:lowerCorner><gml:upperCorner>20 21</gml:upperCorner></gml:Envelope></georss:where></entry>'
];
var output_gml = ['<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:point xmlns:georss="http://www.georss.org/georss">0 10</georss:point></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:polygon xmlns:georss="http://www.georss.org/georss">110 -50 110 -10 155 -10 155 -50 110 -50</georss:polygon></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:line xmlns:georss="http://www.georss.org/georss">0 10 10 20</georss:line></item></rss>',
'<rss xmlns="http://backend.userland.com/rss2"><item><title>Feature 2</title><description>&lt;b&gt;strokeColor&lt;/b&gt;: red&lt;br /&gt;&lt;b&gt;title&lt;/b&gt;: Feature 2&lt;br /&gt;&lt;b&gt;author&lt;/b&gt;: Your Name Here</description><link>http://featureserver.org/featureserver.cgi/scribble/111.atom</link><georss:polygon xmlns:georss="http://www.georss.org/georss">0 1 0 21 20 21 20 1 0 1</georss:polygon></item></rss>'
];
</script>
</head>

View File

@@ -1,107 +1,107 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Handler_Path_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var oldInit = OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"constructor calls parent with the correct options");
}
var handler = new OpenLayers.Handler.Path(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit;
}
function test_Handler_Path_activation(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Path(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
handler.active = false;
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
map.destroy();
}
function test_Handler_Path_bounds(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Path(control, {});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
handler.mousemove(evt);
t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
map.destroy();
}
function test_Handler_Path_destroy(t) {
t.plan(6);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Path(control, {foo: 'bar'});
handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
t.ok(handler.layer,
"handler has a layer prior to destroy");
t.ok(handler.point,
"handler has a point prior to destroy");
t.ok(handler.line,
"handler has a line prior to destroy");
handler.destroy();
t.eq(handler.layer, null,
"handler.layer is null after destroy");
t.eq(handler.point, null,
"handler.point is null after destroy");
t.eq(handler.line, null,
"handler.line is null after destroy");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Handler_Path_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var oldInit = OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"constructor calls parent with the correct options");
}
var handler = new OpenLayers.Handler.Path(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit;
}
function test_Handler_Path_activation(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Path(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
handler.active = false;
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
map.destroy();
}
function test_Handler_Path_bounds(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Path(control, {});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
handler.mousemove(evt);
t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
map.destroy();
}
function test_Handler_Path_destroy(t) {
t.plan(6);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Path(control, {foo: 'bar'});
handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
t.ok(handler.layer,
"handler has a layer prior to destroy");
t.ok(handler.point,
"handler has a point prior to destroy");
t.ok(handler.line,
"handler has a line prior to destroy");
handler.destroy();
t.eq(handler.layer, null,
"handler.layer is null after destroy");
t.eq(handler.point, null,
"handler.point is null after destroy");
t.eq(handler.line, null,
"handler.line is null after destroy");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>

View File

@@ -1,113 +1,113 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Handler_Polygon_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var oldInit = OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"constructor calls parent with the correct options");
}
var handler = new OpenLayers.Handler.Polygon(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit;
}
function test_Handler_Polygon_activation(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Polygon(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
handler.active = false;
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
map.destroy();
}
function test_Handler_Polygon_bounds(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Polygon(control, {});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
handler.mousemove(evt);
t.ok(!handler.polygon.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
"Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
map.destroy();
}
function test_Handler_Polygon_destroy(t) {
t.plan(8);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Polygon(control, {foo: 'bar'});
handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
t.ok(handler.layer,
"handler has a layer prior to destroy");
t.ok(handler.point,
"handler has a point prior to destroy");
t.ok(handler.line,
"handler has a line prior to destroy");
t.ok(handler.polygon,
"handler has a polygon prior to destroy");
handler.destroy();
t.eq(handler.layer, null,
"handler.layer is null after destroy");
t.eq(handler.point, null,
"handler.point is null after destroy");
t.eq(handler.line, null,
"handler.line is null after destroy");
t.eq(handler.polygon, null,
"handler.polygon is null after destroy");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Handler_Polygon_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var oldInit = OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"constructor calls parent with the correct options");
}
var handler = new OpenLayers.Handler.Polygon(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit;
}
function test_Handler_Polygon_activation(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Polygon(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
handler.active = false;
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
map.destroy();
}
function test_Handler_Polygon_bounds(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Polygon(control, {});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
handler.mouseup(evt);
t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
handler.mousemove(evt);
t.ok(!handler.polygon.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
"Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
map.destroy();
}
function test_Handler_Polygon_destroy(t) {
t.plan(8);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Polygon(control, {foo: 'bar'});
handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousedown(evt);
t.ok(handler.layer,
"handler has a layer prior to destroy");
t.ok(handler.point,
"handler has a point prior to destroy");
t.ok(handler.line,
"handler has a line prior to destroy");
t.ok(handler.polygon,
"handler has a polygon prior to destroy");
handler.destroy();
t.eq(handler.layer, null,
"handler.layer is null after destroy");
t.eq(handler.point, null,
"handler.point is null after destroy");
t.eq(handler.line, null,
"handler.line is null after destroy");
t.eq(handler.polygon, null,
"handler.polygon is null after destroy");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>

View File

@@ -1,49 +1,49 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Handler_RegularPolygon_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var oldInit = OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"regular polygon constructor calls parent with the correct options");
}
var handler = new OpenLayers.Handler.RegularPolygon(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit;
}
function test_Handler_RegularPolygon_activation(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
handler.active = false;
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Handler_RegularPolygon_constructor(t) {
t.plan(3);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {foo: "bar"};
var options = {bar: "foo"};
var oldInit = OpenLayers.Handler.prototype.initialize;
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
t.eq(con.id, control.id,
"constructor calls parent with the correct control");
t.eq(call, callbacks,
"constructor calls parent with the correct callbacks");
t.eq(opt, options,
"regular polygon constructor calls parent with the correct options");
}
var handler = new OpenLayers.Handler.RegularPolygon(control, callbacks, options);
OpenLayers.Handler.prototype.initialize = oldInit;
}
function test_Handler_RegularPolygon_activation(t) {
t.plan(3);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control);
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
handler.active = false;
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
map.destroy();
}
}
function test_Handler_RegularPolygon_deactivation(t) {
t.plan(1);
var map = new OpenLayers.Map('map');
@@ -58,91 +58,91 @@
"deactivate doesn't throw an error if layer was" +
" previously destroyed");
map.destroy();
}
function test_Handler_RegularPolygon_four_corners(t) {
t.plan(7);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control, {});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.15625,-35.15625,35.15625,35.15625",
"correct bounds after move");
t.eq(handler.feature.geometry.components[0].components.length, 5,
"geometry has 5 components");
t.eq(handler.feature.geometry.CLASS_NAME,
"OpenLayers.Geometry.Polygon",
"geometry is a polygon");
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.15625,-35.15625,35.15625,35.15625",
"correct bounds after move with a fixed radius");
handler.cancel();
handler.setOptions({radius:2 / Math.sqrt(2)});
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-1,-1,1,1",
"bounds with manual radius setting");
var evt = {xy: new OpenLayers.Pixel(175, 90), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"34.15625,-22.09375,36.15625,-20.09375",
"bounds with manual radius setting and mousemove");
}
function test_Handler_RegularPolygon_four_corners(t) {
t.plan(7);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control, {});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.15625,-35.15625,35.15625,35.15625",
"correct bounds after move");
t.eq(handler.feature.geometry.components[0].components.length, 5,
"geometry has 5 components");
t.eq(handler.feature.geometry.CLASS_NAME,
"OpenLayers.Geometry.Polygon",
"geometry is a polygon");
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.15625,-35.15625,35.15625,35.15625",
"correct bounds after move with a fixed radius");
handler.cancel();
handler.setOptions({radius:2 / Math.sqrt(2)});
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-1,-1,1,1",
"bounds with manual radius setting");
var evt = {xy: new OpenLayers.Pixel(175, 90), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"34.15625,-22.09375,36.15625,-20.09375",
"bounds with manual radius setting and mousemove");
map.destroy();
}
function test_Handler_RegularPolygon_circle(t) {
t.plan(7);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control, {}, {'sides':40});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.15625,-35.15625,35.15625,35.15625",
"correct bounds after move");
t.eq(handler.feature.geometry.components[0].components.length, 41,
"geometry has correct numbre of components");
t.eq(handler.feature.geometry.CLASS_NAME,
"OpenLayers.Geometry.Polygon",
"geometry is a polygon");
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.823348,-35.823348,35.823348,35.823348",
"correct bounds after move with fixed radius");
handler.cancel();
handler.setOptions({radius:1});
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-0.996917,-0.996917,0.996917,0.996917",
"bounds with manual radius setting");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"34.159333,-8.028167,36.153167,-6.034333",
"bounds with manual radius setting and mousemove");
}
function test_Handler_RegularPolygon_circle(t) {
t.plan(7);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control, {}, {'sides':40});
var activated = handler.activate();
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.15625,-35.15625,35.15625,35.15625",
"correct bounds after move");
t.eq(handler.feature.geometry.components[0].components.length, 41,
"geometry has correct numbre of components");
t.eq(handler.feature.geometry.CLASS_NAME,
"OpenLayers.Geometry.Polygon",
"geometry is a polygon");
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-35.823348,-35.823348,35.823348,35.823348",
"correct bounds after move with fixed radius");
handler.cancel();
handler.setOptions({radius:1});
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.down(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"-0.996917,-0.996917,0.996917,0.996917",
"bounds with manual radius setting");
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
handler.move(evt);
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"34.159333,-8.028167,36.153167,-6.034333",
"bounds with manual radius setting and mousemove");
map.destroy();
}
@@ -185,10 +185,10 @@
// should result in a 10 x 5 rectangle
handler.move({xy: {x: 20, y: 15}});
}
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
</body>
</html>

View File

@@ -1,120 +1,120 @@
<html>
<head>
<script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var layer;
function test_01_Layer_Yahoo_constructor (t) {
t.plan( 4 );
var tempEventPane = OpenLayers.Layer.EventPane.prototype.initialize;
OpenLayers.Layer.EventPane.prototype.initialize = function(name, options) {
t.ok(name == g_Name, "EventPane initialize() called with correct name");
t.ok(options == g_Options, "EventPane initialize() called with correct options");
}
var tempFixedZoomLevels = OpenLayers.Layer.FixedZoomLevels.prototype.initialize;
OpenLayers.Layer.FixedZoomLevels.prototype.initialize = function(name, options) {
t.ok(name == g_Name, "FixedZoomLevels initialize() called with correct name");
t.ok(options == g_Options, "FixedZoomLevels initialize() called with correct options");
}
g_Name = {};
g_Options = {};
var l = new OpenLayers.Layer.Yahoo(g_Name, g_Options);
OpenLayers.Layer.EventPane.prototype.initialize = tempEventPane;
OpenLayers.Layer.FixedZoomLevels.prototype.initialize = tempFixedZoomLevels;
}
function test_02_Layer_Yahoo_loadMapObject(t) {
t.plan(5);
var temp = YMap;
YMap = OpenLayers.Class({
initialize: function(div, type, size) {
t.ok(div == g_Div, "correct div passed to YMap constructor");
t.ok(type == g_Type, "correct type passed to YMap constructor");
t.ok(size == g_YMapSize, "correct size passed to YMap constructor");
},
disableKeyControls: function() {
t.ok(true, "disableKeyControls called on map object");
}
});
g_Div = {};
g_Type = {};
g_MapSize = {};
g_YMapSize = {};
var l = new OpenLayers.Layer.Yahoo();
l.div = g_Div;
l.type = g_Type;
l.map = {
'getSize': function() {
return g_MapSize;
}
};
l.getMapObjectSizeFromOLSize = function(mapSize) {
t.ok(mapSize == g_MapSize, "correctly translating map size from ol to YSize");
return g_YMapSize;
};
l.loadMapObject();
YMap = temp;
}
function test_03_Layer_Yahoo_onMapResize(t) {
t.plan(2);
g_MapSize = {};
g_YMapSize = {};
var l = new OpenLayers.Layer.Yahoo();
l.mapObject = {
'resizeTo': function(size) {
t.ok(size == g_YMapSize, "correct YSize passed to reiszeTo on map object");
}
}
l.map = {
'getSize': function() {
return g_MapSize;
}
};
l.getMapObjectSizeFromOLSize = function(mapSize) {
t.ok(mapSize == g_MapSize, "correctly translating map size from ol to YSize");
return g_YMapSize;
};
l.onMapResize();
}
function test_04_Layer_Yahoo_getMapObjectSizeFromOLSize(t) {
t.plan(2);
var temp = YSize;
YSize = function(w, h) {
t.ok(w == g_Size.w, "correct width passed to YSize constructor");
t.ok(h == g_Size.h, "correct height passed to YSize constructor");
}
g_Size = {
'w': {},
'h': {}
};
OpenLayers.Layer.Yahoo.prototype.getMapObjectSizeFromOLSize(g_Size);
YSize = temp;
}
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
<html>
<head>
<script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var layer;
function test_01_Layer_Yahoo_constructor (t) {
t.plan( 4 );
var tempEventPane = OpenLayers.Layer.EventPane.prototype.initialize;
OpenLayers.Layer.EventPane.prototype.initialize = function(name, options) {
t.ok(name == g_Name, "EventPane initialize() called with correct name");
t.ok(options == g_Options, "EventPane initialize() called with correct options");
}
var tempFixedZoomLevels = OpenLayers.Layer.FixedZoomLevels.prototype.initialize;
OpenLayers.Layer.FixedZoomLevels.prototype.initialize = function(name, options) {
t.ok(name == g_Name, "FixedZoomLevels initialize() called with correct name");
t.ok(options == g_Options, "FixedZoomLevels initialize() called with correct options");
}
g_Name = {};
g_Options = {};
var l = new OpenLayers.Layer.Yahoo(g_Name, g_Options);
OpenLayers.Layer.EventPane.prototype.initialize = tempEventPane;
OpenLayers.Layer.FixedZoomLevels.prototype.initialize = tempFixedZoomLevels;
}
function test_02_Layer_Yahoo_loadMapObject(t) {
t.plan(5);
var temp = YMap;
YMap = OpenLayers.Class({
initialize: function(div, type, size) {
t.ok(div == g_Div, "correct div passed to YMap constructor");
t.ok(type == g_Type, "correct type passed to YMap constructor");
t.ok(size == g_YMapSize, "correct size passed to YMap constructor");
},
disableKeyControls: function() {
t.ok(true, "disableKeyControls called on map object");
}
});
g_Div = {};
g_Type = {};
g_MapSize = {};
g_YMapSize = {};
var l = new OpenLayers.Layer.Yahoo();
l.div = g_Div;
l.type = g_Type;
l.map = {
'getSize': function() {
return g_MapSize;
}
};
l.getMapObjectSizeFromOLSize = function(mapSize) {
t.ok(mapSize == g_MapSize, "correctly translating map size from ol to YSize");
return g_YMapSize;
};
l.loadMapObject();
YMap = temp;
}
function test_03_Layer_Yahoo_onMapResize(t) {
t.plan(2);
g_MapSize = {};
g_YMapSize = {};
var l = new OpenLayers.Layer.Yahoo();
l.mapObject = {
'resizeTo': function(size) {
t.ok(size == g_YMapSize, "correct YSize passed to reiszeTo on map object");
}
}
l.map = {
'getSize': function() {
return g_MapSize;
}
};
l.getMapObjectSizeFromOLSize = function(mapSize) {
t.ok(mapSize == g_MapSize, "correctly translating map size from ol to YSize");
return g_YMapSize;
};
l.onMapResize();
}
function test_04_Layer_Yahoo_getMapObjectSizeFromOLSize(t) {
t.plan(2);
var temp = YSize;
YSize = function(w, h) {
t.ok(w == g_Size.w, "correct width passed to YSize constructor");
t.ok(h == g_Size.h, "correct height passed to YSize constructor");
}
g_Size = {
'w': {},
'h': {}
};
OpenLayers.Layer.Yahoo.prototype.getMapObjectSizeFromOLSize(g_Size);
YSize = temp;
}
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>

View File

@@ -1,59 +1,59 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Popup_Anchored_setOpacity(t) {
t.plan(5);
var opacity = 0.5;
var id = "chicken";
var w = 500;
var h = 400;
var sz = new OpenLayers.Size(w,h);
var lon = 5;
var lat = 40;
var ll = new OpenLayers.LonLat(lon, lat);
var content = "foo";
var x = 50;
var y = 100;
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer('name', {'isBaseLayer':true}));
map.zoomToMaxExtent();
var popup = new OpenLayers.Popup.AnchoredBubble(id,
ll,
sz,
content,
null,
false);
map.addPopup(popup);
popup.setOpacity(opacity);
popup.draw(new OpenLayers.Pixel(x, y));
if (navigator.appName.indexOf("Microsoft") == -1) {
t.eq(parseFloat(popup.div.style.opacity), opacity, "good default popup.opacity");
} else {
t.eq(popup.div.style.filter, "alpha(opacity=" + opacity*100 + ")", "good default popup.opacity");
}
t.ok(popup.groupDiv!=null, "popup.groupDiv exists");
t.ok(popup.groupDiv.parentNode!=null, "popup.groupDiv.parentNode exists");
t.ok(popup.groupDiv.parentNode.getElementsByTagName("span").length > 0, "popup.groupDiv.parentNode has SPAN children");
var ricoCornerDiv = popup.groupDiv.parentNode.getElementsByTagName("span")[0];
if (navigator.appName.indexOf("Microsoft") == -1) {
t.eq(parseFloat(ricoCornerDiv.style.opacity), opacity, "good default ricoCornerDiv.opacity");
} else {
t.eq(ricoCornerDiv.style.filter, "alpha(opacity=" + opacity*100 + ")", "good default ricoCornerDiv.opacity");
}
}
</script>
</head>
<body>
<div id="map" style="width:512px; height:256px"> </div>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Popup_Anchored_setOpacity(t) {
t.plan(5);
var opacity = 0.5;
var id = "chicken";
var w = 500;
var h = 400;
var sz = new OpenLayers.Size(w,h);
var lon = 5;
var lat = 40;
var ll = new OpenLayers.LonLat(lon, lat);
var content = "foo";
var x = 50;
var y = 100;
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer('name', {'isBaseLayer':true}));
map.zoomToMaxExtent();
var popup = new OpenLayers.Popup.AnchoredBubble(id,
ll,
sz,
content,
null,
false);
map.addPopup(popup);
popup.setOpacity(opacity);
popup.draw(new OpenLayers.Pixel(x, y));
if (navigator.appName.indexOf("Microsoft") == -1) {
t.eq(parseFloat(popup.div.style.opacity), opacity, "good default popup.opacity");
} else {
t.eq(popup.div.style.filter, "alpha(opacity=" + opacity*100 + ")", "good default popup.opacity");
}
t.ok(popup.groupDiv!=null, "popup.groupDiv exists");
t.ok(popup.groupDiv.parentNode!=null, "popup.groupDiv.parentNode exists");
t.ok(popup.groupDiv.parentNode.getElementsByTagName("span").length > 0, "popup.groupDiv.parentNode has SPAN children");
var ricoCornerDiv = popup.groupDiv.parentNode.getElementsByTagName("span")[0];
if (navigator.appName.indexOf("Microsoft") == -1) {
t.eq(parseFloat(ricoCornerDiv.style.opacity), opacity, "good default ricoCornerDiv.opacity");
} else {
t.eq(ricoCornerDiv.style.filter, "alpha(opacity=" + opacity*100 + ")", "good default ricoCornerDiv.opacity");
}
}
</script>
</head>
<body>
<div id="map" style="width:512px; height:256px"> </div>
</body>
</html>

View File

@@ -1,41 +1,41 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Logical_constructor(t) {
t.plan(3);
var options = {'foo': 'bar'};
var rule = new OpenLayers.Rule.Logical(options);
t.ok(rule instanceof OpenLayers.Rule.Logical,
"new OpenLayers.Rule.Logical returns object" );
t.eq(rule.foo, "bar", "constructor sets options correctly");
t.eq(typeof rule.evaluate, "function", "rule has an evaluate function");
}
function test_Logical_destroy(t) {
t.plan(1);
var rule = new OpenLayers.Rule.Logical();
rule.destroy();
t.eq(rule.rules, null, "rules array nulled properly");
}
function test_Logical_evaluate(t) {
t.plan(1);
var rule = new OpenLayers.Rule.Logical({
type: OpenLayers.Rule.Logical.NOT});
rule.rules.push(new OpenLayers.Rule());
var feature = new OpenLayers.Feature.Vector();
t.eq(rule.evaluate(feature), false,
"feature evaluates to false correctly.");
}
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Logical_constructor(t) {
t.plan(3);
var options = {'foo': 'bar'};
var rule = new OpenLayers.Rule.Logical(options);
t.ok(rule instanceof OpenLayers.Rule.Logical,
"new OpenLayers.Rule.Logical returns object" );
t.eq(rule.foo, "bar", "constructor sets options correctly");
t.eq(typeof rule.evaluate, "function", "rule has an evaluate function");
}
function test_Logical_destroy(t) {
t.plan(1);
var rule = new OpenLayers.Rule.Logical();
rule.destroy();
t.eq(rule.rules, null, "rules array nulled properly");
}
function test_Logical_evaluate(t) {
t.plan(1);
var rule = new OpenLayers.Rule.Logical({
type: OpenLayers.Rule.Logical.NOT});
rule.rules.push(new OpenLayers.Rule());
var feature = new OpenLayers.Feature.Vector();
t.eq(rule.evaluate(feature), false,
"feature evaluates to false correctly.");
}
</script>
</head>
<body>
</body>
</html>

View File

@@ -1,146 +1,146 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Style_constructor(t) {
t.plan(3);
var options = {'foo': 'bar'};
var style = new OpenLayers.Style(null, options);
t.ok(style instanceof OpenLayers.Style,
"new OpenLayers.Style returns object" );
t.eq(style.foo, "bar", "constructor sets options correctly");
t.eq(typeof style.createStyle, "function", "style has a createStyle function");
}
function test_Style_create(t) {
t.plan(10);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector("layer");
var baseStyle = OpenLayers.Util.extend(
OpenLayers.Feature.Vector.style["default"],
{externalGraphic: "bar${foo}.png"});
var style = new OpenLayers.Style(baseStyle);
var rule1 = new OpenLayers.Rule.FeatureId({
fids: ["1"],
symbolizer: {"Point": {fillColor: "green"}},
maxScaleDenominator: 500000});
var rule2 = new OpenLayers.Rule.FeatureId({
fids: ["1"],
symbolizer: {"Point": {fillColor: "yellow"}},
minScaleDenominator: 500000,
maxScaleDenominator: 1000000});
var rule3 = new OpenLayers.Rule.FeatureId({
fids: ["1"],
symbolizer: {"Point": {fillColor: "red"}},
minScaleDenominator: 1000000,
maxScaleDenominator: 2500000});
style.addRules([rule1, rule2, rule3]);
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(3,5),
{"foo": "bar"},
style);
feature.fid = "1";
// for this fid, the above rule should apply
layer.addFeatures([feature]);
map.addLayer(layer);
map.setBaseLayer(layer);
map.setCenter(new OpenLayers.LonLat(3,5), 10);
// at this scale, the feature should be green
var createdStyle = style.createStyle(feature);
t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly.");
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly.");
map.setCenter(new OpenLayers.LonLat(3,5), 9);
// at this scale, the feature should be red
createdStyle = style.createStyle(feature);
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
t.eq(createdStyle.fillColor, "yellow", "Point symbolizer from rule applied correctly.");
map.setCenter(new OpenLayers.LonLat(3,5), 8);
// at this scale, the feature should be yellow
createdStyle = style.createStyle(feature);
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
t.eq(createdStyle.fillColor, "red", "Point symbolizer from rule applied correctly.");
map.setCenter(new OpenLayers.LonLat(3,5), 7);
// at this scale, the feature should be invisible
createdStyle = style.createStyle(feature);
t.eq(createdStyle.display, "none", "Feature is invisible at scale "+map.getScale());
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Point symbolizer from base style applied correctly.");
feature.fid = "2";
// now the rule should not apply
createdStyle = style.createStyle(feature);
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Correct style for rule that does not apply to fid=\"2\".");
}
function test_Style_createStyle(t) {
t.plan(2);
var style = new OpenLayers.Style();
var rule = new OpenLayers.Rule({
id: Math.random()
});
var elseRule = new OpenLayers.Rule({
id: Math.random(),
elseFilter: true
});
style.addRules([rule, elseRule]);
// test that applySymbolizer is only called with rule
style.applySymbolizer = function(r) {
t.eq(r.id, rule.id, "(plain) applySymbolizer called with correct rule");
}
style.createStyle(new OpenLayers.Feature.Vector());
rule.evaluate = function() {return false;};
style.applySymbolizer = function(r) {
t.eq(r.id, elseRule.id, "(else) applySymbolizer called with correct rule");
}
style.createStyle(new OpenLayers.Feature.Vector());
}
function test_Style_context(t) {
t.plan(1);
var context = {
foo: "bar",
size: 10};
var rule = new OpenLayers.Rule.Comparison({
type: OpenLayers.Rule.Comparison.LESS_THAN,
context: context,
property: "size",
value: 11,
symbolizer: {"Point": {externalGraphic: "${foo}.png"}}});
var style = new OpenLayers.Style();
style.addRules([rule]);
var styleHash = style.createStyle(new OpenLayers.Feature.Vector());
t.eq(styleHash.externalGraphic, "bar.png", "correctly evaluated rule against a custom context");
}
function test_Style_destroy(t) {
t.plan(1);
var style = new OpenLayers.Style();
style.destroy();
t.eq(style.rules, null, "rules array nulled properly");
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:500px"></div>
</body>
</html>
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_Style_constructor(t) {
t.plan(3);
var options = {'foo': 'bar'};
var style = new OpenLayers.Style(null, options);
t.ok(style instanceof OpenLayers.Style,
"new OpenLayers.Style returns object" );
t.eq(style.foo, "bar", "constructor sets options correctly");
t.eq(typeof style.createStyle, "function", "style has a createStyle function");
}
function test_Style_create(t) {
t.plan(10);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector("layer");
var baseStyle = OpenLayers.Util.extend(
OpenLayers.Feature.Vector.style["default"],
{externalGraphic: "bar${foo}.png"});
var style = new OpenLayers.Style(baseStyle);
var rule1 = new OpenLayers.Rule.FeatureId({
fids: ["1"],
symbolizer: {"Point": {fillColor: "green"}},
maxScaleDenominator: 500000});
var rule2 = new OpenLayers.Rule.FeatureId({
fids: ["1"],
symbolizer: {"Point": {fillColor: "yellow"}},
minScaleDenominator: 500000,
maxScaleDenominator: 1000000});
var rule3 = new OpenLayers.Rule.FeatureId({
fids: ["1"],
symbolizer: {"Point": {fillColor: "red"}},
minScaleDenominator: 1000000,
maxScaleDenominator: 2500000});
style.addRules([rule1, rule2, rule3]);
var feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(3,5),
{"foo": "bar"},
style);
feature.fid = "1";
// for this fid, the above rule should apply
layer.addFeatures([feature]);
map.addLayer(layer);
map.setBaseLayer(layer);
map.setCenter(new OpenLayers.LonLat(3,5), 10);
// at this scale, the feature should be green
var createdStyle = style.createStyle(feature);
t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly.");
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly.");
map.setCenter(new OpenLayers.LonLat(3,5), 9);
// at this scale, the feature should be red
createdStyle = style.createStyle(feature);
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
t.eq(createdStyle.fillColor, "yellow", "Point symbolizer from rule applied correctly.");
map.setCenter(new OpenLayers.LonLat(3,5), 8);
// at this scale, the feature should be yellow
createdStyle = style.createStyle(feature);
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
t.eq(createdStyle.fillColor, "red", "Point symbolizer from rule applied correctly.");
map.setCenter(new OpenLayers.LonLat(3,5), 7);
// at this scale, the feature should be invisible
createdStyle = style.createStyle(feature);
t.eq(createdStyle.display, "none", "Feature is invisible at scale "+map.getScale());
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Point symbolizer from base style applied correctly.");
feature.fid = "2";
// now the rule should not apply
createdStyle = style.createStyle(feature);
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Correct style for rule that does not apply to fid=\"2\".");
}
function test_Style_createStyle(t) {
t.plan(2);
var style = new OpenLayers.Style();
var rule = new OpenLayers.Rule({
id: Math.random()
});
var elseRule = new OpenLayers.Rule({
id: Math.random(),
elseFilter: true
});
style.addRules([rule, elseRule]);
// test that applySymbolizer is only called with rule
style.applySymbolizer = function(r) {
t.eq(r.id, rule.id, "(plain) applySymbolizer called with correct rule");
}
style.createStyle(new OpenLayers.Feature.Vector());
rule.evaluate = function() {return false;};
style.applySymbolizer = function(r) {
t.eq(r.id, elseRule.id, "(else) applySymbolizer called with correct rule");
}
style.createStyle(new OpenLayers.Feature.Vector());
}
function test_Style_context(t) {
t.plan(1);
var context = {
foo: "bar",
size: 10};
var rule = new OpenLayers.Rule.Comparison({
type: OpenLayers.Rule.Comparison.LESS_THAN,
context: context,
property: "size",
value: 11,
symbolizer: {"Point": {externalGraphic: "${foo}.png"}}});
var style = new OpenLayers.Style();
style.addRules([rule]);
var styleHash = style.createStyle(new OpenLayers.Feature.Vector());
t.eq(styleHash.externalGraphic, "bar.png", "correctly evaluated rule against a custom context");
}
function test_Style_destroy(t) {
t.plan(1);
var style = new OpenLayers.Style();
style.destroy();
t.eq(style.rules, null, "rules array nulled properly");
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:500px"></div>
</body>
</html>