|
Author: Roberto Colonello Article source: http://www.parsec.it/. Used with author's permission.
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);
?>
Show Weather On Map
More info: http://www.parsec.it/tutorials/ Roberto Colonello owns and operates http://www.parsec.it and http://www.gmdir.com
Tips On Buying Keyboards And Digital Pianos There are so many keyboards and digital pianos on the market today. How does one make a selection? Here are a few tips to help you choose one that meets your ne...
Home Equity Increases $1 Trillion in Five Years – Is the Market Peaking? The huge increase in California home equity and in the number of interest-only mortgages suggests that the real estate market may be peaking. Buyers should be ...
Concrete Cleaning Discussed at World of Concrete Expo 03 If you are in the pressure washing business and are serious about what you clean on the ground floor, I suggest you attend the WOC. The WOC is the World of Conc...
Camping Stove Performance: Ease of Use & What to Avoid Learn how to choose the best type of camping stove for the type of camping, hiking or backpacking you do.
Signature Frames - Your Guestbook and Wedding Frame Together At Last! Signature frames are a modern solution of combining the traditional guestbook and wedding photography into a unique framed display. This new wedding frame can b...
The Answer to Your Worst Networking Nightmare Imagine you just met your ideal client at a networking event. He's friendly, has great ideas and could use a valuable person like you to help grow his business...
A Life Insurance Quote Became Reality Thank goodness John took his life insurance quote seriously. It didn't prevent our daughters from wishing he were still here but thanks to his foresight they an...
What Does It Take To Be Happy? Happiness, an important issue in the lives of many and at the same time it appears to be an elusive experience. Why is this? In this article I discuss reasons w...
Increasing E-commerce Website Sales With consumers purchasing billions of dollars of merchandise online each and every year, the Internet has become the key to financial security. The e-commerce b...
Aviation Maintenance Job Boards A career in aviation maintenance presents many job opportunities for the savvy job seeker. Some of the top employment sites are listed within.
How You Feel Affects How You Shop & How Much You Spend Article points out the downfalls of shopping when your mood is not right. Being upset, angry, or depressed can have drastic consequences on your pocketbook afte...
8 BIG Benefits To Selling Big Ticket Items Are you sick and tired of selling E-books or other low profit items? Discover what the big name marketers understand about the benefits of selling big ticket it...
Publish It Now! No Matter What It Is Many people, some very good writers, simply give up. Today, we live in the electronic age, and the process for writers has become amazingly simple; it's just t...
Intranet Portal – Business Case ROI How can I make the business case for an Intranet, or Corporate, Portal? What benefits can I include to establish a decent Return on Investment (ROI)? This art...
Christmas Recipes: Main Dishes. No.10 of 12 - Lamb with Chestnut and Tomato Relish A christmas recipe main dish to try on your friends and relatives. Something different.
Do Your Children Stress You Out? "Do your Children stress you out?" - is an article that gives you 3 simple ways to talk or communicate more effectively with your children.
As a parent you wi...
Georgian And Victorian Style Conservatories A look at the evolution of georgian and victorian style conservatories and how they compare in today's world.
What is Romance, and How Can You Be More Romantic? Whether you've been in a relationship for a long time, or whether you're single, learning how to romance and love can be one of the greatest skills to learn (an...
The Ins and Outs of Dropshipping on eBay Dropshipping is an attractive marketing technique, but when you take it to eBay it becomes a real phenomenon. There are tens of thousands of people running drop...
Some Truth About Credit Credit is the foundation of business funding and needs to be considered and developed with patience and diligence
Hear What Your Diet Pills Say The article on weight loss helps you know more about diet pills and tips you with the most efficient ways to have diet pills for best results.
Baby Safety Checklist - Protecting Your Baby There are so many things to think about when bringing home a new baby. Here is a checklist to ensure that your home is baby friendly.
Poor Credit Mortgage Reigns High Among Mortgages Available to Bad Credit Borrowers Borrowers looking for poor credit mortgages feel that they are all alone in their search. However, there is a thriving market for poor credit mortgages, given t...
To MLM or Not to MLM Whether you want to be your own boss or you want to be handsomely rich, the internet offers great possibilities. Maybe too many! Here's some helpful, firsthand...
|