[OpenLayers-Users] How to print map area with openlayers

guillaumev guillaume at viguierjust.com
Tue May 4 10:44:49 EDT 2010


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.



More information about the Users mailing list