2011-01-24 00:34:05 +01:00
|
|
|
/*
|
2012-10-05 01:48:01 +02:00
|
|
|
* Copyright [2012] [wisemapping]
|
2011-08-30 19:21:55 +02:00
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-01-24 00:34:05 +01:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
web2d.PolyLine = new Class({
|
|
|
|
Extends: web2d.Element,
|
|
|
|
initialize:function(attributes) {
|
|
|
|
var peer = web2d.peer.Toolkit.createPolyLine();
|
|
|
|
var defaultAttributes = {strokeColor:'blue',strokeWidth:1,strokeStyle:'solid',strokeOpacity:1};
|
|
|
|
for (var key in attributes) {
|
|
|
|
defaultAttributes[key] = attributes[key];
|
|
|
|
}
|
|
|
|
this.parent(peer, defaultAttributes);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
getType : function() {
|
|
|
|
return "PolyLine";
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
setFrom : function(x, y) {
|
|
|
|
this._peer.setFrom(x, y);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
setTo : function(x, y) {
|
|
|
|
this._peer.setTo(x, y);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
setStyle : function(style) {
|
|
|
|
this._peer.setStyle(style);
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
getStyle : function() {
|
|
|
|
return this._peer.getStyle();
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
buildCurvedPath : function(dist, x1, y1, x2, y2) {
|
|
|
|
var signx = 1;
|
|
|
|
var signy = 1;
|
|
|
|
if (x2 < x1) {
|
|
|
|
signx = -1;
|
|
|
|
}
|
|
|
|
if (y2 < y1) {
|
|
|
|
signy = -1;
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
var path;
|
|
|
|
if (Math.abs(y1 - y2) > 2) {
|
|
|
|
var middlex = x1 + ((x2 - x1 > 0) ? dist : -dist);
|
|
|
|
path = x1.toFixed(1) + ", " + y1.toFixed(1) + " " + middlex.toFixed(1) + ", " + y1.toFixed(1) + " " + middlex.toFixed(1) + ", " + (y2 - 5 * signy).toFixed(1) + " " + (middlex + 5 * signx).toFixed(1) + ", " + y2.toFixed(1) + " " + x2.toFixed(1) + ", " + y2.toFixed(1);
|
|
|
|
} else {
|
|
|
|
path = x1.toFixed(1) + ", " + y1.toFixed(1) + " " + x2.toFixed(1) + ", " + y2.toFixed(1);
|
|
|
|
}
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
return path;
|
|
|
|
},
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-08-30 19:21:55 +02:00
|
|
|
buildStraightPath : function(dist, x1, y1, x2, y2) {
|
|
|
|
var middlex = x1 + ((x2 - x1 > 0) ? dist : -dist);
|
|
|
|
return x1 + ", " + y1 + " " + middlex + ", " + y1 + " " + middlex + ", " + y2 + " " + x2 + ", " + y2;
|
|
|
|
}
|
|
|
|
});
|
2009-06-07 20:59:43 +02:00
|
|
|
|
|
|
|
|