Users Archive

List Statistics

  • Total Threads: 1594
  • Total Posts: 3418
  #1  
15-04-2010 03:45 PM
Users member admin is online now
User
 

The easiest thing is to print the page containing the map (or a simpler print
page containing the map).

For other approaches, this may help:
http://trac.openlayers.org/wiki/Printing
--
View this message in context: http://n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p4907550.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #2  
15-04-2010 04:47 PM
Users member admin is online now
User
 

rakesh.modi1585 wrote:
>
> Hi,
>
> I want to print map area (WMS Layer) with overlay vector layers. Is it
> possible in openlayers, if it then how it is done?
>
> Thanks
> Rakesh
>

Check out the link that Lisa said in her e-mail. We resorted to a server
side stitching because we couldn't rely on the differences between browsers.
Some browsers wouldn't be able to print all the layers and we didn't have
much success with printing vector.

By going server side, we can control all that (including vectors) and
provide options for output (JPG, PDF, etc..)

Shawn
--
View this message in context: http://n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p4907889.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #3  
26-04-2010 08:29 PM
Users member admin is online now
User
 

Hi,

soatley > I'm trying to do the exact same thing (server side stitching of
the different layers of the map). However, after using the code here:
http://trac.openlayers.org/wiki/Printing, the vector layers do NOT get
printed. Do you have some reusable code that you would be willing to share,
in order to properly print the vector layers ? Thank you.
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p4964522.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #4  
27-04-2010 09:42 PM
Users member admin is online now
User
 

Hi,

I now have my vector layers being displayed properly in the image and the
result looks ok, but I still have one small problem: when I move the map,
the generated image remains the same. I need to do a zoom out and zoom in to
have the generated image reinitialized to the right position. Anybody here
encountered the same problem ?

Thank you.
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p4970936.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #5  
29-04-2010 07:58 PM
Users member admin is online now
User
 

Hi,

I still wasn't able to solve that problem. Basically, what happens is that
if I move through the map, then do a zoom out and then a zoom in, the map is
printed at the position where I moved to. However, if I just move through
the map, without doing a zoom out and zoom in, the map is printed in its
initial position (the position before moving through it). Any thoughts on
that ?

Thank you.
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p4981714.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #6  
03-05-2010 10:58 PM
Users member admin is online now
User
 

Hi,

Just in case someone encounters the same problem (i. e. when moving the map,
it is printed in its initial position), I solved it by adding the position
of the viewport (map.layerContainerDiv.style.left and
map.layerContainerDiv.style.top), and then adding the left value of the
viewport to the $tile->x and the top value of the viewport to the $tile->y
in the calls to imagecopymerge_alpha.

Here is my full client code (I encapsulated the map object within an
object):

this.print = function(print_url, callback) {
var size = this.map.getSize();
var tiles = [];

var nb_layers = this.map.layers.length;
var layeri = 0;
var nb_vector_layers = 0;
var features = [];
for (layeri = 0; layeri < nb_layers; layeri++) {
// if the layer isn't visible at this range, or is turned off, skip it
var layer = this.map.layers[layeri];
if (!layer.getVisibility()) continue;
if (!layer.calculateInRange()) continue;
if (layer.grid) {
// iterate through their grid's tiles, collecting each tile's extent and
pixel location at this moment
var grid_length = layer.grid.length;
var row_length = 0;
var tilerow = 0;
var tilei = 0;
for (tilerow = 0; tilerow < grid_length; tilerow++) {
row_length = layer.grid[tilerow].length;
tilei = 0;
for (tilei = 0; tilei < row_length; tilei++) {
var tile = layer.grid[tilerow][tilei];
var url = layer.getURL(tile.bounds);
var position = tile.position;
var opacity = layer.opacity ? parseInt(100*layer.opacity) : 100;
var bounds = tile.bounds;
tiles[tiles.length] = {url:url, x:position.x, y:position.y,
opacity:opacity, bounds:{left:bounds.left, right: bounds.right, top:
bounds.top, bottom: bounds.bottom}};
}
}
} else {
// get the features of the layer
var olFeatures = layer.features;
var features_temp = [];
var styles = {};
var nb_features = layer.features.length;
var featuresi = 0;
var nextId = 1;
for (var i = 0; i < nb_features; i++) {
var feature = olFeatures[i];
var style = feature.style || layer.style ||
layer.styleMap.createSymbolizer(feature, feature.renderIntent);
if(feature.geometry) {
if (feature.geometry.CLASS_NAME.search(/point$/i) >= 0) {
var fpos = this.map.getLayerPxFromLonLat(new
OpenLayers.LonLat(feature.geometry.x, feature.geometry.y));
if(fpos != null) {
features_temp[featuresi] = {type: 'point', x: fpos.x, y:fpos.y,
style: style};
featuresi++;
}
}
}
}
features[nb_vector_layers] = features_temp;
nb_vector_layers++;
}

}

// hand off the list to our server-side script, which will do the heavy
lifting
var tiles_json = JSON.stringify(tiles);
var features_json = JSON.stringify(features);
var viewport_left = parseInt(this.map.layerContainerDiv.style.left);
var viewport_top = parseInt(this.map.layerContainerDiv.style.top);
var viewport = {top: viewport_top, left: viewport_left};
var viewport_json = JSON.stringify(viewport);
var scale = Math.round(this.map.getScale());

OpenLayers.Request.POST(
{ url:print_url,

data:OpenLayers.Util.getParameterString({width:size.w,height:size.h,scale:scale,viewport:
viewport_json,tiles:tiles_json,features:features_json}),
headers:{'Content-Type':'application/x-www-form-urlencoded'},
callback: callback
}
);
}
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p5000414.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #7  
04-05-2010 12:16 PM
Users member admin is online now
User
 

