Dynamic Maps with php??

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a little php application to store day hiking trips and to keep a
running total of their yearly trips for a few users.  Currently they
select their hiking routes using drop lists or checkboxes containing the
names and numbers of the trails.  If the route is simple the form takes
1-2 minutes to fill in, if it involves lots of  tiny sections it can
become tedious to search for every trailname and may take 20 minutes.
Because of this they have asked for a map, rather than lists, and want
to open the application to the public.  Hmmm..

So I'm looking to create an application where users can select their
routes, by somehow selecting lines on a map, then somehow pass this to a
php script to process.

Suggestions on how to do this are invited.  I hope it's trivial, I fear
it isn't.


Re: Dynamic Maps with php??

Craig Storey wrote:

Quoted text here. Click to load it

Not really trivial, but may be easier than you think... hope you know
Flash & ActionScript....

Flash can send/retrieve values from PHP scripts in the background by
using the getURL/loadVariables methods (as well as using XML and the
like). Since Flash uses vector art, you can use it to zoom in-and-out of
parts of a map and such. I'd go into all the details here, but that's
the kind of thing I get paid for at work... ;)

That should be enough information to allow you to find the correct stuff
on Google to help you out. I won't plug my employer's name here, I'm not
fishing for projects right now, but if you need services, email me.

Justin Koivisto - justin@koivi.com

Re: Dynamic Maps with php??

Quoted text here. Click to load it

 Sounds like you basically need an image map. The old-style server-side image
maps rather than client-side maps may be the way to go, since these just pass
x/y coordinates of the click to the script. You can then look up the nearest
point or line to the click and add it to the route.


 Then with the GD functions (http://php.net/image ) you should be able to
superimpose a route on a map.

 It's a round-trip to the server for each click - this might be a little
annoying but it's simple and safe. You could get fancy with
JavaScript/XMLHTTPRequest type things to avoid roundtrips, but you probably
want to save that for version 2 :-)

<http://www.andyhsoftware.co.uk/space Space: disk usage analysis tool

Re: Dynamic Maps with php??

Craig Storey wrote:

Quoted text here. Click to load it

You could try to do this with SVG graphics.  If you can get your maps in an
SVG format.  This also means you're visitors need an SVG plugin.
But it would be a kick-ass solution...

http://www.carto.net/papers/svg/links /
http://www.webreference.com/authoring/languages/svg /
http://kartoweb.itc.nl/public_examples/SVG /
http://www.w3.org/2004/Talks/1211-Twente -

Rutger Claes                                                rgc@rgc.tld
Replace tld with top level domain of belgium to contact me    pgp:0x3B7D6BD6
Do not reply to the from address.   It's read by /dev/null and sa-learn only

Re: Dynamic Maps with php??


I have been working on a GIS for several years. I was using a ready-made
framework for it. The learning curve of a framework is often seen as a
downside, but imho if you actually need to learn about something as
complex as GIS, the opportuninty the framework offers you to learn by
looking into existing code and trying out the examples rather is an
advantage. Without the framework i would have needed much more time to
get into GIS programming.

Unfortunately this framework was Smalltalk, so it won't be much good for
php. So I agree with Rutger that you should try out SVG. Mainly because
i think it is the eayest way to learn about the graphics technology you
will need to handle those x, y coordinates from clickable maps. I don't
think SVG is ALL you need, i think you will need to build some sort of
server side representation of those graphics and things like 'trails' in
php too. I suggest you use an object oriented domain model, like the
ones used by phpPeanuts. But to know what these models should actually,
well, MODEL, SVG is a great place to start.

One other tip: The new version of MySQL has GIS extensions. These will
also help you with the server side model, and at the same time they may
boost the performance of your server side code dramatically.

If you need more advice or help, please let me know.

Greetings, succes,

Henk Verhoeven,

BTW, for the same reason i think the learning curve of phpPeanuts is
actually an advantage if you want to learn somthing as complex as OOP ;-)

Rutger Claes wrote:
Quoted text here. Click to load it

Re: Dynamic Maps with php??

Quoted text here. Click to load it

If you know Flash, then it's trivial. If not, then Javascript is probably a
easier option, as Flash is tricky, especially when you have to deal with

I would do it like this:

1. Create two transparent gifs per trail, one showing it as selectable and
the other as selected. These images should be of the same size as the map.
2. Overlay all these images on the map, with the CSS visibility of the
selected ones set to hidden. The HTML will look something like this:

<div style="position: relative">
<img src="map.gif">
<img src="trail1_gray.gif" id="trail1"
            style="position: absolute; left: 0; top: 0;">
<img src="trail1_red.gif"  id="trail1_sel"
            style="position: absolute; left: 0; top: 0; visibility: hidden">
<img src="trail2_gray.gif" id="trail2"
            style="position: absolute; left: 0; top: 0;">
<img src="trail2_red.gif"  id="trail2_sel"
            style="position: absolute; left: 0; top: 0; visibility: hidden">
.... etc ...

3. On top of all these, overlay a blank transparent gif of the same size as
the map. This will be used for the image map.
4. Create a client-side image map for users to click on. Use polygon regions
to define clickable area near each trail. Attach an onclick handler to each
area. The HTML will look something like the following:

<map name="trails">
<area shape="polygon" coords="123,23,32,434,45,342"
        onclick="return ToggleTrail(1)" title="Trail 1">
<area shape="polygon" coords="231,232,332,34,35,142"
        onclick="return ToggleTrail(2)" title="Trail 1">
.... etc ...
5. In the Javascript handler toggle between the selectable and selected
image by setting the CSS visibility to hidden/visible. Save the selection
somewhere. The code will look something like this:

function ToggleTrail(num) {
    if(selected[num]) {
        document.getElementById('trial' + num).style.visible = 'visible';
        document.getElementById('trial' + num + '_sel').style.visible =
        selected[num] = false;
    else {
        document.getElementById('trial' + num).style.visible = 'hidden';
        document.getElementById('trial' + num + '_sel').style.visible =
        selected[num] = true;
6. When the user press submit, saved the selections into a hidden element
and post the form.

Obviously you will need to add code that checks whether the trails are
actually connected.

Re: Dynamic Maps with php??

Craig Storey wrote:
Quoted text here. Click to load it
  Thanks for all the great ideas!


Re: Dynamic Maps with php??

Take a look at www.mountainviews.ie which uses dynamic maps built from php,
sql, image-maps, GIS, SRTM data etc.

Quoted text here. Click to load it

Site Timeline