Changeset 7593
- Timestamp:
- 07/29/08 19:30:32 (4 months ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Feature/Vector.js (modified) (1 diff)
- trunk/openlayers/tests/Feature/Vector.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Feature/Vector.js
r7395 r7593 216 216 destroyPopup: function() { 217 217 // pass 218 }, 219 220 /** 221 * Method: move 222 * Moves the feature and redraws it at its new location 223 * 224 * Parameters: 225 * state - {OpenLayers.LonLat or OpenLayers.Pixel} the 226 * location to which to move the feature. 227 */ 228 move: function(location) { 229 230 if(!this.layer || !this.geometry.move){ 231 //do nothing if no layer or immoveable geometry 232 return; 233 } 234 235 var pixel; 236 if (location.CLASS_NAME == "OpenLayers.LonLat") { 237 pixel = this.layer.getViewPortPxFromLonLat(location); 238 } else { 239 pixel = location; 240 } 241 242 var lastPixel = this.layer.getViewPortPxFromLonLat(this.geometry.getBounds().getCenterLonLat()); 243 var res = this.layer.map.getResolution(); 244 this.geometry.move(res * (pixel.x - lastPixel.x), 245 res * (lastPixel.y - pixel.y)); 246 this.layer.drawFeature(this); 247 return lastPixel; 218 248 }, 219 249 trunk/openlayers/tests/Feature/Vector.html
r7252 r7593 87 87 } 88 88 89 function test_Feature_Vector_move(t) { 90 t.plan(3); 89 91 92 var oldx = 26; 93 var oldy = 14; 94 var newx = 6; 95 var newy = 4; 96 var res = 10; 97 98 var geometry = new OpenLayers.Geometry.Point(oldx, 99 oldy); 100 101 var drawn = false; 102 103 feature = new OpenLayers.Feature.Vector(geometry); 104 105 feature.layer = { 106 getViewPortPxFromLonLat : function(lonlat){ 107 return new OpenLayers.Pixel(lonlat.lon,lonlat.lat); 108 }, 109 map: { 110 getResolution: function(){ 111 return res; 112 } 113 }, 114 drawFeature: function(){ 115 drawn = true; 116 } 117 } 118 119 var pixel = new OpenLayers.Pixel(newx,newy) 120 121 feature.move(pixel); 122 123 geometry = feature.geometry; 124 125 t.ok(drawn, "The feature is redrawn after the move"); 126 t.eq(geometry.x, res * (newx - oldx) + oldx, "New geometry has proper x coordinate"); 127 t.eq(geometry.y, res * (oldy - newy) + oldy, "New geometry has proper y coordinate"); 128 } 129 90 130 91 131 </script>
