curve - Using cubiccurve in OpenLayers 2? -


i want use cubiccurve in openlayers 2.13, , have added necessary files, when drawing line drawn instead of curve.

files available on website: http://trac.osgeo.org/openlayers/ticket/1715#no1

drawing curve important , no way control curve.

can 1 me?

<html>  <head>  <script src="http://dev.openlayers.org/openlayers.js" type="text/javascript"></script> <title>ya mahdi</title> <style>     html,body {         height: 99%;         width: 99%;     }     #map {         width: 100%;         height: 100%;         border: 1px solid black;     } </style> <script>     mmgetcurvepoints = function(ptsa, tension, isclosed, numofsegments)     {         if (ptsa.length <= 2)             return ptsa;          tension = typeof tension === 'number' ? tension : 0.5;         isclosed = typeof isclosed === 'boolean' ? isclosed : false;         numofsegments = typeof numofsegments === 'number' ? numofsegments : 16;         var ptsaclone = ptsa.slice(0);         if (isclosed)             ptsaclone.push(ptsa[0], ptsa[1], ptsa[2], ptsa[3]);          var _pts, res = [], /// clone array                 x, y, /// our x,y coords                 t1x, t2x, t1y, t2y, /// tension vectors                 c1, c2, c3, c4, /// cardinal points                 st, t, i, /// steps based on num. of segments                 pow3, pow2, /// cache powers                 pow32, pow23,                 p0, p1, p2, p3, /// cache points                 pl = ptsaclone.length;          /// clone array don't change original content         _pts = ptsaclone.concat();          _pts.unshift(ptsaclone[1]);                 /// copy 1. point , insert @ beginning         _pts.unshift(ptsaclone[0]);         _pts.push(ptsaclone[pl - 2], ptsaclone[pl - 1]);    /// copy last point , append          /// 1. loop goes through point array         /// 2. loop goes through each segment between 2 points + 1 point before , after         (i = 2; < pl; += 2) {              p0 = _pts[i];             p1 = _pts[i + 1];             p2 = _pts[i + 2];             p3 = _pts[i + 3];              /// calc tension vectors             t1x = (p2 - _pts[i - 2]) * tension;             t2x = (_pts[i + 4] - p0) * tension;              t1y = (p3 - _pts[i - 1]) * tension;             t2y = (_pts[i + 5] - p1) * tension;              (t = 0; t <= numofsegments; t++) {                 /// calc step                 st = t / numofsegments;                  pow2 = math.pow(st, 2);                 pow3 = pow2 * st;                 pow23 = pow2 * 3;                 pow32 = pow3 * 2;                  /// calc cardinals                 c1 = pow32 - pow23 + 1;                 c2 = pow23 - pow32;                 c3 = pow3 - 2 * pow2 + st;                 c4 = pow3 - pow2;                  /// calc x , y cords common control vectors                 x = c1 * p0 + c2 * p2 + c3 * t1x + c4 * t2x;                 y = c1 * p1 + c2 * p3 + c3 * t1y + c4 * t2y;                  /// store points in array                 res.push(x, y);             }         }          if (isclosed)             res = res.slice(0, res.length - 2 * numofsegments);          return res;     };      var map, control,layer,feature,points;     var xy = [];     var array = [];     function init(){         map = new openlayers.map('map', {             center: [45.476333, 39.4854095],             zoom: 10         });         var wms = new openlayers.layer.wms( "openlayers wms",                 "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'});          layer = new openlayers.layer.vector("simple geometry");         map.addlayer(wms);         map.addlayer(layer);         function drawend(e){             if(xy.length<6) {                 xy.push(e.x);                 xy.push(e.y);                 return;             }             else if(xy.length==6){                 feature = new openlayers.feature.vector(                         new openlayers.geometry.linestring(array),{properties: {state: 'a'}}                 );                  layer.addfeatures(feature);                 console.log("add f");                 feature="";                 layer.refresh({force:true});                 xy=[];             }          }           function putpoint(e){             if(xy.length<6)  {                 return;             }          }          function sketchmodified(e, ee, eee){             if(xy.length<6)                 return;             try{                 layer.removefeatures(feature);             }catch(err){}              var xytemp = [];             xytemp.push(xy[0]);             xytemp.push(xy[1]);              xytemp.push(xy[2]);             xytemp.push(xy[3]);              xytemp.push(e.x);             xytemp.push(e.y);              points = mmgetcurvepoints(xytemp, 0.5, false, 15);             var = 0;              while(i<points.length){                 array.push(new openlayers.geometry.point(points[i], points[i+1]));                 i++;                 i++;             }              feature = new openlayers.feature.vector(                     new openlayers.geometry.linestring(array),{properties: {state: 'a'}}             );             layer.addfeatures([feature]);             array=[];             points=[];             layer.refresh({force:true});         }          function cancel(){          }          var callbackparams = {             "done": drawend,             "point": putpoint,             "modify": sketchmodified,             "cancel": cancel         };           var drawcrtl = new openlayers.control.drawfeature(layer, openlayers.handler.point, {callbacks: callbackparams});         map.addcontrols([drawcrtl]);         drawcrtl.activate();      }  </script> </head>  <body onload="init()"> <div id="map" style="width: 400px; height: 400px;"></div> </body> </html> 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -