Search the web
Sign In
New User? Sign Up
yws-maps · Yahoo! Maps Developer Community

Group Information

  • Members: 3977
  • Category: Internet
  • Founded: Jun 9, 2005
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

  Messages Help
Advanced
JS code to load xml data points   Message List  
Reply Message #612 of 7486 |
Re: JS code to load xml data points

--- In yws-maps@yahoogroups.com, "digitaldelisle" <luc@d...> wrote:
>
> I want to load data in an xml file and be able to create markers on
> the map accordingly
>
> The xml would contain the following fields
> Lat, long, description
>
> Can someone please point me to a Java script example of the code that
> would do this using the new BETA of Yahoo maps

There are two APIs that use Javascript. There is JS-Flash where
Javascript controls a Flash map component and there is the AJAX API
where Javascript controls a DHTML version of the map. You didn't
indicate which one you were interested in.

For the JS-Flash API it is really easy. It sounds like you have some
control over your XML file. If so, make it look like this:

<rss version="2.0">
<channel>
<item>
<title>Title for Entry 1</title>
<description>Description for Entry 1</description>
<link>http://example.com/some_link</link>
<geo:lat>51.8421</geo:lat>
<geo:long>-174.6053</geo:long>
</item>
... more items here ...
</channel>
</rss>

Generate that and stick it on your web server. Then in your JS code
do this:

overlay = new GeoRSSOverlay('http://your.server/file.xml');
mymap.addOverlay(overlay);

There is a full example here using the US Geological earthquake data:

http://lerdorf.com/php/ymap/rssquakes.php

If you want to use the JS-DHTML API, then it is a bit harder. The
easiest way is to throw a bit of PHP at the problem server-side. You
read the XML file server-side and then generate a new YMarker for each
item. You can also do it client-side in Javascript and parse the XML
there, but I am a server-side guy and find it easier to grasp from
that end. You still need some Javascript trickery to get the
smartwindow stuff working right. Here is a DHTML version of the
earthquake example:

http://www.lerdorf.com/php/ymap/dquakes.php

There is a source code link at the bottom there. The magic is in
these 4 lines of PHP-enhanced Javascript that are run for each item in
the XML file with $i being the incrementing index.

First, create a YMarker at the lat/long from the XML file.

marker[<?php echo $i?>] = new YMarker(new YGeoPoint(<?php echo
$feed[$i]['lat'][0].','.$feed[$i]['long'][0]?>));

Then add a label. We'll just use the index number. Would probably
look cooler to pick out the earthquake magnitude here.

marker[<?php echo $i?>].addLabel("<b><?php echo $i?></b>");

Now a trick. We'll use a dynamic function which bakes in the per-item
eathquake info which will get called on a click on each marker.

YEvent.Capture(marker[<?php echo $i?>], EventsList.MouseClick, new
Function("marker[<?php echo $i?>].openSmartWindow('<?php echo
$info?>');"));

And finally, we add the marker to the map.

mymap.addOverlay(marker[<?php echo $i?>]);

Not that hard, but a whole lot harder than just calling GeoRSSOverlay.
The one advantage with this latter approach is that you can handle
any XML file format. There is also an example of doing this manually
with the JS-Flash API here: http://www.lerdorf.com/php/ymap/yquakes.php

-Rasmus






Mon Nov 7, 2005 9:28 am

rlerdorf
Online Now Online Now
Send Email Send Email

Message #612 of 7486 |
Expand Messages Author Sort by Date

I want to load data in an xml file and be able to create markers on the map accordingly The xml would contain the following fields Lat, long, description Can...
digitaldelisle Offline Send Email Nov 6, 2005
5:50 am

I have been playing around with Yahoo Maps for 3 days now. I am trying to create a point on a map for all the users in my website's user database -- users...
Del Dhanoa
dhanoad Offline Send Email
Nov 6, 2005
3:08 pm

I agree, Tutorials are very big right now in terms of helping developers and users of advanced products to really get up to speed. Flash Video is really...
Robert Thompson
robert_thomp... Offline Send Email
Nov 6, 2005
4:45 pm

How about a Wiki? In the meantime . . . How about those of us who have something working, using the new features, post the link here with some pointers on how...
ridemaps Offline Send Email Nov 6, 2005
5:00 pm

That's a great point ridemaps....I'm afraid however that Wiki is something new to me. I've seen it on several sites and am familiar with it, but not it's...
Robert Thompson
robert_thomp... Offline Send Email
Nov 6, 2005
7:24 pm

so is anyone going to publish some tutorials? also, has anyone noticed that the javascript version of Yahoo! Maps loads darn slow compared to the other ones? ...
Del Dhanoa
dhanoad Offline Send Email
Nov 6, 2005
8:48 pm

... Well, if Yahoo! Would like to hire me (Big Friendly Grin) to do it . . . Quick! Somebody teach me this stuff! (on the off chance that Yahoo! decides to...
ridemaps Offline Send Email Nov 6, 2005
9:27 pm

Hi, I wrote an AJAX tutorial that describes how the make REST calls get data to overlay on your maps. ...
Dan Theurer
dantheurer Offline Send Email
Nov 6, 2005
10:50 pm

Robert, More info than you could want at http://wiki.org But for just the definition, http://wiki.org/wiki.cgi?WhatIsWiki ... something new to me. I've seen...
ridemaps Offline Send Email Nov 6, 2005
9:32 pm

Thanks, but it's really more of a phenomena than a good technology. But thanks for the ref. ridemaps <yahoogroups@...> wrote: Robert, More info than...
Robert Thompson
robert_thomp... Offline Send Email
Nov 6, 2005
9:34 pm

My appologies, wrong link. http://en.wikipedia.org...
ridemaps Offline Send Email Nov 6, 2005
9:40 pm

... I have a couple of things up at http://toys.lerdorf.com/ The http://lerdorf.com/map example with source at http://lerdorf.com/map.phps is a good example of...
Rasmus Lerdorf
rlerdorf Online Now Send Email
Nov 7, 2005
5:53 am

... There are two APIs that use Javascript. There is JS-Flash where Javascript controls a Flash map component and there is the AJAX API where Javascript...
Rasmus Lerdorf
rlerdorf Online Now Send Email
Nov 7, 2005
9:31 am

Thank You so much for Your reply Rasmus, I used your recommandations and the code from the Earthquake web site and when I load the page, the map won't load....
digitaldelisle Offline Send Email Nov 7, 2005
6:51 pm

... My example uses server-side PHP. If you look at the source for that mymapnew3.htm page, you will see the PHP tags. This means that PHP was not activated...
Rasmus Lerdorf
rlerdorf Online Now Send Email
Nov 8, 2005
11:16 am

Hello Rasmus and thanks again After running the phpinfo I get a full page of stuff I'm running PHP 4.3.11 (By Zend V 1.3.0) I renamed my html file to PHP...
digitaldelisle Offline Send Email Nov 8, 2005
2:20 pm

I get the same results with PHP 4.3.11 with Zend. Jim ... __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 ...
Jim Georgeson
jimgeorgeson Online Now Send Email
Nov 8, 2005
2:25 pm

This is actually a way to get Yahoo weather into a map. Assuming someone submits a zip....
arbmorris Offline Send Email Feb 1, 2007
5:57 pm

Hello Rasmus, I was able to solve my problem Thanks for your help ... From: "Rasmus Lerdorf" To: yws-maps@yahoogroups.com Subject: [yws-maps] Re: JS code to...
Luc Delisle
digitaldelisle Offline Send Email
Nov 14, 2005
5:48 pm
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help