Easy map controls in Ubiquity XForms

The map controls in Ubiquity XForms are by far the simplest way to add Google Maps to your web pages. This article shows you how to use them and some of the extra benefits that you get from the XForms engine powering them. Screenshot of a map in Ubiquity XForms

A basic map

There are three easy steps involved in adding a map to your web page. The first one is to paste the XForms namespace declaration on to the html root element:

  1. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">

Next, you need to paste a couple of script tags into your document's head:

  1. <script src="http://ubiquity-xforms.googlecode.com/svn/trunk/src/ubiquity-loader.js" type="text/javascript">/**/</script>
  2. <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ENTER YOUR GOOGLE MAPS API KEY HERE" type="text/javascript">/**/</script>

These will load Ubiquity XForms and Google Maps. Google Maps requires you to get an API key from their site. When you have one, just paste it in place of the text: ENTER YOUR GOOGLE MAPS API KEY HERE

The third and final step is to add an XForms output control to the body of your document. The control must have the attribute class="geolocation" and a value attribute that evaluates to the location that you want to display. The location can be in the form of an address, or a semi-colon separated latitude and longitude pair of co-ordinates. For instance, the following markup displays a map showing the location of the webBackplane office in central London:

  1. <xf:output value="'4 Pear Tree Court, London, EC1R 0DS'" class="geolocation" />

If you just want to display a static map on your page, then that is all you need. However, the presence of Ubiquity XForms enables things to get a lot more interesting than that.

User input

You may notice that the map in the previous example does not permit the user to change the location. There are buttons to zoom in and out, but the centre point is locked in place. This is because it uses output, which does not allow user input by definition. In order for a user to move your map around, you have to swap the output control for a range control. And, since range doesn't support the value attribute, you'll also need to add an XForms model containing the instance data that the range can be bound to:

  1. <xf:model>
  2. <xf:instance>
  3. <location xmlns="">4 Pear Tree Court, London, EC1R 0DS</location>
  4. </xf:instance>
  5. </xf:model>
  6.  
  7. <xf:range ref="/location" class="geolocation" />
4 Pear Tree Court, London, EC1R 0DS

You will see that, although the map looks similar to the last example, it now has buttons for panning the map north, south, east and west. Additionally, if you click and hold the left-hand mouse button, you can drag the map to move it to a new location. Each time you move the map, the bound instance data will get updated with the centre point, indicated by the red map marker. You can further verify this binding by adding a second map, bound to the same instance data as the first one. Each time you move the position of the first map, the position of the second will get updated automatically by the XForms dependency engine and vice versa:

  1. <xf:model>
  2. <xf:instance>
  3. <location xmlns="">4 Pear Tree Court, London, EC1R 0DS</location>
  4. </xf:instance>
  5. </xf:model>
  6.  
  7. <xf:range ref="/location" class="geolocation" />
  8.  
  9. <xf:range ref="/location" class="geolocation" />
4 Pear Tree Court, London, EC1R 0DS

Adding a hint

In XForms, each of the UI controls can be complemented with a child hint element. Ubiquity XForms makes use of hint for map controls to add contextual information to the map marker. When the user clicks the left-hand mouse button on the central map marker, an information bubble will pop up. In an output map control, this information might be static data:

  1. <xf:output value="'4 Pear Tree Court, London, EC1R 0DS'" class="geolocation">
  2. <xf:hint>webBackplane office</xf:hint>
  3. </xf:output>
webBackplane office

For range controls though, you would most likely want the hint itself to be based dynamically on the current location of the map. Fortunately, this is straightforward to achieve with the ref attribute on the hint element:

  1. <xf:model>
  2. <xf:instance>
  3. <location xmlns="">4 Pear Tree Court, London, EC1R 0DS</location>
  4. </xf:instance>
  5. </xf:model>
  6.  
  7. <xf:range ref="/location" class="geolocation">
  8. <xf:hint ref="." />
  9. </xf:range>
4 Pear Tree Court, London, EC1R 0DS

Notice how, after the map is moved, clicking on the marker will display different information: the latitude and longitude of the newly selected location.

Styling your maps

Map controls can be further customised by setting the width and height via CSS. Depending on how much space you assign to display the map, Ubiquity XForms will make decisions about which adornments should be displayed. It also initialises maps to a zoomed out, progressively less detailed view as their size is reduced. In the following example, the output control will be displayed with no adornments and zoomed out, whereas the range control will be displayed zoomed in with a full set of adornments. But because they are bound to the same instance data, they are just different views of the same location. Panning the map in the range will also cause the location of the output map to shift:

  1. <xf:model>
  2. <xf:instance>
  3. <location xmlns="">4 Pear Tree Court, London, EC1R 0DS</location>
  4. </xf:instance>
  5. </xf:model>
  6.  
  7. <xf:output ref="/location" class="geolocation" style="width: 100px; height: 80px;" />
  8.  
  9. <xf:range ref="/location" class="geolocation" style="width: 650px; height: 400px;" />