Hello,

I'm trying to make a tool like yours, indeed I asked this before but
nobody seemed to know the solution, but I'm not able to figure out how
to process the features data in php script. Can you please give me some
clues to solve the problem??

Another question I've got is that I see that you're just parsing Point
fetures. If I would want to parse polygons or lines how could I do it?
Do I have to use GeoJSON Syntax??

Thanks.

P.S. I'm a bit newbie, I know.

-----Mensaje original-----
De: users- [mailto:users-]
En nombre de guillaumev
Enviado el: lunes, 03 de mayo de 2010 23:59
Para:
Asunto: Re: [OpenLayers-Users] How to print map area with openlayers


Hi,

Just in case someone encounters the same problem (i. e. when moving the
map, it is printed in its initial position), I solved it by adding the
position of the viewport (map.layerContainerDiv.style.left and
map.layerContainerDiv.style.top), and then adding the left value of the
viewport to the $tile->x and the top value of the viewport to the
$tile->y in the calls to imagecopymerge_alpha.

Here is my full client code (I encapsulated the map object within an
object):

this.print = function(print_url, callback) {
var size = this.map.getSize();
var tiles = [];

var nb_layers = this.map.layers.length;
var layeri = 0;
var nb_vector_layers = 0;
var features = [];
for (layeri = 0; layeri < nb_layers; layeri++) {
// if the layer isn't visible at this range, or
is turned off, skip it
var layer = this.map.layers[layeri];
if (!layer.getVisibility()) continue;
if (!layer.calculateInRange()) continue;
if (layer.grid) {
// iterate through their grid's tiles,
collecting each tile's extent and pixel location at this moment
var grid_length = layer.grid.length;
var row_length = 0;
var tilerow = 0;
var tilei = 0;
for (tilerow = 0; tilerow < grid_length;
tilerow++) {
row_length =
layer.grid[tilerow].length;
tilei = 0;
for (tilei = 0; tilei <
row_length; tilei++) {
var tile =
layer.grid[tilerow][tilei];
var url =
layer.getURL(tile.bounds);
var position =
tile.position;
var opacity =
layer.opacity ? parseInt(100*layer.opacity) : 100;
var bounds =
tile.bounds;
tiles[tiles.length] =
{url:url, x:position.x, y:position.y, opacity:opacity,
bounds:{left:bounds.left, right: bounds.right, top:
bounds.top, bottom: bounds.bottom}};
}
}
} else {
// get the features of the layer
var olFeatures = layer.features;
var features_temp = [];
var styles = {};
var nb_features = layer.features.length;
var featuresi = 0;
var nextId = 1;
for (var i = 0; i < nb_features; i++) {
var feature = olFeatures[i];
var style = feature.style ||
layer.style || layer.styleMap.createSymbolizer(feature,
feature.renderIntent);
if(feature.geometry) {
if
(feature.geometry.CLASS_NAME.search(/point$/i) >= 0) {
var fpos =
this.map.getLayerPxFromLonLat(new OpenLayers.LonLat(feature.geometry.x,
feature.geometry.y));
if(fpos != null)
{

features_temp[featuresi] = {type: 'point', x: fpos.x, y:fpos.y,
style: style};

featuresi++;
}
}
}
}
features[nb_vector_layers] =
features_temp;
nb_vector_layers++;
}

}

// hand off the list to our server-side script, which
will do the heavy lifting
var tiles_json = JSON.stringify(tiles);
var features_json = JSON.stringify(features);
var viewport_left =
parseInt(this.map.layerContainerDiv.style.left);
var viewport_top =
parseInt(this.map.layerContainerDiv.style.top);
var viewport = {top: viewport_top, left: viewport_left};
var viewport_json = JSON.stringify(viewport);
var scale = Math.round(this.map.getScale());

OpenLayers.Request.POST(
{ url:print_url,

data:OpenLayers.Util.getParameterString({width:size.w,height:size.h,scal
e:scale,viewport:
viewport_json,tiles:tiles_json,features:features_json}),

headers:{'Content-Type':'application/x-www-form-urlencoded'},
callback: callback
}
);
}
--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/How-to-print-map-area-with-openla
yers-tp4901023p5000414.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #8  
04-05-2010 03:44 PM
Users member admin is online now
User
 

