stoimen.com/blog

web developing

Archive for August, 2009

JavaScript Date object

The Date object in JS helps you work with dates as it sounds logical. However there are limited number of functions attached to it which you can use. You can check for full Date specification in w3schools : here.

How to get the month name?

Normally when you try to use a date object you can format it with the following code:

var d = new Date();
alert(d.getFullYear());
alert(d.getMonth());
alert(d.getDate());

The problem is that you cannot reference the date object and to get the full name of the month. Something like d.getFullMonth()!

That’s why the easiest way to get the full month name is to make a custom locale array such this one:

var monthLocale = new Array(12);
monthLocale[0] = "January";
monthLocale[1] = "February";
monthLocale[3] = "April";
monthLocale[4] = "May";
monthLocale[5] = "June";
monthLocale[6] = "July";
monthLocale[7] = "August";
monthLocale[8] = "September";
monthLocale[9] = "October";
monthLocale[10] = "November";
monthLocale[11] = "December";

And than you can simply reference the locale with that chuck of code:


and you get the name of the month!

The ocean is blue!

Yeah, that should sound OK, because as we all know the ocean is blue, but here I mean the ocean is blue on the maps of OpenStreetMap.org. This map uses pre-generated tiles with parts of the world map and using a tool such OpenLayers javascript library you can construct a geo map. The problem is that those tiles are always with blue ocean, as you can see on the picture below:

a openstreetmap tile with part of east asia
a openstreetmap tile with part of east asia

Well those are generated, how can I change the ocean color?

There is no way to change it, except you modify the .xml file from which those tiles are generated, but so far I haven’t done it.

Since I need a vector (thematic) map, such as this on http://thematicmapping.org/ with geoJSON formated borders I noticed that one you’ve a vector map, there’s no loading of the tiles and thus – no blue color of the ocean. You can see an example here:

emq26y57vz

  • 0 Comments
  • Filed under: micro tutorial
  • OpenLayers vectors IE bug!

    OpenLayers and OpenStreetMap

    If you’re not familiar with OpenLayers library, in breve this is a JavaScript library which interacts with a tile server such as this of OpenStreetMap.org

    Vectors

    Because it’s JavaScript OpenLayers library it renders different types of vectors when it becomes the case of vectors. It tries the VML way, but as you may know not every browser support it.  Actually everything works fine in every browser, and that’s the good part of OpenLayers, which is one of the best JavaScript organized project I’ve worked with.

    The problem is that if you’ve something in the DOM with z-index over the vector layer IE’s giving problems because as it appears it cannot be rendered.

    The solution is to draw the layer but skip the .addLayer before the vectors should be seen. You than remove the DOM element, which is over the vector layer you set .setVisibility(true) and the layer appears on the stage.

    So far this is the only solution I got, but there may be others.

  • 0 Comments
  • Filed under: javascript
  • Wait for the image!

    This is common task. You’d like to load an image and then show it. With jQuery that is simple enough. Let’s assume this code:

    <img src="image.jpg" />
    <div>displayed after the image is loaded</div>

    This is OK if the div is hidden with jQuery you can show it with adding this code in your javascript:

    <script>
        $('img').load(function() {
            $('div').show();
        });
    </script>