1

ol.Feature.getGeometry().j get me the array of all coordinates. [ x, y, x, y, x, y .. ] thats work for points, or polygons. I use it to move the features and it work fast and fine. But the .j is not the "official" way to get the array. How about the best way? edit: I dont like use getCoordinates() it give different instance of arrays for points, or polygons and i dont like to use .j because it can chance in later versions. ( so i must fix it )

use ol.js 3.5.0 and jquery for the example code

var x=5, y=-10;
var l=feature.getGeometry().j,n=[],b=true;
$.each(l,function(i,v){
   if(b){
      n.push(v+x);
      b=false
   }else{
      n.push(v+y);
      b=true
}});
feature.getGeometry().j=n;
2
  • Are you using some custom ol3 build? What is this .j? Jun 12, 2015 at 13:38
  • No it is the normal ol3 build. If you use console.log(new ol.Feature()), or console.log(you_test_feature), you can see in the console all base functions and the class "attributs", one of it is the feature.j in it is the array of all 2D Coordinats in the style [ x,y,x,y .. ]. It is a nice way in javascript to work without the apis, becouse you see what the class can do.
    – cedJ
    Jun 14, 2015 at 12:20

1 Answer 1

1

The function applyTransform() allows you to modify this internal representation of the geometry.

var move = function(input, output, dimension) {
  for (var i = 0, ii = input.length; i < ii; i += dimension) {
    output[i] = input[i] + x;
    output[i + 1] = input[i + 1] + y;
  }
};
geometry.applyTransform(move);

See also ol.TransformFunction

3
  • It see like a nice solution for the base idea to move the features. I will try it. If it work i didnt need the j. I test it later, but mark it as true answer, now. Thank you @tsauerwein :)
    – cedJ
    Jun 14, 2015 at 12:28
  • If you can, I'd like to see an example of this move. Jun 15, 2015 at 9:34
  • The code in my answer is actually "all the magic". But anyway here is a JsFiddle: jsfiddle.net/5449m7em
    – tsauerwein
    Jun 15, 2015 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.