Skip to content

Commit

Permalink
Closes #2637 (#2698)
Browse files Browse the repository at this point in the history
  • Loading branch information
kappu72 authored and mbarto committed Mar 6, 2018
1 parent 9043050 commit d5d99bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions web/client/components/print/MapPreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,20 @@ class MapPreview extends React.Component {
})
});
};

renderLayerContent = (layer) => {
renderLayerContent = (layer, projection) => {
if (layer.features && layer.type === "vector") {
return layer.features.map( (feature) => {
return (
<Feature
crs={projection}
key={feature.id}
type={feature.type}
geometry={feature.geometry}
msId={feature.id}
featuresCrs={ layer.featuresCrs || 'EPSG:4326' }
style={ feature.style || layer.style || null }/>
layerStyle={layer.style}
style={ feature.style || layer.style || null }
properties={feature.properties}/>
);
});
}
Expand Down Expand Up @@ -132,7 +134,7 @@ class MapPreview extends React.Component {
{this.props.layers.map((layer, index) =>
(<Layer key={layer.id || layer.name} position={index} type={layer.type}
options={assign({}, this.adjustResolution(layer), {srs: projection})}>
{this.renderLayerContent(layer)}
{this.renderLayerContent(layer, projection)}
</Layer>)

)}
Expand Down
8 changes: 6 additions & 2 deletions web/client/utils/PrintUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,27 @@ const PrintUtils = {
})
}
},
rgbaTorgb: (rgba = "") => {
return rgba.indexOf("rgba") !== -1 ? `rgb${rgba.slice(rgba.indexOf("("), rgba.lastIndexOf(","))})` : rgba;
},
/**
* Useful for print (Or generic Openlayers 2 conversion style)
* http://dev.openlayers.org/docs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.OpenLayers.Feature.Vector.style
*/
toOpenLayers2Style: function(layer, style) {
if (!style) {
return PrintUtils.getOlDefaultStyle(layer);
}
// commented the available options.
return {
"fillColor": style.fillColor,
"fillColor": PrintUtils.rgbaTorgb(style.fillColor),
"fillOpacity": style.fillOpacity,
// "rotation": "30",
"externalGraphic": style.iconUrl,
// "graphicName": "circle",
// "graphicOpacity": 0.4,
"pointRadius": style.radius,
"strokeColor": style.color,
"strokeColor": PrintUtils.rgbaTorgb(style.fillColor),
"strokeOpacity": style.opacity,
"strokeWidth": style.weight
// "strokeLinecap": "round",
Expand Down
5 changes: 5 additions & 0 deletions web/client/utils/__tests__/PrintUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,9 @@ describe('PrintUtils', () => {
expect(printSpec.dpi).toBe(96);
expect(printSpec.layers.length).toBe(1);
});
it('from rgba to rgb', () => {
const rgb = PrintUtils.rgbaTorgb("rgba(255, 255, 255, 0.1)");
expect(rgb).toExist();
expect(rgb).toBe("rgb(255, 255, 255)");
});
});

0 comments on commit d5d99bb

Please sign in to comment.