을 포인트를 평평하게 나는 다음과 같은 데이터 구조를 가지고 : 나는 polyline
points
속성으로 사용하는 5535,5535 5535,60000 60000,60000 60000,5535
에 평평하게하고 싶은SVG 폴리 라인에 폴리머
'points': [
{
'x': 5535,
'y': 5535
},
{
'x': 5535,
'y': 60000
},
{
'x': 60000,
'y': 60000
},
{
'x': 60000,
'y': 5535
}
];
합니다.
나는 <template>
<polyline
id="polygon",
points="{{points | polygonPoints | toSvgPoints(width, height)}}"
stroke="rgba({{colour.r}}, {{colour.g}}, {{colour.b}}, {{opacity}})"
fill="rgba({{colour.r}}, {{colour.g}}, {{colour.b}}, {{opacity * 0.6}})"
stroke-width="{{lineWidth}}"
stroke-linecap="round"
stroke-linejoin="round"
/>
polygonPoints
및 toSvgPoints
필터 그래서 같이 폴리머에 다음과 같습니다
/**
* Retrieves the polygon points for this object.
* @param point optionally provide a list of normalized points
* @returns the polygon points or all points if a line
*/
polygonPoints: function(points) {
var array = points.slice(0);
points = points || this.points;
array.push(points[0])
return array;
},
/**
* Retrieves the polygon points for this object.
* @param point optionally provide a list of normalized points
* @returns the polygon points or all points if a line
*/
toSvgPoints: function(points, width, height) {
var i, string = '';
points = points || this.points;
for (i = 0; i < points.length; ++i) {
string += this.normalizedToActual(points[i].x, width);
string += ',';
string += this.normalizedToActual(points[i].y, height);
string += ' ';
}
return string;
},
이 작품의 toSvgPoints
반환 정확한 포인트를하지만 포인트 값으로 바인딩 Polymer가 자동으로 설정하지 마십시오. 예를 들어 this.points[0].x = 4219
을 수정하면 바인딩이 다각형 속성에 만들어지지 않았기 때문에 다각형이 업데이트되지 않습니다.
다시 그리기를 호출하는 다른 방법을 제공하지 않으면이 문제를 해결할 수 없습니까? 이상적으로는이 작업을 수행 할 것 다음 points
속성에 x
및 y
값을 근절하고 바인딩을 설정합니다
<polyline
id="polygon",
points="{{x,y for (points | polygonPoints)}}"
...
/>
합니다.
의 최신 버전에서는 작동하지 않습니다. 어떻게 toSvgPoints가 요소를 듣게합니까? 'onMutation'은 가벼운 DOM 요소를위한 것이고 그 것은 작동하지 않습니다. –
observe-js에 대한 링크를 추가했습니다. –