AttachmentSize
ubiquity-xforms-map-detail.jpg22.85 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

There are buttons to zoom in

There are buttons to zoom in and out, but the centre point is locked in place.
Business Travel Blog

I never usually post on blogs

I never usually post on blogs but I have found this is very useful work. I high appreciate this post.
Cialis

Thanks for nice article,

Thanks for nice article, which shows me how to use Ubiquity XForms easier than before.
personal loans

This is a good piece of

This is a good piece of writing mate for this particular topic. I was wondering if I could use this write-up on my website, I will link it back to your website though. If this is a problem please let me know and I will take it down right away.
Depression Treatment

self-defeating. I have had

self-defeating. I have had clients who just seem to want to jam thing into their sites w/o thinking of their audience. Thanks for the comment, ask me anything else.link building service

I have spent quite a long

I have spent quite a long time to read and re-read your article. it is pretty much informative and it was also a very good Essay Help for me as a student who was looking for the info like that.
Cheers,
Stewe

Hey very nice blog!! Man ..

Hey very nice blog!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also..
online casino

It helped me with ocean of

It helped me with ocean of knowledge so I really believe you will do much better in the future I appreciate everything you have added to my knowledge base .Admiring the time and effort you put into your blog and detailed information you offer! thermal infared

I like to spend my free time

I like to spend my free time by reading various internet recourses. Today I came across your blog and I found it is as one of the best free resources available! Well done! Keep on this quality!
chat software

Aw, it was a top quality

Aw, it was a top quality content. Actually I would like to write like this as well - taking time and real energy to bring about an excellent post... however what can I say... I procrastinate an awful lot and by no means appear to get things completed...
simulation assurance auto

i loved it. Seo Services Seo

I would like to write like

I would like to write like this as well - taking time and real energy to bring about an excellent post.Freelance SEO India | PSD To HTML Services

This article showed me how to

This article showed me how to use them and some of the extra benefits that I got from the XForms engine powering.cheap hosting

nice work. web

It helped me with ocean of

It helped me with ocean of knowledge so I really believe you will do much better in the future I appreciate everything you have added to my knowledge base .Admiring the time and effort you put into your blog and detailed information you offer! tv on pc

the post about easy map

the post about easy map controls in Ubiquity XForms.Thanks for this wonderful update and hoping,,Best SEO

Great blog. There's a lots

Great blog. There's a lots good data in this blog, though I would like tell you something. I can understand the content, but the navigation doesn't work so good. I never usually post on blogs but I have found this is very useful work. I high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information? Dog Obedience

Resources like the one you

Resources like the one you mentioned here is very useful! I will post a link to this page on my blog. I am sure my visitors will find that very useful. thank you for sharing
ava fx

Best site for quality written

Best site for quality written essay paper, term paper, research paper, course work, book report and resume writing. All writing services are guaranteed written by professional writers.

I really loved reading your

I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well! simmons beautyrest world class

The post is written in very a

The post is written in very a good manner and it entails many useful information for me. I am happy to find your distinguished way of writing the post about easy map controls in Ubiquity XForms.Thanks for this wonderful update and hoping to post more of this!
chase auto loan

That is great to read this

That is great to read this page about the map controls in Ubiquity XForms,which are by far the simplest way to add Google Maps to your web pages. This article showed me how to use them and some of the extra benefits that I got from the XForms engine powering them.
chase personal loans

I am wondering does this map

I am wondering does this map work better than that of google's??
free advertising |job listings|tempurpedic

Actually I would like to

Actually I would like to write like this as well - taking time and real energy to bring about an excellent post...Link Building

I love open source because it

I love open source because it helps other to continue to expand on other peoples ideas, it allows for problems that were unfix able to become fixable through the collaboration of other peoples thoughts and ideas.
p90x workoutwe
insanity workoutall
turbo firebenefit
p90x chin up barfrom
p90xopen source

That is really nice, thanks!

That is really nice, thanks! I will use it when I need some jobs for writers or the IT guys.

I have read which are really

I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well!Fiesta leasing

yes thnaks from sudoku solver

yes thnaks from sudoku solver sudoku solver as well

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.