<?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>tanomsak.com &#187; Uncategorized</title>
	<atom:link href="http://www.tanomsak.com/index.php/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tanomsak.com</link>
	<description>Random Thoughts on Random Things by Tanomsak</description>
	<lastBuildDate>Sun, 23 May 2010 08:39:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>การใช้รูปภาพแทนปุ่มซูมเข้าออก (Custom control)</title>
		<link>http://www.tanomsak.com/index.php/2009/07/google-maps-custom-control/</link>
		<comments>http://www.tanomsak.com/index.php/2009/07/google-maps-custom-control/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 10:49:04 +0000</pubDate>
		<dc:creator>tanomsak</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tanomsak]]></category>

		<guid isPermaLink="false">http://www.tanomsak.com/?p=295</guid>
		<description><![CDATA[zickr_url='http://www.tanomsak.com/index.php/2009/07/google-maps-custom-control/' ถ้าใครเคยเข้าไปเวป ddproperty.com จะเห็นว่าปุ่มซูมเข้าซูมออกจะไม่เหมือนแบบปกติของ Google Maps และมีปุ่มย่อขยายแผนที่เพิ่มขึ้นมาด้วย การทำแบบนี้เค้าเรียกว่า Custom Control ครับ คราวนี้เราจะพูดถึงเรื่องการสร้าง Control ของ Google Maps ให้เป็นแบบเฉพาะของเวปเรากันครับ ทำความรู้จักกับ Control ใน Google Maps ก่อนอื่นมาทำความรู้จักกับ Control ใน Google Maps API กันก่อน ในตัว Google Maps API มี Control มาตราฐานมาให้เราใช้อยู่หลายอย่างครับ GLargeMapControl &#8211; เป็น Control ที่มีครบทั้งซูมเข้าออก,เลื่อนแผนที่ซ้ายขวา และ Slider GSmallMapControl &#8211; จะมีแค่ซูมเข้าออก,เลื่อนแผนที่ซ้ายขวา GSmallZoomControl &#8211; มีแต่ ซูมเข้าออกเล็กๆ GScaleControl &#8211; scale บอกขนาดแผนที่ GLargeMapControl3D [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="width: 100%; margin-bottom: 30px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.tanomsak.com%2Findex.php%2F2009%2F07%2Fgoogle-maps-custom-control%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.tanomsak.com%2Findex.php%2F2009%2F07%2Fgoogle-maps-custom-control%2F&amp;source=tanomsak&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<div style="FLOAT: right; MARGIN-LEFT: 20px"><div class="zickrbutton"><script>zickr_url='http://www.tanomsak.com/index.php/2009/07/google-maps-custom-control/'</script><script language="javascript" src="http://api.zickr.com/button.js"></script></div></div>
<p>ถ้าใครเคยเข้าไปเวป <a title="ขายบ้าน บ้านมือสอง ขายคอนโด" href="http://www.ddproperty.com" target="_blank">ddproperty.com</a> จะเห็นว่าปุ่มซูมเข้าซูมออกจะไม่เหมือนแบบปกติของ Google Maps และมีปุ่มย่อขยายแผนที่เพิ่มขึ้นมาด้วย การทำแบบนี้เค้าเรียกว่า Custom Control ครับ</p>
<p style="TEXT-ALIGN: center"><img src="http://www.tanomsak.com/wp-content/uploads/2009/07/ddproperty_maps_crop.jpg" alt="ddproperty-maps-crop.jpg" width="488" height="304" /></p>
<p>คราวนี้เราจะพูดถึงเรื่องการสร้าง Control ของ Google Maps ให้เป็นแบบเฉพาะของเวปเรากันครับ</p>
<p><span id="more-295"></span></p>
<h3>ทำความรู้จักกับ Control ใน Google Maps</h3>
<p>ก่อนอื่นมาทำความรู้จักกับ Control ใน Google Maps API กันก่อน ในตัว Google Maps API มี Control มาตราฐานมาให้เราใช้อยู่หลายอย่างครับ</p>
<ul>
<li>GLargeMapControl &#8211; เป็น Control ที่มีครบทั้งซูมเข้าออก,เลื่อนแผนที่ซ้ายขวา และ Slider</li>
<li>GSmallMapControl &#8211; จะมีแค่ซูมเข้าออก,เลื่อนแผนที่ซ้ายขวา</li>
<li>GSmallZoomControl &#8211; มีแต่ ซูมเข้าออกเล็กๆ</li>
<li>GScaleControl &#8211; scale บอกขนาดแผนที่</li>
<li>GLargeMapControl3D &#8211; เหมือน GLargeMapControl แต่ว่าดูสวยกว่า <img src='http://www.tanomsak.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>GSmallZoomControl3D &#8211; เหมือน GSmallZoomControl แต่ว่าดูสวยกว่า</li>
<li>GMapTypeControl &#8211; เอาไว้เลือกประเภทแผนที่ ว่าจะเป็นแผนที่ธรรมดา หรือภาพถ่ายดาวเทียม</li>
<li>GHierarchicalMapTypeControl &#8211; Control แบบที่มี Drop down ให้เลือกได้</li>
<li>GOverviewMapControl &#8211; แผนที่ขนาดเล็กที่ปกติอยู่ทางขวาล่าง</li>
<li>GNavLabelControl &#8211; Label แสดง &#8220;ที่อยู่&#8221; ณ ตำแหน่งปัจจุบัน</li>
</ul>
<p>ปกติเราเรียกใช้งาน Control พวกนี้โดยคำสั่งแบบนี้ครับ</p>
<p><code>map.addControl(new GLargeMapControl());</code></p>
<h3>มาสร้าง Control ของเรากันครับ</h3>
<p>ขอเริ่มจาก source code ละกันนะครับ</p>
<pre class="brush: jscript;">
// ก่อนอื่นสร้าง function myZoomControl ขึ้นมาก่อน
function myZoomControl() {
}
// ทำ &quot;subclass&quot; GControl โ้้ดยการกำหนดให้ prototype object เป็น Instance ของ GControl
myZoomControl.prototype = new GControl();

myZoomControl.prototype.initialize = function(map) {
  // เริ่มต้นก็สร้าง div ว่างๆมาหนึ่งอัน เอาไ้ว้เป็น container
  var container = document.createElement(&quot;div&quot;);

  container.style.width = &quot;37px&quot;;
  container.style.height = '100px';

  // สร้าง div อีกอันเอาไว้เป็นปุ่ม ZoomIn
  var zoomInDiv = document.createElement(&quot;div&quot;);
  // กำหนด style ให้กับปุ่ม -&gt; ไป call function ด้านล่าง
  this.setButtonStyle_(zoomInDiv,&quot;zoonin.png&quot;);
  // เพิ่ม div ของปุ่ม ZoomIn ไว้ใส่ container
  container.appendChild(zoomInDiv);

  // กำหนดหน้าที่ให้กับปุ่ม
  GEvent.addDomListener(zoomInDiv, &quot;click&quot;, function() {
    map.zoomIn();
  });

  // สร้าง div อีกอันเอาไว้เป็นปุ่ม ZoomOut
  var zoomOutDiv = document.createElement(&quot;div&quot;);
  // กำหนด style ให้กับปุ่ม -&gt; ไป call function ด้านล่าง
  this.setButtonStyle_(zoomOutDiv,&quot;zoomout.png&quot;);
  // เพิ่ม div ของปุ่ม ZoomIn ไว้ใส่ container
  container.appendChild(zoomOutDiv);

  // กำหนดหน้าที่ให้กับปุ่ม
  GEvent.addDomListener(zoomOutDiv, &quot;click&quot;, function() {
    map.zoomOut();
  });

  // นำ div container ใส่เข้าไปในแผนที่
  map.getContainer().appendChild(container);
  return container;
}

myZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

myZoomControl.prototype.setButtonStyle_ = function(button,button_pic) {

    button.style.backgroundImage = &quot;url(/&quot;+button_pic+&quot;)&quot;;
    button.style.width = &quot;31px&quot;;
    button.style.height = &quot;31px&quot;;
    button.style.margin = &quot;0px 0px 3px 3px&quot;;
    //styleFloat  for IE
    if (navigator.appName.indexOf(&quot;Netscape&quot;) != -1) {
       button.style.cssFloat = &quot;left&quot;;
    }
    else {
       button.style.styleFloat = &quot;left&quot;;
    }
    button.style.cursor = &quot;pointer&quot;;
}

function load() {
    if (GBrowserIsCompatible()) {
       var map = new GMap2(document.getElementById(&quot;map&quot;));

       // เรียกใช้ Custom Control ที่สร้าง
       map.addControl(new myZoomControl());
       map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    }
}
</pre>
<p><a href="http://www.tanomsak.com/tutorial-5.htm" target="_blank">ดูตัวอย่างกันครับว่าออกเป็นแบบไหน</a></p>
<p>การสร้าง Custom Control จริงแล้วไม่ยากเลยครับ ส่วนที่สำคัญๆมีดังนี้ครับ</p>
<p>บรรทัดที่ 1-5 กำหนด prototype ของ Custom Control ที่จะสร้าง ให้เป็น instance ของ GControl ขั้นตอนนี้้เป็นการทำ &#8220;subclass&#8221; จาก GControl แต่ว่า Javascript ไม่มีการ inherit Class เหมือนพวก OOP แต่มีการทำ prototype แทนครับ ไม่ต้องงงครับ  copy ไปเลย <img src='http://www.tanomsak.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>มี function ที่สำคัญ 2 อันคือ initialize บรรทัดที่ 7-41 กับ getDefaultPosition บรรทัด 43-45 ห้ามตกหล่นไม่งั้นไม่ work</p>
<p>โดย initialize ทำหน้าที่กำหนดหน้าตาของ Custom Control และ กำหนด Action เวลากดปุ่มต่าง มาดูกันทีละบรรทัดครับ</p>
<p>บรรทัด 9-11 เริ่มต้นด้วยการสร้าง div เปล่าๆขึ้นมาและกำหนดขนาดให้มัน div อันนี้จะเรียกว่า container ครับ โดยเราจะสร้างปุ่มไว้ข้างใน แล้วก็ append ทั้ง container เข้าไปใน Google maps ของเราตอนท้าย คอยดูนะครับ</p>
<p>บรรทัด 15-17 เริ่มสร้างปุ่ม ZoomIn โดยการสร้าง div อีกอันนึง แล้วก็ กำหนด style ให้มันโดยเรียก function setButtonStyle_<span> ถ้าตามไปดูข้างในก็จะเห็นว่าเป็นการกำหนด background ให้เป็นรูปปุ่ม และก็กำหนดขนาดนั้นเอง</span></p>
<p><span>บรรทัด 19 ใส่ div ZoomIn เข้าไปใน Container</span></p>
<p><span>บรรทัด 22-24 เป็นการตั้ง Listener ให้ซูมเข้าเวลามรการ &#8220;click&#8221; ที่ div ZoomIn ของเรา</span></p>
<p><span>จากนั้น บรรทัด 26-36 ก็ทำซ้ำสำหรับปุ่ม ZoomOut</span></p>
<p><span>บรรทัด 39 ก็ append container ที่เราใส่ปุ่ม ZoomIn/ZoomOut แล้วเข้าไปในแผนที่</span></p>
<p><span>ส่วน </span>getDefaultPosition ทำหน้าที่กำหนดตำแหน่งว่า Control ของเราจะอยู่ตรงไหนของแผนที่ครับ</p>
<p>สุดท้ายก็เรียกใช้ myZoomControl ก็เป็นอันเรียบร้อย</p>
<p>Update:</p>
<p>คุณ @<a href="http://twitter.com/iampz" target="_blank">iampz</a> แนะนำให้ใช้ id/class กำหนด style แทน ผมทดลองแล้วตามแล้ว<a href="http://www.tanomsak.com/tutorial-5-1.htm " target="_blank">ลองดูตัวอย่าง</a>นะครับ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tanomsak.com/index.php/2009/07/google-maps-custom-control/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>ไปบ้านเด็กพิการตาบอดซ้ำซ้อนที่รามอินทรา</title>
		<link>http://www.tanomsak.com/index.php/2009/06/%e0%b8%9a%e0%b9%89%e0%b8%b2%e0%b8%99%e0%b9%80%e0%b8%94%e0%b9%87%e0%b8%81%e0%b8%9e%e0%b8%b4%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b2%e0%b8%9a%e0%b8%ad%e0%b8%94/</link>
		<comments>http://www.tanomsak.com/index.php/2009/06/%e0%b8%9a%e0%b9%89%e0%b8%b2%e0%b8%99%e0%b9%80%e0%b8%94%e0%b9%87%e0%b8%81%e0%b8%9e%e0%b8%b4%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b2%e0%b8%9a%e0%b8%ad%e0%b8%94/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 04:18:19 +0000</pubDate>
		<dc:creator>tanomsak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tanomsak.com/?p=254</guid>
		<description><![CDATA[วันนี้โำพสบล๊อกใหม่ที่ blog.ddproperty.com หลังจากทิ้งไปนานไม่ได้ update เลยครับ ตั้งแต่เริ่มเวป www.ddproperty.com @pangporn มีความคิดว่าอยากแบ่งเงินที่ได้จากเวปไซด์ไปบริกาคและทำบุญ วันก่อนได้มีโอกาสแวะไปที่บ้านเด็กพิการตาบอดซ้ำซ้อนรามอินทรา เคยไปมาครั้งนึงนานแล้วยังไม่ใหญ่โตขนาดนี้ ตอนนี้มีการสร้างตึกใหม่โหญ่โตมาก (จนอดคิดไม่ได้ว่า ใหญ่ไปเปล่าครับ) พอเข้าไปข้างในก็เย็นสบายดี ตอนที่พวกผมเข้าไปมีคนมาบริจาคอยู่ประมาณ 3 กลุ่ม และก็มีคนทยอยมาเรื่อยๆไม่ขาดสาย น่าดีใจจริงๆ มีของขายด้วยนะครับ พวกของที่ระลึก และเสื้อน่ารักๆ พอได้ทำบุญแล้วก็สบายใจดีครับ ขอแบ่งความสุข ความสบายใจให้ผู้ใช้งาน และสนับสนุนเวปไซด์ทุกๆท่านนะครับ ที่ช่วยให้เวปเติมโตมาถึงทุกวันนี้]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="width: 100%; margin-bottom: 30px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.tanomsak.com%2Findex.php%2F2009%2F06%2F%25e0%25b8%259a%25e0%25b9%2589%25e0%25b8%25b2%25e0%25b8%2599%25e0%25b9%2580%25e0%25b8%2594%25e0%25b9%2587%25e0%25b8%2581%25e0%25b8%259e%25e0%25b8%25b4%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%2595%25e0%25b8%25b2%25e0%25b8%259a%25e0%25b8%25ad%25e0%25b8%2594%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.tanomsak.com%2Findex.php%2F2009%2F06%2F%25e0%25b8%259a%25e0%25b9%2589%25e0%25b8%25b2%25e0%25b8%2599%25e0%25b9%2580%25e0%25b8%2594%25e0%25b9%2587%25e0%25b8%2581%25e0%25b8%259e%25e0%25b8%25b4%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%2595%25e0%25b8%25b2%25e0%25b8%259a%25e0%25b8%25ad%25e0%25b8%2594%2F&amp;source=tanomsak&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><em>วันนี้โำพสบล๊อกใหม่ที่ blog.ddproperty.com หลังจากทิ้งไปนานไม่ได้ update เลยครับ</em></p>
<p>ตั้งแต่เริ่มเวป <a title="ขายบ้าน บ้านมือสอง บ้านเดี่ยว คอนโด" href="http://www.ddproperty.com" target="_blank">www.ddproperty.com</a> @<a href="http://www.twitter.com/pangporn" target="_blank">pangporn</a> มีความคิดว่าอยากแบ่งเงินที่ได้จากเวปไซด์ไปบริกาคและทำบุญ วันก่อนได้มีโอกาสแวะไปที่บ้านเด็กพิการตาบอดซ้ำซ้อนรามอินทรา เคยไปมาครั้งนึงนานแล้วยังไม่ใหญ่โตขนาดนี้ ตอนนี้มีการสร้างตึกใหม่โหญ่โตมาก (จนอดคิดไม่ได้ว่า ใหญ่ไปเปล่าครับ)</p>
<p><img src="http://www.tanomsak.com/wp-content/uploads/2009/06/Image082_resize.jpg" alt="Image082_resize.jpg" width="480" height="360" /><br />
<span id="more-254"></span></p>
<p>พอเข้าไปข้างในก็เย็นสบายดี ตอนที่พวกผมเข้าไปมีคนมาบริจาคอยู่ประมาณ 3 กลุ่ม และก็มีคนทยอยมาเรื่อยๆไม่ขาดสาย น่าดีใจจริงๆ<br />
<img src="http://www.tanomsak.com/wp-content/uploads/2009/06/Image084_resize.jpg" alt="Image084_resize.jpg" width="480" height="360" /></p>
<p>มีของขายด้วยนะครับ พวกของที่ระลึก และเสื้อน่ารักๆ<br />
<img src="http://www.tanomsak.com/wp-content/uploads/2009/06/Image087_resize.jpg" alt="Image087_resize.jpg" width="360" height="480" /></p>
<p>พอได้ทำบุญแล้วก็สบายใจดีครับ ขอแบ่งความสุข ความสบายใจให้ผู้ใช้งาน และสนับสนุนเวปไซด์ทุกๆท่านนะครับ ที่ช่วยให้เวปเติมโตมาถึงทุกวันนี้</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tanomsak.com/index.php/2009/06/%e0%b8%9a%e0%b9%89%e0%b8%b2%e0%b8%99%e0%b9%80%e0%b8%94%e0%b9%87%e0%b8%81%e0%b8%9e%e0%b8%b4%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b2%e0%b8%9a%e0%b8%ad%e0%b8%94/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
