Google Maps WFS Interface
I’m currently working on a way to use OGC‘s WFS (Web Feature Service) to plot points, polygons, etc. onto Google Maps. I’ve got it to work pretty well for simple points, polylines, and polygons. Give this a try:
I’ll explain a little of how this works. First, it loads the Google Map. Then, it takes the lat/long bounds of the Google Maps, adds a buffer region around the bounds and sends a request for the bounds plus the buffer region to the WFS url. When the request comes back, it clears the map of overlays and marks all of the points in the WFS response XML on the map. It does this cycle every time you change the map type in the upper right.
So, its not complete yet, but it works well for what it is supposed to do right now.
Future Plans:
- DONE – Draw WFS Polygons as GPolylines.
- Tile (similar to Google image tiles) and cache WFS responses (which are just XML files)
- Put attributes of Points into info windows
UPDATE: Worked a little more on it, and it works much better in IE. Something is screwy with my version of FF: 1.0.3.
UPDATE 2: So, maybe it wasn’t a problem with Firefox, but instead a problem of extra space that I wasn’t expecting in the XML input. So, I put in some code to trim the space around the polyline coordinates, and it works much better in FF. I’m still having problems with getting the information I want into the info windows. Javascript just does not have a friendly way to parse XML. I’ll have to learn some more about that. If anyone can help me, that would be great.
August 12th, 2005 at 9:11 am
Hm… Seems like a good idea but I don’t see any points yet?
August 12th, 2005 at 9:32 am
I realized last night that it doesn’t work in IE…. Oops. I’ll have to fix that.
August 12th, 2005 at 4:55 pm
Kyle –
This is excellent. Please keep me appraised of your progress. FYI, there are a couple of other folks out there also working WFS implementations against the Google platform.
Cheers
Carl
August 12th, 2005 at 8:39 pm
Carl,
I’d be interested to talk with whoever is working on them. Oh, and I’ll update my blog, but unless I have an email address, I can’t really contact you personally.
-Kyle
August 14th, 2005 at 11:59 am
Hmm, couldn’t seem to see anything. Is the WFS down?
August 15th, 2005 at 12:57 pm
For IE, looks like you’re missing
v\:* {
behavior:url(#default#VML);
}
August 15th, 2005 at 3:48 pm
So, I added that. Nothing changed. Keep in mind I haven’t gotten around to polylines yet.
August 21st, 2005 at 12:43 am
Your line
Should be
August 21st, 2005 at 12:44 am
<html xmlns=”http://www.w3.org/1999/xhtml”>
<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:v=”urn:schemas-microsoft-com:vml”>
September 16th, 2005 at 4:33 am
Great idea! It shows how important open, XML based standards are!
Franz-Josef Behr
May 1st, 2006 at 2:40 pm
Hi Kyle, Its really nice feeling when i saw we can plot a polyline along the road on google map.
I need to draw polyline along the road. You can assume I have start and end lat-long positions.
But i still did undestand How u doing it in “http://maps.kylemulka.com/test.wfs5.html”. Could please explain me how everything is working and resources which I might be helpful.
Thanks
Amrit
apstiwana@rediffmail.com
May 1st, 2006 at 8:17 pm
Amrit,
None of those lines are plotted along roads necessarily. They are along state boundaries.
The information about where to plot the polylines come from a WFS whose URL is http://webservices.ionicsoft.com/unData/wfs/UN?.
The Google Maps API allows you to plot polylines wherever you want as long as you have the data. Google will not give you the data.
Here’s the Polyline documentation from Google:
http://www.google.com/apis/maps/documentation/#Polylines_overview
Here’s Wikipedia’s entry on WFS:
http://en.wikipedia.org/wiki/Web_Feature_Service
Here’s Mapserver’s WFS Server documentation:
http://mapserver.gis.umn.edu/docs/howto/wfs_server
Email me if you need more info.
-Kyle
May 2nd, 2006 at 7:04 am
Kyle, Thanks for prompt reply.
I have few more questions.
1) What changes I need in .js or .html, to make it run on my local server.
2) Do I need to implement my own WFS server? or there are freely available which I can use for my public site.
Thanks,
Amrit
May 2nd, 2006 at 12:35 pm
The only two things I’m aware of that you would have to change are the Google Maps API key and the link to the javascript file. Copy the javascript file onto your server and change the path to it in the html.
There are many freely available WFS servers you can use. It’s just a matter of finding the one with the data you want to display.
Here’s one listing, but I’m sure you could find many others by Googling.
http://docs.codehaus.org/display/GEOS/Available+WMS+and+WFS+servers
-Kyle
May 3rd, 2006 at 6:18 am
The two things which you mentioned to change, were already done. But the its not plotting the line alone state boundaries. Can you please let me know if i need to change anything else. I read few comments regarding wfs proxy in .js file. But couldn’t figure out anything.
Thanks,
Amrit
May 3rd, 2006 at 6:48 am
It worked, i just commented the proxy part in .js file.
May 8th, 2006 at 12:28 am
I am new to google map API. I’ve tried using version 2 which gives me error GMapWFS is undefined. Got any remedies for this or any documentation?
thanking u in advance
May 8th, 2006 at 12:28 am
I am new to google map API. I’ve tried ur code using version 2 which gives me error GMapWFS is undefined. Got any remedies for this or any documentation?
thanking u in advance
May 8th, 2006 at 12:56 am
OOps! it includes js file. Now got error saying object doesn’t support this property or method at line 152. I am actually trying to overlay simple line feature.
January 6th, 2007 at 11:52 pm
I am having trouble using your code to load an xml file off another server. I understand that loading xml files is subject to the ‘same origin’ rule, which is a security option in most browsers that prevents web pages from loading data from sites with different base urls. How have you overcome this? So far as I can tell, you should be getting an error when you load the page:
Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
January 7th, 2007 at 3:37 pm
Wade, I have a proxy script on my server which basically just takes the request and passes it on to the remote WFS server:
http://maps.kylemulka.com/wfs_proxy.phps
January 7th, 2007 at 8:45 pm
Oh I see. Thank you for your help.
April 29th, 2007 at 6:16 am
Where can I get the javascript (GMapWFS)?
Thanks
June 14th, 2007 at 8:38 am
Hi Kyle.
I’ve had a go with this for our site. I’ve reimplemented your wfs library to use the GMap2 class and used xparse (http://www.jeremie.com/Dev/XML) for the attribute data.
There’s a link to a live version below: It’s probably buggy but the only thing I can’t get to work at all is the openInfoWindowHTML method so I’ve had to bung the attribute data into a separate div below the map. I wondered if this might have something to do with clearing the overlays when the map moves.
http://www.humber-edc.org.uk/gmap/wfstest.html
Let me know if you have any thoughts.
Cheers. Dan
August 5th, 2007 at 9:42 am
i am one of the other folks working on WFS support for google maps
TNTmap has it in its alpha version… the services panel lets you choose wfs services
http://www.microimages.com/ogc/alpha
a stripped down example targetting a specific wfs is at http://www.dyasdesigns.com/egeotest/wfsusa.htm
Basically I have adapted EGeoXML(KML parser to parse GML and GeoRSS.
It is a work in progress but quite far along
http://www.dyasdesigns.com/egeotest/
Dyas Designs is my private site and is sometimes down but the microimages.com should always be up and running.
There are some limitations including the slow on the fly polyline encoding and wfs servers who wont serve up latlong coordinates