<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dimuthu's Blog &#187; openlayers</title>
	<atom:link href="http://www.dimuthu.org/catagory/openlayers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 07 Jul 2010 12:42:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>Writing Web Apps with Google, Yahoo and Microsoft Maps</title>
		<link>http://www.dimuthu.org/blog/2008/12/05/writing-web-apps-with-google-yahoo-and-microsoft-maps/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/05/writing-web-apps-with-google-yahoo-and-microsoft-maps/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 17:04:37 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[openlayers]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[virtual earth]]></category>
		<category><![CDATA[web application]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=763</guid>
		<description><![CDATA[Google Maps Google provides a nice API allowing developers to integrate Google Maps to their web applications. For that you first need to create a Google Map API key from here, http://code.google.com/apis/maps/signup.html. It is free and you can create as many amount of keys as needed for all of your web sites. After generaing the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Google Maps</strong></p>
<p>Google provides <a href="http://code.google.com/apis/maps/">a nice API</a> allowing developers to integrate <a href="http://maps.google.com/">Google Maps</a> to their web applications. For that you first need to create a Google Map API key from here, <a href="http://code.google.com/apis/maps/signup.html">http://code.google.com/apis/maps/signup.html</a>. It is free and you can create as many amount of keys as needed for all of your web sites. After generaing the key it will give you a nice piece of sample code. You can use this code to start your work. What you needed to do is include the the Google map API script to your web page and create a GMap2 object. Optionally you can set what should be focused, what controls (navigation, zooming) should be available in the view.</p>
<p>Here is a very simple code I wrote using this API. You can run this code live from <a href="http://test.dimuthu.org/blog/maps/google.html">here</a>.</p>
<pre class="javascript">    &lt;script src=<span style="color: #3366cc;">"http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=false&amp;amp;key=ABQIAAAASLxXDwVRuSoGL8Q-tFgkwBS4YfDDHXLghwcnNbKI3a0b78AiZBS4d4SXNzmv-OUqc8l8T_bziKPHTg"</span>
            type=<span style="color: #3366cc;">"text/javascript"</span>&gt;&lt;/script&gt;
    &lt;script type=<span style="color: #3366cc;">"text/javascript"</span>&gt;

   <span style="font-style: italic; color: #009900;">// replace the latitude, logitude, zoom values for your location</span>
   <span style="font-weight: bold; color: #003366;">var</span> lat = <span style="color: #cc0000;">8</span>;
   <span style="font-weight: bold; color: #003366;">var</span> lon = <span style="color: #cc0000;">80.5</span>;
   <span style="font-weight: bold; color: #003366;">var</span> zoom = <span style="color: #cc0000;">8</span>;

    <span style="font-weight: bold; color: #003366;">function</span> initialize<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
      <span style="font-weight: bold; color: #000066;">if</span> <span style="color: #66cc66;">(</span>GBrowserIsCompatible<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
        <span style="font-weight: bold; color: #003366;">var</span> map = <span style="font-weight: bold; color: #003366;">new</span> GMap2<span style="color: #66cc66;">(</span>document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">"map_canvas"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// setting lat lon</span>
        map.<span style="color: #006600;">setCenter</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">new</span> GLatLng<span style="color: #66cc66;">(</span>lat, lon<span style="color: #66cc66;">)</span>, zoom<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// adding the map controls for navigation</span>
        map.<span style="color: #006600;">addControl</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">new</span> GSmallMapControl<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
      <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span>

    &lt;/script&gt;</pre>
<p><strong>Yahoo Maps</strong></p>
<p>Yahoo provides two different technologies to add a map to a web page. One is just using <a href="http://developer.yahoo.com/maps/ajax/">Javascript with Ajax</a> and the second is using <a href="http://developer.yahoo.com/maps/flash/jsGettingStarted.html">Javascript with Flash</a>. They both are very simple to use. Similar to Google, you have to have your own app id to run yahoo maps. You can register for an appid from <a href="https://developer.yahoo.com/wsregapp/">https://developer.yahoo.com/wsregapp/</a>.</p>
<p>Here is the code you may use to have a Flash map. (<a href="http://test.dimuthu.org/blog/maps/yahoo_map_flash.html">Click here</a> to view the demo. Remember You need flash to view this).</p>
<pre class="javascript">&lt;script type=<span style="color: #3366cc;">"text/javascript"</span> src=<span style="color: #3366cc;">"http://maps.yahooapis.com/v3.5.2/fl/javascript/apiloader.js?appid=CyVSsM_V34GOZUkb9MnakFBTrwVHqfHebJ6LC6nZtoxXMJvbaxczvPh71MXUi_K3"</span>&gt;&lt;/script&gt;
&lt;script type=<span style="color: #3366cc;">"text/javascript"</span>&gt;

<span style="font-style: italic; color: #009900;">// replace the latitude, logitude, zoom values for your location</span>
<span style="font-weight: bold; color: #003366;">var</span> lat = <span style="color: #cc0000;">8</span>;
<span style="font-weight: bold; color: #003366;">var</span> lon = <span style="color: #cc0000;">80.5</span>;
<span style="font-weight: bold; color: #003366;">var</span> zoom = <span style="color: #cc0000;">10</span>;

<span style="font-style: italic; color: #009900;">// Create a latitude/longitude object </span>
<span style="font-weight: bold; color: #003366;">var</span> latlon = <span style="font-weight: bold; color: #003366;">new</span> LatLon<span style="color: #66cc66;">(</span>lat, lon<span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #009900;">// Display the map centered on that location. Add your Yahoo! Application</span>
<span style="font-weight: bold; color: #003366;">var</span> map = <span style="font-weight: bold; color: #003366;">new</span> Map<span style="color: #66cc66;">(</span><span style="color: #3366cc;">"mapContainer"</span>, <span style="color: #3366cc;">"CyVSsM_V34GOZUkb9MnakFBTrwVHqfHebJ6LC6nZtoxXMJvbaxczvPh71MXUi_K3"</span>, latlon, zoom<span style="color: #66cc66;">)</span>; 

<span style="font-style: italic; color: #009900;">// Make the map draggable</span>
map.<span style="color: #006600;">addTool</span><span style="color: #66cc66;">(</span> <span style="font-weight: bold; color: #003366;">new</span> PanTool<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>, <span style="font-weight: bold; color: #003366;">true</span> <span style="color: #66cc66;">)</span>;
&lt;/script&gt;</pre>
<p>Using Ajax + Javascript Yahoo Map API is very similar to its Flash + javascript API.  Here is the same map is viewed with the Ajax map. (<a href="http://test.dimuthu.org/blog/maps/yahoo_map_ajax.html">Click here</a> for the live demo of the following code)</p>
<pre class="javascript">&lt;script type=<span style="color: #3366cc;">"text/javascript"</span>
src=<span style="color: #3366cc;">"http://api.maps.yahoo.com/ajaxymap?v=3.8&amp;appid=CyVSsM_V34GOZUkb9MnakFBTrwVHqfHebJ6LC6nZtoxXMJvbaxczvPh71MXUi_K3"</span>&gt;&lt;/script&gt;
&lt;script type=<span style="color: #3366cc;">"text/javascript"</span>&gt;  

    <span style="font-style: italic; color: #009900;">// replace the latitude, logitude, zoom values for your location</span>
    <span style="font-weight: bold; color: #003366;">var</span> lat = <span style="color: #cc0000;">8</span>;
    <span style="font-weight: bold; color: #003366;">var</span> lon = <span style="color: #cc0000;">80.5</span>;
    <span style="font-weight: bold; color: #003366;">var</span> zoom = <span style="color: #cc0000;">10</span>;

    <span style="font-style: italic; color: #009900;">// geo point from lat and lon</span>
    <span style="font-weight: bold; color: #003366;">var</span> point = <span style="font-weight: bold; color: #003366;">new</span> YGeoPoint<span style="color: #66cc66;">(</span>lat, lon<span style="color: #66cc66;">)</span>;

    <span style="font-style: italic; color: #009900;">// Create a map object  </span>
    <span style="font-weight: bold; color: #003366;">var</span> map = <span style="font-weight: bold; color: #003366;">new</span> YMap<span style="color: #66cc66;">(</span>document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">(</span><span style="color: #3366cc;">'map'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;  

    <span style="font-style: italic; color: #009900;">// Add map type control  </span>
    map.<span style="color: #006600;">addTypeControl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;  

    <span style="font-style: italic; color: #009900;">// Add map zoom (long) control  </span>
    map.<span style="color: #006600;">addZoomLong</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;  

    <span style="font-style: italic; color: #009900;">// Add the Pan Control  </span>
    map.<span style="color: #006600;">addPanControl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;  

    <span style="font-style: italic; color: #009900;">// Set map type to either of: YAHOO_MAP_SAT, YAHOO_MAP_HYB, YAHOO_MAP_REG  </span>
    map.<span style="color: #006600;">setMapType</span><span style="color: #66cc66;">(</span>YAHOO_MAP_SAT<span style="color: #66cc66;">)</span>;  

    <span style="font-style: italic; color: #009900;">// Display the map centered on a geocoded location  </span>
    map.<span style="color: #006600;">drawZoomAndCenter</span><span style="color: #66cc66;">(</span>point, zoom<span style="color: #66cc66;">)</span>;
&lt;/script&gt;</pre>
<p><strong>Microsoft Virtual Earth</strong></p>
<p><a href="http://dev.live.com/virtualearth/">Microsoft Virtual Earth</a> also provides a map API. And it has a really cool <a href="http://dev.live.com/virtualearth/sdk/">interactive map SDK</a>. You can get a nice map with just few lines of javascripts.</p>
<pre class="javascript">      &lt;script type=<span style="color: #3366cc;">"text/javascript"</span> src=<span style="color: #3366cc;">"http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"</span>&gt;&lt;/script&gt;
      &lt;script type=<span style="color: #3366cc;">"text/javascript"</span>&gt;
         <span style="font-weight: bold; color: #003366;">var</span> map = <span style="font-weight: bold; color: #003366;">null</span>;

         <span style="font-style: italic; color: #009900;">// replace the latitude, logitude, zoom values for your location</span>
         <span style="font-weight: bold; color: #003366;">var</span> lat = <span style="color: #cc0000;">8</span>;
         <span style="font-weight: bold; color: #003366;">var</span> lon = <span style="color: #cc0000;">80.5</span>;
         <span style="font-weight: bold; color: #003366;">var</span> zoom = <span style="color: #cc0000;">8</span>;

         <span style="font-weight: bold; color: #003366;">function</span> GetMap<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>
         <span style="color: #66cc66;">{</span>
            map = <span style="font-weight: bold; color: #003366;">new</span> VEMap<span style="color: #66cc66;">(</span><span style="color: #3366cc;">'map'</span><span style="color: #66cc66;">)</span>;
            map.<span style="color: #006600;">LoadMap</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">new</span> VELatLong<span style="color: #66cc66;">(</span>lat, lon<span style="color: #66cc66;">)</span>, zoom, <span style="color: #3366cc;">'r'</span>, <span style="font-weight: bold; color: #003366;">false</span><span style="color: #66cc66;">)</span>;
         <span style="color: #66cc66;">}</span>
      &lt;/script&gt;</pre>
<p><a href="http://test.dimuthu.org/blog/maps/ve.html">Here</a> is how this code run.</p>
<p><strong>All Together with OpenLayers</strong></p>
<p>So now we know how to create web based map applications using each of these providers. But how if you want to create map using all the providers. Actually you can do it with some effort in javascripts. But you don&#8217;t need to.</p>
<p>That is when <a href="http://openlayers.org/">openlayers</a> help. You can add maps from Google, Yahoo, Microsoft or any Map Server as layers in a openlayers map.</p>
<p>See how it is done in the following code. You can view a running instance of this code at <a href="http://test.dimuthu.org/blog/maps/openlayers.html">here</a>.</p>
<pre class="html4strict"><span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- you have to include all the maps provider api script + openlayer script --&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="font-weight: bold; color: #000000;">&lt;script</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=false&amp;amp;key=ABQIAAAASLxXDwVRuSoGL8Q-tFgkwBS4YfDDHXLghwcnNbKI3a0b78AiZBS4d4SXNzmv-OUqc8l8T_bziKPHTg"</span>
            <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span><span style="font-weight: bold; color: #000000;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: #000000;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="font-weight: bold; color: #000000;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span>
        <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"http://api.maps.yahoo.com/ajaxymap?v=3.8&amp;appid=CyVSsM_V34GOZUkb9MnakFBTrwVHqfHebJ6LC6nZtoxXMJvbaxczvPh71MXUi_K3"</span><span style="font-weight: bold; color: #000000;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: #000000;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="font-weight: bold; color: #000000;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"</span><span style="font-weight: bold; color: #000000;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: #000000;">&lt;/script&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="font-weight: bold; color: #000000;">&lt;script</span></a> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"http://www.openlayers.org/api/OpenLayers.js"</span><span style="font-weight: bold; color: #000000;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: #000000;">&lt;/script&gt;</span></span>

&lt;script language=<span style="color: #3366cc;">"javascript"</span>&gt;
    <span style="font-style: italic; color: #009900;">// replace the latitude, logitude, zoom values for your location</span>
    <span style="font-weight: bold; color: #003366;">var</span> lat = <span style="color: #cc0000;">8</span>;
    <span style="font-weight: bold; color: #003366;">var</span> lon = <span style="color: #cc0000;">80.5</span>;
    <span style="font-weight: bold; color: #003366;">var</span> zoom = <span style="color: #cc0000;">8</span>;

    <span style="font-weight: bold; color: #003366;">var</span> map;

    init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    <span style="font-weight: bold; color: #003366;">function</span> init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

        <span style="font-style: italic; color: #009900;">// creating the base map</span>
        map = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Map</span><span style="color: #66cc66;">(</span> <span style="color: #3366cc;">'map'</span> <span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// we will add all the google layers</span>

        gphy = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Layer</span>.<span style="color: #006600;">Google</span><span style="color: #66cc66;">(</span>
            <span style="color: #3366cc;">"Google Physical"</span>,
            <span style="color: #66cc66;">{</span>type: G_PHYSICAL_MAP<span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">)</span>;
        gmap = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Layer</span>.<span style="color: #006600;">Google</span><span style="color: #66cc66;">(</span>
            <span style="color: #3366cc;">"Google Streets"</span>, <span style="font-style: italic; color: #009900;">// the default</span>
            <span style="color: #66cc66;">{</span>numZoomLevels: <span style="color: #cc0000;">20</span><span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">)</span>;
        gsat = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Layer</span>.<span style="color: #006600;">Google</span><span style="color: #66cc66;">(</span>
            <span style="color: #3366cc;">"Google Satellite"</span>,
            <span style="color: #66cc66;">{</span>type: G_SATELLITE_MAP, numZoomLevels: <span style="color: #cc0000;">20</span><span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">)</span>;
        ghyb = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Layer</span>.<span style="color: #006600;">Google</span><span style="color: #66cc66;">(</span>
            <span style="color: #3366cc;">"Google Hybrid"</span>,
            <span style="color: #66cc66;">{</span>type: G_HYBRID_MAP, numZoomLevels: <span style="color: #cc0000;">20</span><span style="color: #66cc66;">}</span>
        <span style="color: #66cc66;">)</span>;

        map.<span style="color: #006600;">addLayers</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">[</span>gphy, gmap, gsat, ghyb<span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// Now we will add the yahoo layer</span>
        yahooLayer = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Layer</span>.<span style="color: #006600;">Yahoo</span><span style="color: #66cc66;">(</span> <span style="color: #3366cc;">"Yahoo"</span><span style="color: #66cc66;">)</span>;
        map.<span style="color: #006600;">addLayer</span><span style="color: #66cc66;">(</span>yahooLayer<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// finally adding the MS virtual earth layer</span>
        velayer = <span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Layer</span>.<span style="color: #006600;">VirtualEarth</span><span style="color: #66cc66;">(</span> <span style="color: #3366cc;">"VE"</span>,
                                <span style="color: #66cc66;">{</span><span style="color: #3366cc;">'type'</span>: VEMapStyle.<span style="color: #006600;">Aerial</span><span style="color: #66cc66;">}</span><span style="color: #66cc66;">)</span>;
        map.<span style="color: #006600;">addLayer</span><span style="color: #66cc66;">(</span>velayer<span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// adding some control</span>
        map.<span style="color: #006600;">setCenter</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">LonLat</span><span style="color: #66cc66;">(</span>lon, lat<span style="color: #66cc66;">)</span>, zoom<span style="color: #66cc66;">)</span>;
        map.<span style="color: #006600;">addControl</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Control</span>.<span style="color: #006600;">MousePosition</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

        <span style="font-style: italic; color: #009900;">// adding the layer switcher</span>
        map.<span style="color: #006600;">addControl</span><span style="color: #66cc66;">(</span><span style="font-weight: bold; color: #003366;">new</span> OpenLayers.<span style="color: #006600;">Control</span>.<span style="color: #006600;">LayerSwitcher</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

    <span style="color: #66cc66;">}</span>

&lt;/script&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/05/writing-web-apps-with-google-yahoo-and-microsoft-maps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a Mashup with Maps and Weather</title>
		<link>http://www.dimuthu.org/blog/2008/12/01/writing-a-mashup-with-maps-and-weather/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/01/writing-a-mashup-with-maps-and-weather/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 16:37:23 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[mashup server]]></category>
		<category><![CDATA[openlayers]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[kml]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[Weather]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=747</guid>
		<description><![CDATA[Few weeks back, I did a screencast on how to consume a web service using WSF/PHP demonstrating an application of US National Digital Weather Forecast Database. In that webservice there are operations like &#8220;GmlLatLonList&#8221; that retrieve a KML for a given longitude and latitude inside USA. I wrote a simple mashup that load this KML [...]]]></description>
			<content:encoded><![CDATA[<p>Few weeks back, I did a screencast on how to consume a web service using WSF/PHP demonstrating an application of <a href="http://www.nws.noaa.gov/forecasts/xml/">US National Digital Weather Forecast Database</a>. In that webservice there are operations like &#8220;<strong>GmlLatLonList&#8221;</strong> that retrieve a KML for a given longitude and latitude inside USA. I wrote a <a href="http://mooshup.com/services/Dimuthu/weatherMap/">simple mashup</a> that load this KML from the web service and set it as a layer in a map which is created using <a href="http://openlayers.org/">openlayers</a>.</p>
<p>There I use the <a href="http://wso2.org/projects/mashup">WSO2 Mashup Server</a> to create the stub to invoke the weather forecasting web service. This stub can be easily used to invoke the service from a javascript in a HTML page.</p>
<p>You can visit the mashup from the <a href="http://www.mooshup.com">Mashup Server community site mooshup.com</a> from here, <a href="http://mooshup.com/services/Dimuthu/weatherMap/">http://mooshup.com/services/Dimuthu/weatherMap/</a>.</p>
<p>Here are the steps I used to create this mashup.</p>
<ol>
<li>First I wrote a javascript to wrap the web service. It has a function that can be used as a stub to invoke the web service operation just as a javascript function call. Here is the <a href="http://mooshup.com/services/Dimuthu/weatherMap?source&amp;content-type=text/plain">source of the javascript </a> I wrote. It wraps the &#8220;GmlLatLonList&#8221; service operation in the &#8220;fetchWeatherInfo&#8221; function. I gave this javascript service the name &#8220;weatherMap&#8221;.
<pre class="javascript"><span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">serviceName</span> = <span style="color: #3366cc;">"weatherMap"</span>;
<span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">scope</span> = <span style="color: #3366cc;">"application"</span>;
<span style="font-weight: bold; color: #000066;">this</span>.<span style="color: #006600;">documentation</span> = <span style="color: #3366cc;">"Visit the weather information from just a mouse click"</span>;

fetchWeatherInfo.<span style="color: #006600;">documentation</span> = <span style="color: #3366cc;">"Retrieve the weather information for the given inputs"</span> ;
fetchWeatherInfo.<span style="color: #006600;">inputTypes</span> = <span style="color: #66cc66;">{</span><span style="color: #3366cc;">"listLatLon"</span> : <span style="color: #3366cc;">"string"</span>,
                               <span style="color: #3366cc;">"startTime"</span> : <span style="color: #3366cc;">"string"</span>,
                               <span style="color: #3366cc;">"endTime"</span> : <span style="color: #3366cc;">"string"</span><span style="color: #66cc66;">}</span>;
fetchWeatherInfo.<span style="color: #006600;">outputType</span> = <span style="color: #3366cc;">"xml"</span>;
<span style="font-weight: bold; color: #003366;">function</span> fetchWeatherInfo<span style="color: #66cc66;">(</span>listLatLon, startTime, endTime<span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>

    <span style="font-weight: bold; color: #003366;">var</span> url = <span style="color: #3366cc;">"http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php"</span>;

    <span style="font-style: italic; color: #009900;">// setting up the the WSRequest</span>
    <span style="font-weight: bold; color: #003366;">var</span> request = <span style="font-weight: bold; color: #003366;">new</span> WSRequest<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

    <span style="font-weight: bold; color: #003366;">var</span> options = <span style="font-weight: bold; color: #003366;">new</span> Array<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    options.<span style="color: #006600;">useSOAP</span> = <span style="color: #cc0000;">1.1</span>;
    options.<span style="color: #006600;">useWSA</span> = <span style="font-weight: bold; color: #003366;">false</span>;

    <span style="font-style: italic; color: #009900;">// do the request</span>
    request.<span style="color: #000066;">open</span><span style="color: #66cc66;">(</span>options, url, <span style="font-weight: bold; color: #003366;">false</span><span style="color: #66cc66;">)</span>;

    <span style="font-weight: bold; color: #003366;">var</span> reqXml =
        &lt;ns:GmlTimeSeries xmlns:ns=<span style="color: #3366cc;">"uri:DWMLgen"</span>&gt;
            &lt;listLatLon&gt;<span style="color: #66cc66;">{</span>listLatLon<span style="color: #66cc66;">}</span>&lt;/listLatLon&gt;
            &lt;startTime&gt;<span style="color: #66cc66;">{</span>startTime<span style="color: #66cc66;">}</span>&lt;/startTime&gt;
            &lt;endTime&gt;<span style="color: #66cc66;">{</span>endTime<span style="color: #66cc66;">}</span>&lt;/endTime&gt;
            &lt;compType&gt;Between&lt;/compType&gt;
            &lt;featureType&gt;Ndfd_KmlPoint&lt;/featureType&gt;
            &lt;propertyName&gt;&lt;/propertyName&gt;
        &lt;/ns:GmlTimeSeries&gt;

    request.<span style="color: #006600;">send</span><span style="color: #66cc66;">(</span>reqXml<span style="color: #66cc66;">)</span>;

    <span style="font-weight: bold; color: #000066;">return</span> request.<span style="color: #006600;">responseXML</span>;
<span style="color: #66cc66;">}</span></pre>
</li>
<li>Deployed it in the <a href="http://wso2.org/projects/mashup">WSO2 Mashup server</a>. I downloaded and setup the mashup server locally. Then I just needed to put the script inside &#8220;scripts/dimuthu&#8221; directory. There is <a href="http://www.mooshup.com">an online instance of mashup server called mooshup.com</a> in which I later deployed my service. After deployed it in the mashup, it will generate the javascript stub for that service. You can view the generated stub by adding a &#8220;?stub&#8221; to the mashup url. Here is the stub for the &#8220;weatherMap&#8221; mashup deployed in the mooshup server, <a href="http://mooshup.com/services/Dimuthu/weatherMap?stub">http://mooshup.com/services/Dimuthu/weatherMap?stub</a>. Similarly you can view the try out page for the service from, <a href="http://mooshup.com/services/Dimuthu/weatherMap?tryit">http://mooshup.com/services/Dimuthu/weatherMap?tryit</a></li>
<li>Wrote an HTML interface for the service. I used the openlayers javascript library to load google map in to my page. And added a custom control that handles the click. In the click handler, I just call the stub and get the response KML string back using a code similar to this.
<pre class="html4strict"><span style="color: #009900;"><span style="font-style: italic; color: #808080;">&lt;!-- include the script for the stub --&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="font-weight: bold; color: #000000;">&lt;script</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"text/javascript"</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"../weatherMap?stub"</span><span style="font-weight: bold; color: #000000;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: #000000;">&lt;/script&gt;</span></span>

<span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="font-weight: bold; color: #000000;">&lt;script</span></a> <span style="color: #000066;">language</span>=<span style="color: #ff0000;">"javascript"</span><span style="font-weight: bold; color: #000000;">&gt;</span></span>
...

<span style="font-style: italic; color: #009900;">// the code inside the handler of the click control</span>

   <span style="font-style: italic; color: #009900;">// preparing the stub call</span>
   weatherMap.<span style="color: #006600;">fetchWeatherInfo</span>.<span style="color: #000066;">onError</span> = handleError;
   weatherMap.<span style="color: #006600;">fetchWeatherInfo</span>.<span style="color: #006600;">callback</span> = <span style="font-weight: bold; color: #003366;">function</span><span style="color: #66cc66;">(</span>response<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
       <span style="font-weight: bold; color: #000066;">if</span><span style="color: #66cc66;">(</span>response &amp;&amp; response.<span style="color: #006600;">firstChild</span>.<span style="color: #006600;">firstChild</span>.<span style="color: #006600;">nodeValue</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

           <span style="font-style: italic; color: #009900;">// handling kml document</span>
           <span style="font-weight: bold; color: #003366;">var</span> kmlDoc = response.<span style="color: #006600;">firstChild</span>.<span style="color: #006600;">firstChild</span>.<span style="color: #006600;">nodeValue</span>;

           <span style="font-style: italic; color: #009900;">// the code to add the kml layer to the map and render it</span>
           ....
         <span style="color: #66cc66;">}</span>
    <span style="color: #66cc66;">}</span>;
   <span style="font-style: italic; color: #009900;">// preparing the startTime, endTIme, lat, lon values</span>
   ...

   <span style="font-style: italic; color: #009900;">// doing the request call</span>
   weatherMap.<span style="color: #006600;">fetchWeatherInfo</span><span style="color: #66cc66;">(</span>lat + <span style="color: #3366cc;">","</span> + lon, startTime, endTime<span style="color: #66cc66;">)</span>;

<span style="color: #009900;"><span style="font-weight: bold; color: #000000;">&lt;/script&gt;</span></span></pre>
<p>The KML style icon will be shown in the map after adding the KML layer to the map. And we can render the KML style details which in this case contain the weather forecast data in detail in some other place easily.</li>
</ol>
<p>So this way you can create a mashup using openlayers and the data retrieved from different web services. You can find another mashup that shows the twitter updates on a map in real time at here, <a href="http://mooshup.com/services/tyrell/TwitterMap/">http://mooshup.com/services/tyrell/TwitterMap/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/01/writing-a-mashup-with-maps-and-weather/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
