Skip to content

Commit

Permalink
add right shape in column symboliser
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Brunner committed May 11, 2012
1 parent aa13fc1 commit b924b4e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/GeoExt/FeatureRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* @class GeoExt.FeatureRenderer
*
*
* The feature renderer
*/
Ext.define('GeoExt.FeatureRenderer', {
Expand Down Expand Up @@ -46,7 +46,7 @@ Ext.define('GeoExt.FeatureRenderer', {
* @cfg {String}
* One of ``"Point"``, ``"Line"``, or ``"Polygon"``. Only pertinent if
* OpenLayers.Symbolizer objects are not used. If ``feature``
* is provided, it will be preferred. The default is "Polygon".
* is provided, it will be preferred.
*/
symbolType: "Polygon",

Expand Down
18 changes: 16 additions & 2 deletions src/GeoExt/grid/column/Symbolizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @class GeoExt.grid.column.Symbolizer
*
* An {@link Ext.grid.column.Column} pre-configured with a
* An {@link Ext.grid.column.Column} pre-configured with a
* {@link GeoExt.FeatureRenderer}
*/
Ext.define('GeoExt.grid.column.Symbolizer', {
Expand All @@ -21,10 +21,24 @@ Ext.define('GeoExt.grid.column.Symbolizer', {
defaultRenderer: function(value, meta, record) {
if (value) {
var id = Ext.id();
var symbolType = "Polygon";
if (record) {
var symbolType = "Line";
var className = record.raw.geometry.CLASS_NAME;
if (className == "OpenLayers.Geometry.Point" ||
className == "OpenLayers.Geometry.MultiPoint") {
symbolType = "Point";
}
else if (className == "OpenLayers.Geometry.Polygon" ||
className == "OpenLayers.Geometry.MultiPolygon") {
symbolType = "Polygon";
}
}
window.setTimeout(function() {
var renderer = Ext.create('GeoExt.FeatureRenderer', {
renderTo: id,
symbolizers: value instanceof Array ? value : [value]
symbolizers: value instanceof Array ? value : [value],
symbolType: symbolType
});
}, 0);
meta.css = "gx-grid-symbolizercol";
Expand Down
60 changes: 60 additions & 0 deletions tests/grid/column/Symbolizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,66 @@
document.body.removeChild(el);
});
}

function test_shape(t) {
t.plan(8);

var meta = {},
value = {fillColor: "red", stroke: false},
column = Ext.create('GeoExt.grid.column.Symbolizer'),
markup1 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.Curve()}}),
el1 = document.createElement("div"),
markup2 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.LinearRing()}}),
el2 = document.createElement("div"),
markup3 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.LineString()}}),
el3 = document.createElement("div"),
markup4 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.MultiLineString()}}),
el4 = document.createElement("div"),
markup5 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.MultiPoint()}}),
el5 = document.createElement("div"),
markup6 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.MultiPolygon()}}),
el6 = document.createElement("div"),
markup7 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.Point()}}),
el7 = document.createElement("div"),
markup8 = column.renderer(value, meta, {raw: {geometry: new OpenLayers.Geometry.Polygon()}}),
el8 = document.createElement("div");

document.body.appendChild(el1);
el1.innerHTML = markup1;
document.body.appendChild(el2);
el2.innerHTML = markup2;
document.body.appendChild(el3);
el3.innerHTML = markup3;
document.body.appendChild(el4);
el4.innerHTML = markup4;
document.body.appendChild(el5);
el5.innerHTML = markup5;
document.body.appendChild(el6);
el6.innerHTML = markup6;
document.body.appendChild(el7);
el7.innerHTML = markup7;
document.body.appendChild(el8);
el8.innerHTML = markup8;

t.delay_call(1, function() {
t.ok(el1.outerHTML.indexOf("OpenLayers.Geometry.Line") >= 0, "test for Curve");
t.ok(el2.outerHTML.indexOf("OpenLayers.Geometry.Line") >= 0, "test for LinearRing");
t.ok(el3.outerHTML.indexOf("OpenLayers.Geometry.Line") >= 0, "test for LineString");
t.ok(el4.outerHTML.indexOf("OpenLayers.Geometry.Line") >= 0, "test for MultiLineString");
t.ok(el5.outerHTML.indexOf("OpenLayers.Geometry.Point") >= 0, "test for MultiPoint");
t.ok(el6.outerHTML.indexOf("OpenLayers.Geometry.Polygon") >= 0, "test for MultiPolygon");
t.ok(el7.outerHTML.indexOf("OpenLayers.Geometry.Point") >= 0, "test for Point");
t.ok(el8.outerHTML.indexOf("OpenLayers.Geometry.Polygon") >= 0, "test for Polygon");

Ext.each(Ext.ComponentQuery.query('gx_symbolizercolumn'),
function (renderer) {
renderer.destroy();
});
document.body.removeChild(el1);
document.body.removeChild(el2);
document.body.removeChild(el3);
});
}
</script>

<body>
Expand Down

0 comments on commit b924b4e

Please sign in to comment.