Mr. CP's Blog

Webdeveloper, working for Euroinvestor, located in Hellerup, Denmark

Random thoughts part 2

clock July 15, 2011 23:47 by author CP

Some tricks to remember, which we do not always do:

  1. Do not iterate over a collection, checking when you are at element after the first, and add a seperator - just use String.Join("SEPERATOR",IEnumerableCollection). Remember that you can pre-/postpend a char or string, if you wish to wrap each element in whatever you feel like - off course, you can do the same in JS
  2. When trying to use ViewState, it is not enough to enable it in web.config: remember, if it is enabled in webconfig, but disabled on page, you will have no ViewState. Again, if ViewState is disabled on page, but enabled in control, you will have no ViewState - enable on page AND control, to have ViewState on control.

Just a couple of thoughts, might be expanded...



Random thoughts - Google Maps

clock September 21, 2010 05:37 by author CP

Google Maps Bounds

When working with Google Maps, it is very useful to know which part of a map is visible to the user. The reason for this is, that in most situations, it is not relevant to add markers, which is not actually located in the visible area of the map. One of the ways to do this is:

  • Get the bound of the actual map (defined by zoomlevel etc.)
var bounds = this.map.getBounds();

Now we know the bounds of our map - that is, by using the bounds, we can see the 'box', that is our map

  • Define a variable to containe the specific point
var mapLatLng = null;
  • Imagine you have retrieved a collection of Lat/Longs:
var len = results.length;
for (var i = 0; i < len; i++)
{
   var result = results[i];
   mapLatLng=new GLatLng(result.lat, result.lng);

   if(bounds.containsLatLng(mapLatLng))
   {
    //Do what you need to do with the marker
   }
}

The function:

.containsLatLng(LatLng: object)

Tells us, if the specific set on latitude and longitude is within the bounds of our map (by returning a boolean value), and if not we are not going to add them as marker to the map.

Google Maps Markers

If you have a Lat/Long set, you are able to create a marker on your map:

var marker = new GMarker(new google.maps.LatLng(lat, lng));
this.map.addOverlay(marker);

If you wish to show some info regarding your marker:

marker.openInfoWindowHtml(html);

This can of course be hooked up by events:

GEvent.clearListeners(marker);
GEvent.addListener(marker, 'click', this.markerClick.bind(this, marker, html));

So that the info window only appear on a click.

 



About the author

.NET developer, developing Google Maps, Facebook and Twitter consuming applications.

Month List

Page List

    Sign in