Hi David,

Here is the code I'm using on the server side to parse the features:

$red = imagecolorallocate($image, 255, 0, 0);
$black = imagecolorallocate($image, 0, 0, 0);

foreach($features as $feature_array) {
if(count($feature_array) > 0) {
foreach($feature_array as $feature) {
if($feature->type == "point") {
if($feature->style) {
$dst_x = $feature->x + $viewport->left;
$dst_y = $feature->y + $viewport->top;
if($feature->style->externalGraphic) {
// Draw the external graphic
$tempfilename = basename($feature->style->externalGraphic);
$tempfile = sprintf("%s".DS."%s", $graphs_directory,
$tempfilename);
if(!file_exists($tempfile)) {
$tempfiles[] = $tempfile;

file_put_contents($tempfile,file_get_contents($this->relative_to_absolute_url($feature->style->externalGraphic)));
}
list($fwidth, $fheight, $fformat) = @getimagesize($tempfile);
$feature_image = $this->image_create_from_format($fformat,
$tempfile);
$dst_x = $dst_x - ($fwidth / 2);
$dst_y = $dst_y - ($fheight / 2);
imagecopy($image, $feature_image, $dst_x, $dst_y, 0, 0, $fwidth,
$fheight);
} else {
// something needs to be drawn
$color_rgb = $this->html2rgb($feature->style->fillColor);
$color = imagecolorallocatealpha($image, $color_rgb[0],
$color_rgb[1], $color_rgb[2], 40);
$radius = $feature->style->pointRadius * 2;
imagefilledellipse($image, $dst_x, $dst_y, $radius, $radius,
$color);
}
if($feature->style->label != "") {
imagestring($image, 2, $dst_x, $dst_y, $feature->style->label,
$black);
}
}
}
}
}
}

As you said, I'm only parsing points because, in my case, I'm only
interested in points (I don't have any layer in my map that describes
polygons). However, I'm pretty sure it must be possible to do the same thing
for polygons using the imagepolygon GD function
(http://www.php.net/manual/en/function.imagepolygon.php)...

Also, if you are interested and maybe if other people are interested in this
functionality too, it could be interesting to create an open source library
in PHP to implement this functionality. Let me know if you are in, and if
other people are interested, please let me know...

Guillaume
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-print-map-area-with-openlayers-tp4901023p5003693.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.

  #9  
14-09-2010 12:32 PM
Users member admin is online now
User
 

hi guillaumev,
i am new to openlayers and to javascript also but for i need to complete similar
task in my work routine. Here which url is it referring by print-url in
this.print = function(print_url, callback).
If url is changing as we change zoom level, how we can incorporate this? Please
if anyone has some suggestions, reply..
regards,
shadab

_______________________________________________
___________________________________________________

Posted on the Users mailing list. Go to http://openlayers.org/mailman/listinfo/users to subscribe.





NewsArc Lists  |  Culture Pages   |  Computing Archive  |  Media-Pages
Link to this page on your blog or website by copying the HTML code below and pasting it into your site: