bluedigger.com bluedigger.com
Search:    Site Home -> About Us -> Privacy -> Terms & Conditions -> Add Your Link -> Submit Article   
Add Url
 

Companies & Business

Entertainment

Fitness & Health

Tour & Travel

Children & Teens

Computers & Networking

Healthcare & Medicine

Employment & Careers

Technology & Science

Vehicles & Automotive

Shopping Online

Finance & Investment

Fashion & Relationships

Politics & Government

Games & Play

Sports & Adventure

Issues & News

Self Enhancement

Home & Garden

Food & Recipe

Property & Estate

Creative Arts

Education & Reference

People & Communities

 

Site Home » Computers & Networking » Website Development
 

How to Draw Icons or Images on a Mapserver Generated Map

 
Author: Roberto Colonello

In this example I have used the map of the Itasca demo of the Mapserver. I have done only small changes to the map file. The Itasca demo has (into the html file) the parameters of the path where to store the images:

IMAGEPATH "set in index.html" IMAGEURL "set in index.html"

I have changed them as fixed path

IMAGEPATH "/tmp/ms_tmp/" IMAGEURL "/ms_tmp/"

Than I have set as STATUS ON several layers for a better map.

The Database

The positions and the images paths that have to be shown on the map are stored into a table of a database in MySql. I have created a new database named "mapexample" and a new table "weather":

CREATE TABLE weather (

id bigint(20) NOT NULL auto_increment,

imagepath varchar(255) default NULL,

x double(16,4) default NULL,

y double(16,4) default NULL,

PRIMARY KEY (id)

)

and than I have inserted into the table the positions of the weather images and the path of every icon:

INSERT INTO `weather` VALUES (1, '/data/weather/icons/sunny.gif', 478107.0000, 5250301.0000); INSERT INTO `weather` VALUES (2, ''/data/weather/icons/cloudy.gif', 408107.0000, 5220301.0000); INSERT INTO `weather` VALUES (3, ''/data/weather/icons/storm.gif', 468107.0000, 5270301.0000); INSERT INTO `weather` VALUES (4, ''/data/weather/icons/variable.gif', 408107.0000, 5310301.0000);

It is not necessary for the images to be stored into a directory visible from the web, because are taken directly by the script and then merged with the map.

The PHPMapscript code Here is the code I have used for generating the map:

define("img_WIDTH", 0); define("img_HEIGHT", 1); define("img_TYPE", 2);

// CONFIGURATION OF MYSQL ACCESS $MyHost = "localhost"; $MyLogin = "root"; $MyPassword = ""; $MyDatabase = "mapexample";

$mappath = "D:/data/web"; $scale_to_showicons = 1000000; // SCALE LIMIT TO START TO SHOW THE ICONS ON THE MAP

function AddImagesToMap($mapurl) {

global $MyHost, $MyLogin, $MyPassword, $MyDatabase, $scale_to_showicons, $map, $mappath;

// CONNECT TO DATABASE

@mysql_connect($MyHost, $MyLogin, $MyPassword);

@mysql_select_db($MyDatabase);

// IF the scale is small enougth to show the images on the map?

if ($scale_to_showicons > $map->scale) {

// PATH WHERE TO FIND THE MAP IMAGE GENERATED BY MAPSERVER

$mapimagepath = $mappath . $mapurl;

$mapdim = GetImageSize($mapimagepath);

$coords_map_width = $map->extent->maxx - $map->extent->minx;

$mapscale = $mapdim[img_WIDTH] / $coords_map_width;

switch ($mapdim[img_TYPE]) {

case 1:

$mapimg = ImageCreateFromGif($mapimagepath);

break;

case 2:

$mapimg = ImageCreateFromJpeg($mapimagepath);

break;

case 3:

$mapimg = ImageCreateFromPng($mapimagepath);

break;

} ;

$qry .= "select * from weather where x > '" . $map->extent->minx . "' AND x < '" . $map->extent->maxx . "'

AND y > '" . $map->extent->miny . "' AND y < '" . $map->extent->maxy . "'";

$res = mysql_query($qry);

while ($row = mysql_fetch_object($res)) {

$dimic = GetImageSize($row->imagepath);

switch ($dimic[img_TYPE]) {

case 1:

$tmpimg = ImageCreateFromGif($row->imagepath);

break;

case 2:

$tmpimg =?; ImageCreateFromJpeg($row->imagepath);

break;

case 3:

$tmpimg = ImageCreateFromPng($row->imagepath);

break;

}

$x = ($row->x - $map->extent->minx) * $mapscale;

$y = $mapdim[img_HEIGHT] - (($row->y - $map->extent->miny) * $mapscale);

@ImageCopy ($mapimg, $tmpimg, $x, $y, 0, 0, $dimic[img_WIDTH], $dimic[img_HEIGHT]);

} ;

// SAVE THE NEW IMAGE ON THE OLD ONE

switch ($mapdim[img_TYPE]) {

case 1:

ImageGif($mapimg, $mapimagepath);

break;

case 2:

ImageJpeg($mapimg, $mapimagepath);

break;

case 3:

ImagePng($mapimg, $mapimagepath);

break;

}

} ; } ;

$map = ms_newMapObj("itasca.map");

$img = $map->draw(); $url = $img->saveWebImage(); AddImagesToMap($url);

?>

More info: http://www.parsec.it/tutorials/

Author Bio:
Roberto Colonello is a reputed author. Roberto likes to write articles about this subject.
You can search for this article using: How to Draw Icons or Images on a Mapserver Generated Map, Computers & Networking
 
 
 

Related Articles

 
A Closer Look at Using a Template Site - Is It Professional Choice?
 
I Hate Asking for Referrals! - 6 Proven Methods for Getting a Flood of Referrals Without Asking
 
Search Engine Optimization: Who Do You Trust?
 
How DLP Projectors Work?
 
7 Essential SEO techniques
 
How to Make Money Online with Affiliate Programs
 
More Visitors for Your Web Site with Quick Keyword Optimization
 
Free Maintenance Management Software
 
Absolute References Vs Relative References in Microsoft Excel
 
Stop Renting Your Profits: Can You Survive Without Affiliate Programs?
 
 
 
 
 

Learn about the Google Search Engine Tools

Think you know everything about searching with Google? Think again. Believe it or not, there are man ... - Shell Harris
 

I Did Not Know Software Could Do That, Part II

It never ceases to amaze me how sophisticated and incredibly original some software developers are. ... - John Deprice
 

Simple Steps To Proper Web Design

The importance of knowing proper web design can very well determine where your site is listed in sea ... - John Kovacs
 
 

Search Engines & Web Directories

The so called search box should be given a correct name "search engine" which can be further divided ... - Phillipe Wu
 

Can You Become a Professional Internet Marketing Consultant?

Test yourself and find out if you've got what it takes to be a successful internet marketing consult ... - Christopher J Enders
 
 
Site Home -> Privacy -> Terms & Conditions  
© 2008 www.bluedigger.com All Rights Reserved.