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:

WFS Example

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.

25 Responses to “Google Maps WFS Interface”

  1. Jason Says:

    Hm… Seems like a good idea but I don’t see any points yet?

  2. Kyle Mulka Says:

    I realized last night that it doesn’t work in IE…. Oops. I’ll have to fix that.

  3. Carl Says:

    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

  4. Kyle Mulka Says:

    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

  5. mapgenix Says:

    Hmm, couldn’t seem to see anything. Is the WFS down?

  6. Bryce Says:

    For IE, looks like you’re missing

    v\:* {
    behavior:url(#default#VML);
    }

  7. Kyle Mulka Says:

    So, I added that. Nothing changed. Keep in mind I haven’t gotten around to polylines yet.

  8. 58sniper Says:

    Your line

    Should be

  9. 58sniper Says:

    <html xmlns=”http://www.w3.org/1999/xhtml”>

    <html xmlns=”http://www.w3.org/1999/xhtml” xmlns:v=”urn:schemas-microsoft-com:vml”>

  10. fjbehr Says:

    Great idea! It shows how important open, XML based standards are!

    Franz-Josef Behr

  11. Amrit Says:

    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

  12. Kyle Mulka Says:

    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

  13. Amrit Says:

    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

  14. Kyle Mulka Says:

    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

  15. Amrit Says:

    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

  16. Amrit Says:

    It worked, i just commented the proxy part in .js file.

  17. raman Says:

    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

  18. raman Says:

    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

  19. raman Says:

    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.

  20. Wade Says:

    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

  21. Kyle Mulka Says:

    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

  22. Wade Says:

    Oh I see. Thank you for your help.

  23. kutte Says:

    Where can I get the javascript (GMapWFS)?
    Thanks

  24. Dan Says:

    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

  25. Lance Dyas Says:

    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

Leave a Reply