Kl javascript library

From DreamsteepWiki

Jump to: navigation, search

A PLACE FOR OPENLAYERS RELATED FUNCTIONS


       var maxOpacity = 0.9;
        var minOpacity = 0.1;
        function changeOpacity(byOpacity) {
            var newOpacity = (parseFloat(OpenLayers.Util.getElement('opacity').value) + byOpacity).toFixed(1);
            newOpacity = Math.min(maxOpacity,
                                  Math.max(minOpacity, newOpacity));
            OpenLayers.Util.getElement('opacity').value = newOpacity;
            shade.setOpacity(newOpacity);
        }


                function make_polygon( COORDS){
                   var wkt = new OpenLayers.Format.WKT() ;
                   features=wkt.read(COORDS);

                  var styleMap = new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults(
                      {fillColor: "#00ffff", fillOpacity: .1, strokeColor: "#00ffff"},
                      OpenLayers.Feature.Vector.style["default"]));

                   var thrvec=new OpenLayers.Layer.Vector('WKTLAYER',{styleMap: styleMap}  );
                   map.addLayers([thrvec]);
                   thrvec.addFeatures(features);
                }

COMMON MAP RELATED FUNCTIONS

            function show_browser(response) {
            alert(response.responseText);
   			    }


           function show_log(response){
            write("output",response.responseText)
           }


            function clear_log(){
              write("output","");
            }
            function log(msg) {
                document.getElementById("output").innerHTML += msg + "\n";
            }


            function read(TAGNAME) {
               textstr = document.getElementById(TAGNAME).value;
               return textstr
            }
           function write(TAGNAME,TEXT) {
                document.getElementById(TAGNAME).innerHTML = TEXT ;
            }





function format_text_response( INPUT_TEXT)
{
      ////////////////////////////////////////////////////////

      SPLITCHAR = "="; //"trigger" character to identify lines to use and to locate split on each line
      var OUTPUTARRAY =new Array() //THIS IS THE STORAGE FOR THE SORTED OUTPUT

      OUTPUTARRAY.push("---------------------------");
      
      //this loops through the array
      for (var test in INPUT_TEXT)
      {
        //this iterates the array
        var curline = INPUT_TEXT[test] ;
        //this checks it for an equal sign
        lookforequals =  curline.match("=")  ;
        //this splits it in half
        var buffersplit = curline.split(SPLITCHAR)  ;

        //IF AN EQUAL SIGN IS PRESENT IN LINE LOOK AT RIGHT AND LEFT SIDE , IGNORE ALL OTHERS
        if (lookforequals == "=") //or null
        {

         if (buffersplit[1].length>3 )
          {
           OUTPUTARRAY.push ( (buffersplit[0]+" "+buffersplit[1]  ) );
          }
        }

      }//end of loop
      OUTPUTARRAY.push("---------------------------");
      
      return OUTPUTARRAY;

} //end of function


      function mapserv_string_2_array(INPUT_STRING)
      {
       colonmarker = INPUT_STRING.split(":");
       var OUTPUTARRAY =new Array()
       //
       var splitequals = colonmarker[2].split("=")
       endvalue = splitequals.length

       //alert(INPUT_STRING);

       for (varr=0;varr<=(endvalue-1);varr=varr+1)
        {
            line = splitequals[varr];
            splitsplit = line.split("'");
            //

            if (splitsplit[0]!=undefined && splitsplit[0]!="")
            {
             OUTPUTARRAY.push(splitsplit[0]);
            }

            if (splitsplit[1]!=undefined && splitsplit[1]!="")
            {
             OUTPUTARRAY.push(splitsplit[1]);
            }

            if (splitsplit[2]!=undefined && splitsplit[2]!="")
            {
             OUTPUTARRAY.push(splitsplit[2]);
            }
            OUTPUTARRAY.push("\n") ;
        }


       return OUTPUTARRAY ;
      }



function outputscreen(ARRAY)
{

      for (var test in ARRAY)
      {
        var curline = ARRAY[test] ;
        document.write("<p>"+curline+"</p>")
      }
      
}



	        function parseWKT(WKT_TEXT) {
 	            //var element = document.getElementById('wkt');
 	            var collection = WKT_TEXT //wkt.read(element.value);
 	            //var bounds;
 	
 	            if(collection) {
 	                if(collection.constructor != Array) {
 	                    collection = [collection];
 	                }
 	                var features = [];
 	                for(var i=0; i<collection.length; ++i) {
	                    features.push(new OpenLayers.Feature.Vector(collection[i]));
 	                    if (!bounds) {
 	                        bounds = collection[i].getBounds();
 	                    }
 	                    bounds.extend(collection[i].getBounds());
 	
 	                }
 	                vectors.addFeatures(features);
 	                map.zoomToExtent(bounds);
 	                var plural = (features.length > 1) ? 's' : '';
 	                element.value = 'Feature' + plural + ' added'
 	            } else {
 	                element.value = 'Bad WKT';
 	            }
	        }


         function handler(request) {
            // if the response was XML, try the parsed doc
            alert(request.responseXML);
            // otherwise, you've got the response text
            alert(request.responseText);
            // and don't forget you've got status codes
            alert(request.status);
            // and of course you can get headers
            alert(request.getAllResponseHeaders());
            // etc.
         }










						
						
Personal tools