<?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> &#187; mapping</title>
	<atom:link href="http://www.anzaan.com/category/software-development/mapping/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anzaan.com</link>
	<description></description>
	<lastBuildDate>Sat, 26 Jun 2010 03:29:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Displaying Open Street Map (OSM) tiles inside Google Map</title>
		<link>http://www.anzaan.com/2009/05/displaying-open-street-map-osm-tiles-inside-google-map/</link>
		<comments>http://www.anzaan.com/2009/05/displaying-open-street-map-osm-tiles-inside-google-map/#comments</comments>
		<pubDate>Thu, 21 May 2009 00:58:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mapping]]></category>

		<guid isPermaLink="false">http://www.anzaan.com/?p=14</guid>
		<description><![CDATA[I have been developing  vehicle-tracking system at work  for the past 1 year  or so and we use google for mapping.
Their enterprise license isn’t cheap and we didn’t  have  a viable alternative. I looked into OSM and found their coverage of Australia  not quite upto what we needed. We thought google has all  we needed [...]]]></description>
			<content:encoded><![CDATA[<p>I have been developing  vehicle-tracking system at work  for the past 1 year  or so and we use google for mapping.<br />
Their enterprise license isn’t cheap and we didn’t  have  a viable alternative. I looked into OSM and found their coverage of Australia  not quite upto what we needed. We thought google has all  we needed and settled for it.<br />
Few months back  a security company from Fiji showed keen  interest in buying our product as well as acting as our distributor in Fiji.<br />
That’s where the problem began. You see, Google’s coverage of Fiji is next to nothing, no roads, just a few zoom levels and that was it.</p>
<p>Like all good customers, their patience on the two months timeframe i had given them to get Fiji’s map up and running ran out before the deadline  and last week I promised them I’ll show them at least something within a week.  And of course I had no clue how I was going to keep that promise.</p>
<p>I tried my hand on all sorts of things, I tried to configure and run our own map server to spit our tiles for Fiji,  I tried overlaying Fiji’s map data (which the client provided as shapefiles and it only covered a part of Fiji) on google map, I used good-old Firebug to debug OpenGTS’s<br />
tracking website to see how they did their tracking using Open Street Map.</p>
<p>I had two plans.<br />
Plan A: whatever it takes get the fiji’s map to load inside google map so I can use the existing javascript codebase that relies on google’s api.<br />
Plan B: Use OSM for Fiji and google for rest,  and rewrite javascript code and use OpenLayer  javascript  library as the main library to allow users to switch ebtween providers easily.</p>
<p>Since Plan A is less painful, I tried to find ways to accomplish it. And Plan A  indeed turned out to be extremely painless if there’s such a thing.</p>
<p>I won’t go detail out all the things that failed, but I’ll definitely detail out what worked.</p>
<p>So, to all my fellow colleagues, cursing themselves in their little office cubicle, tearing their hair our trying to integrate OSM in google map,<br />
here’s the solution:</p>
<p>We’ll create a new map type and point google to OSM ’s tile provider to get map tiles from OSM instead of fetching them from google’s servers.</p>
<p>Firstly, We’ll create a new GTileLayer for osm.</p>
<pre class="brush: javascript;">

var osmTileLayer= new GTileLayer(new GCopyrightCollection(”&quot;),1,17);
osmLayer.myLayers=’osm’;
osmLayer.myFormat=’image/jpeg’;
</pre>
<p>This is where we define a custom function for fetchng tiles from OSM map server.<br />
This function will be user by google to fetch tiles from OSM everytime there’s request for tiles.</p>
<pre class="brush: javascript;">

osmLayer.getTileUrl=function(a,b,c) {

return ‘http://c.tile.openstreetmap.org/’+b+’/'+a.x+’/'+a.y+’.png’;

}
</pre>
<p>Then we create a map type and add it to our good old google map.</p>
<pre class="brush: javascript;">
var osmLayer=[osmTileLayer];
var OSMMap = new GMapType(osmLayer, G_SATELLITE_MAP.getProjection(), “OSM”, G_SATELLITE_MAP);
map.addMapType(OSMMap );
</pre>
<p>And that’s it !!<br />
That’s all it takes to add Open Street Map as a new map type in google map.</p>
<p>here’s the complete code:<br />
————————————————</p>
<pre class="brush: javascript;">

var osmTileLayer= new GTileLayer(new GCopyrightCollection(”&quot;),1,17);
osmLayer.myLayers=’osm’;
osmLayer.myFormat=’image/jpeg’;
osmLayer.getTileUrl=function(a,b,c) {

return ‘http://c.tile.openstreetmap.org/’+b+’/'+a.x+’/'+a.y+’.png’;

}

var osmLayer=[osmTileLayer];
var OSMMap = new GMapType(osmLayer, G_SATELLITE_MAP.getProjection(), “OSM”, G_SATELLITE_MAP);
map.addMapType(OSMMap );
</pre>
<p>—————————————————–</p>
<p>and here’s the final result:</p>
<p><img class="alignnone size-full wp-image-9" title="s640x4801" src="http://www.anzaan.com/wp-content/uploads/2009/05/s640x4801.png" alt="s640x4801" width="477" height="480" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anzaan.com/2009/05/displaying-open-street-map-osm-tiles-inside-google-map/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
