0

As the title suggests,I have GeoJSON vectors on OpenLayers map where user should add X/Y offset (i.e 5 meters north,5 meters east).I plan to add some control for it.

Since vectors are drawn map with OpenLayers.Rule object,as I searched for some offset option,then all I found was graphicXOffset & graphicYOffset which eludes normal vectors but only used for external graphics.

Is there any easy way to accomplish this feature on client ?

1 Answer 1

1

Did you try the feature's move(x,y) method?

You can attach a callback on your control's click event, that calls a function like this:

moveAllFeatures = function(layer,x,y){
  var all = layer.features.length;
  for(var i = 0;i<all;i++){
   layer.features[i].geometry.move(x,y);
  }
  layer.redraw();
}

OpenLayers geometry move

3
  • Unfortunately,when layer is redrawn,it is again re-requested and all features in the layer will be at the same position.Moving them is a way,but looping all the features is not a solution.
    – Myra
    May 12, 2013 at 18:22
  • 1
    I know this problem. If you have not so much element on your layer (few thousands), you can use the Fixed strategy instead of BBOX. The Fixed strategy loads all the features and doesnt change them. The BBOX strategy reloads all features when the viewport changes enough to invalidate the current BBOX. btw i just work on a custom bbox strategy, that doesn't remove features, only adds new features to the requested area. May 12, 2013 at 18:50
  • It is dangerous to load entire vector elements at once.Such workload could not be handled by browser.I don't think Fixed Strategy would solve my problem
    – Myra
    May 12, 2013 at 19:24

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.