Monday, February 08, 2010

clearOverlays() in V3

There is no clearOverlays() in API v3. Some practices have been presented. I think this is the simpliest so far.

Push all the overlays in an array when created (as usual). Following code will clear both map and the array:

  while(overlays[0]){
   overlays.pop().setMap(null);
  }

pop() method of an array removes the last element of an array, and returns that element. 'while' keeps that happening as long as there are elements in the array. When overlays[0] does not exist anymore, the mission is completed and code will proceed.

Applied in the example of the previous post.

Rectangle() and Circle() of V3

API v3.28 has new constructors

  new google.maps.Rectangle();
  new google.maps.Circle();

Dimensioning and positioning is set by bounds (Rectangle) or by center and radius (Circle). Circle radius is given in meters. Those can be set as options or by special methods setBounds(), setCenter() and setRadius().  They are documented already.

getBounds() for Circle would be a useful method that is missing.

Altogether those are very handy classes and we can forget my boundsbox.js library in most cases. Image overlaying is still a perfect task for boundsbox.

Quickly testing Rectangle().

.

Friday, January 22, 2010

Suggesting geocoder [3]

From the previous post: "Next logical step of development will be to display all the alternative addresses as a selectable list."

While developing, I found this kind of user interface very handy. You can even learn something new while typing. I like it better than classic maps.google.com.

Maybe I should give a hint to maps.google.com people:)

Play with it and comment please.


<joke>
Many geocoders recognize a placename "undefined".

Thursday, January 21, 2010

Buttonless geocoder [2]

Google's geocoding service is enhanced continuously. It doesn't read your thoughts yet but it is quite forgiving with typos and missing characters.

Now you can see the geocoding result after every character you type in the new geocoder experiment. When you agree with the result in the display, click outside text field or hit Tab or Enter (not IE) and the map is updated too.

So the geocoding request is sent by 'keyup' and map is set by 'change' events of text input field. Clicking on map does not blur the text field and does not trigger 'change'. That is still waiting for a great idea.

Some people can type damn fast. Therefore the geocoding requests are limited to maximum three requests per second.

The 'hint' display shows the first address of the response set. Next logical step of development will be to display all the alternative addresses as a selectable list.

Sunday, January 17, 2010

Custom map types in v3

The latest version update (3.25) introduced custom map types for api v3. The interface is nice. If you are familiar with custom tile sets in v2, there are not many new things to learn. There are three types of custom tile based map types.
  • Image map type, like Open Streetmap tiles in the example page
  • Image overlay map type, like the Traffic tiles in the example page
  • Non-image tile based map type
Image Map Type behaves just like the standard map types. Image Overlay tiles are displayed on top of the Image Map Types. Both of them can be created using ImageMapType class. The difference is how you add the map type to your map. Either to mapTypes registry or to overlayMapTypes MVCArray. Both of them are properties of Map.

The non-image map type makes it possible to create tile layers with SVG, canvas or any html elements.

Tuesday, December 08, 2009

Geocoder without Search button

We are used to see geocoders with address input field and [Search] button.

We can discard the button and use 'onchange' event of the input field instead.

It works quite well. Just type in the address and click anywhere on the page. Well not anywhere because click on map is preventDefaulted. Hitting [Enter] key works too. @M$: please don't file a patent application.

Text input field can also be used for showing how the geocoder actually understood the address.

Full example.

Monday, December 07, 2009

Sidebar with makeMarker() v3

Wouldn't that be convenient if makeMarker(options) would construct a sidebar entry as well. See it here.

A separate SidebarItem() constructor was written. It creates a button element and appends that to a div with id="sidebar" by default. makeMarker() calls the constructor if you have set an option property {sidebarItem: "My label"}

The basic button element needs some CSS cure. You can also style individual sidebar items by setting different CSS class names for them. {sidebarItemClassName: "important_item"}

The events are set to work bidirectionally.
  • click on sidebar -> click on marker
  • select on sidebar -> click on marker (select by [Tab])
  • click on marker -> focus on sidebar
  • mouseover on sidebar -> mouseover on marker
  • mouseout on sidebar -> mouseout on marker
One of the reasons why I selected a button element was that it is 'focusable' and 'selectable'. You can open an info window by stepping the focus to a sidebar item by [Tab] or [Shift]+[Tab] and select the item by [Enter] or [Space] (some browsers). That is called accessibility.

Also you can use :hover and :focus CSS pseudoselectors. (:focus does not work with IE)

SidebarItem() instance has methods addIn() and remove(). We need addIn() to decide where to add the item. That helps to implement the categories.