<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Spatial Horizons</title>
	
	<link>http://spatialhorizons.com</link>
	<description>Exploring Geographic Technologies</description>
	<lastBuildDate>Sat, 10 Mar 2012 01:43:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SpatialHorizons" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="spatialhorizons" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">SpatialHorizons</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>The Rise of OpenStreetMap</title>
		<link>http://spatialhorizons.com/2012/03/10/the-rise-of-openstreetmap/</link>
		<comments>http://spatialhorizons.com/2012/03/10/the-rise-of-openstreetmap/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 01:43:11 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[OpenStreetMap]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/?p=362</guid>
		<description><![CDATA[The last several months have seen a number of high-profile companies switch from using Google Maps to OpenStreetMap (OSM). Welcome, Apple Foursquare is joining the OpenStreetMap movement Why (and how) we&#8217;ve switched away from Google Maps The power of free data is incredibly compelling for these companies but it should also resonate with every person [...]]]></description>
			<content:encoded><![CDATA[<p>The last several months have seen a number of high-profile companies switch from using Google Maps to <a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap (OSM)</a>.
<ul>
<li><a target="_blank" href="http://blog.osmfoundation.org/2012/03/08/welcome-apple/">Welcome, Apple</a></li>
<li><a target="_blank" href="http://blog.foursquare.com/2012/02/29/foursquare-is-joining-the-openstreetmap-movement-say-hi-to-pretty-new-maps/">Foursquare is joining the OpenStreetMap movement</a></li>
<li><a target="_blank" href="http://blog.nestoria.co.uk/why-and-how-weve-switched-away-from-google-ma">Why (and how) we&#8217;ve switched away from Google Maps</a></li>
</ul>
<p>The <a href="http://www.digitaltrends.com/mobile/why-are-companies-defecting-from-google-maps/#" target="_blank">power of free data</a> is incredibly compelling for these companies but it should also resonate with every person who loves maps.</p>
<p>If you haven&#8217;t joined OSM yet, you should! Read over their <a href="http://wiki.openstreetmap.org/wiki/Beginners%27_guide" target="_blank">beginner&#8217;s guide</a> and learn how to improve the roads and points of interest in your area.</p>
<p>We will take a look at some of the ways you can use OSM data and maps in future posts.</p>
<p><iframe width="475" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.openstreetmap.org/export/embed.html?bbox=-127.8,14.8,-66.6,57.6&amp;layer=mapnik" style="border: 1px solid black"></iframe><br /><small><a href="http://www.openstreetmap.org/?lat=36.2&amp;lon=-97.2&amp;zoom=3&amp;layers=M">View Larger Map</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2012/03/10/the-rise-of-openstreetmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TileMill Tutorial – Installation</title>
		<link>http://spatialhorizons.com/2011/05/06/tilemill-tutorial-installation/</link>
		<comments>http://spatialhorizons.com/2011/05/06/tilemill-tutorial-installation/#comments</comments>
		<pubDate>Fri, 06 May 2011 20:19:01 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[TileMill]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/?p=236</guid>
		<description><![CDATA[Update: TileMill version 0.4 has been released and offers a simple one-click installation. Parts of this post are now out-of-date and can be ignored. TileMill is a new map development environment that is free for anyone to use. In their own words: &#8220;TileMill is a modern map design studio powered by open source technology.&#8221; TileMill [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: <a href="http://tilemill.com/pages/index.html" target="_blank">TileMill version 0.4 has been released</a> and offers a simple one-click installation.  Parts of this post are now out-of-date and can be ignored.</strong></p>
<p><a href="http://tilemill.com/">TileMill</a> is a new map development environment that is free for anyone to use. In their own words:</p>
<p class="shquote">&#8220;TileMill is a modern map design studio powered by open source technology.&#8221;</p>
<p>TileMill allows you to take raw GIS data (shapefiles and rasters) and generate high-quality maps. In addition, it allows exporting maps to a set of map tiles which can be used on a website or transferred to a mobile device (there currently is an <a href="http://mapbox.com/#/ipad">iPad app</a> available).</p>
<p>Unlike many of our other tutorials, this probably isn&#8217;t for beginners. You need to have some background in GIS, HTML/CSS and have access to a Mac or Linux computer.  Don&#8217;t let this scare you off though as TileMill may just be the future of map design and distribution.</p>
<p><span id="more-236"></span></p>
<h3>Installation Setup</h3>
<p>The <a href="http://tilemill.com/">TileMill website</a> provides the basic instructions for installing TileMill on Mac or Linux. In our testing, we successfully installed it on an older MacBook running Snow Leopard.</p>
<p>TileMill require several applications to be installed first. <a href="http://developer.apple.com/technologies/tools/whats-new.html">Xcode</a> version 4 was first installed from the Mac App Store. Next, <a href="http://dbsgeo.com/downloads/#mapnik-2.0.0">Mapnik</a> for Snow Leopard was downloaded and installed.</p>
<p>TileMill&#8217;s distribution package was then downloaded from the website as a zip file. After extracting the files, the folder was renamed to just <em>tilemill</em> and copied into the applications folder using the Finder.</p>
<h3>Installing from the Terminal</h3>
<p>TileMill needs to be built from Mac&#8217;s Terminal. We launched Terminal and navigated to the TileMill folder.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">cd /Applications/tilemill</pre></div></div>

<p>Continuing with their instructions on the website, we executed the build command:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">./ndistro</pre></div></div>

<p>The building process runs through a series of steps.  In our case, there were 69 steps it slowly progressed through. At step 50, it seemed to hang and even show an error message.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">50</span>/<span style="color: #cc66cc;">69</span><span style="color: #00AA00;">&#93;</span> libv8<span style="color: #6666ff;">.a</span><span style="color: #00AA00;">:</span> deps/v8/SConstruct -<span style="color: #00AA00;">&gt;</span> build/<span style="color: #993333;">default</span>/libv8<span style="color: #6666ff;">.a</span>
scons<span style="color: #00AA00;">:</span> warning<span style="color: #00AA00;">:</span> Ignoring missing SConscript <span style="color: #ff0000;">'obj/test/release/SConscript'</span>
File <span style="color: #ff0000;">&quot;/Applications/tilemill/src/node-0.2.6/deps/v8/SConstruct&quot;</span><span style="color: #00AA00;">,</span> line <span style="color: #cc66cc;">1097</span><span style="color: #00AA00;">,</span> in BuildSpecific</pre></div></div>

<p>But eventually the process continued and finished. It appears this is <a href="https://github.com/mapbox/tilestream/issues/11">known issue</a> according to their support site.  The important thing to note is several times it appeared to hang but don&#8217;t lose faith!</p>
<h3>Running TileMill</h3>
<p>TileMill needs to be started from the Terminal by running this command.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">cd /applications/tilemill/tilemill.js</pre></div></div>

<p>A message should appear informing you it is ready to use.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">Started TileMill on port <span style="color: #cc66cc;">8889</span></pre></div></div>

<p>TileMill is a unique in that it is a local, web-based application so you need to open a web browser to access it. Enter the following in the address bar:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">http<span style="color: #00AA00;">:</span>//localhost<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">8889</span></pre></div></div>

<p>TileMill should appear and several demo projects will already be visible.</p>
<p><a href="http://spatialhorizons.com/wp-content/uploads/2011/05/tilemill-projects.jpg"><img src="http://spatialhorizons.com/wp-content/uploads/2011/05/tilemill-projects.jpg" alt="" title="TileMill Projects Window" width="500" height="323" class="alignnone size-full wp-image-348" /></a></p>
<h3>Explore TileMill</h3>
<p>Browse the existing projects to get a sense of how TileMill works.  Remember the software is still really new so don&#8217;t be surprised if you run into a crash or freeze. In our testing, reloading the browser usually resolved any issues.</p>
<p>Check out this tutorial video on how you can use TileMill. We will explore it in more detail in a future post.</p>
<p><iframe src="http://player.vimeo.com/video/20006926?title=0&amp;byline=0&amp;portrait=0" width="400" height="250" frameborder="0"></iframe>
<p><a href="http://vimeo.com/20006926">TileMill: Open Source Map Design</a> from <a href="http://vimeo.com/developmentseed">Development Seed</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2011/05/06/tilemill-tutorial-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenLayers Tutorial – Place a Marker</title>
		<link>http://spatialhorizons.com/2011/03/27/openlayers-place-a-marker/</link>
		<comments>http://spatialhorizons.com/2011/03/27/openlayers-place-a-marker/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 14:50:45 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[OpenLayers]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/?p=282</guid>
		<description><![CDATA[This post continues our series of OpenLayers tutorials. If you are new to OpenLayers, review our basic map setup tutorial before continuing. A common task of any mapping application is to place a marker at a specified location. OpenLayers provides several options for doing this but we will focus on using a Marker. Our simple [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo">This post continues our series of OpenLayers tutorials. If you are new to OpenLayers, review our <a href="http://spatialhorizons.com/2011/03/16/openlayers-basic-map-setup/">basic map setup tutorial</a> before continuing.</p>
<p>A common task of any mapping application is to place a marker at a specified location. OpenLayers provides several options for doing this but we will focus on using a <a href="http://dev.openlayers.org/docs/files/OpenLayers/Layer/Markers-js.html" target="_blank">Marker</a>.</p>
<p>Our simple example will allow a user to plot the location of various US cities on an OpenLayers map.  In order to accomplish this, we need to know the longitude (X) and latitude (Y) of each city.  We will use <a href="http://www.realestate3d.com/gps/uslatlongdegmin.htm" target="_blank">this list</a> of city coordinates to create a HTML &lt;select&gt; box.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jumpTo&quot;</span> <span style="color: #000066;">onchange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jumpTo();&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;NA&quot;</span>&gt;</span>=== Select a City ===<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-84.42,33.65&quot;</span>&gt;</span>Atlanta<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-104.87,39.75&quot;</span>&gt;</span>Denver<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>  
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-95.35,29.97&quot;</span>&gt;</span>Houston<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-81.32,28.43&quot;</span>&gt;</span>Orlando<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span> 
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-121.50,38.52&quot;</span>&gt;</span>Sacramento<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-95.62,39.07&quot;</span>&gt;</span>Topeka<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span> 
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></div></div>

<p><span id="more-282"></span><br />
Each &lt;option&gt; uses the value attribute to store the city&#8217;s coordinates. Note that the longitude coordinate is listed first and uses a negative number because we are in the western hemisphere.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/02/latlon_map.jpg" /></p>
<p>We also added a javascript function call <em>jumpTo</em> that is called when the selected value is changed.  This is where we will use OpenLayers to place a marker on the map.</p>
<p>Our OpenLayers map will be a single HTML page that is based on our <a href="http://spatialhorizons.com/2011/03/16/openlayers-basic-map-setup/">basic map setup tutorial</a>.  We next need to add a variable to track the markers.  This will be placed in the &lt;head&gt; along with some basic OpenLayers initialization code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #003366; font-weight: bold;">var</span> map<span style="color: #339933;">,</span> baseLayer<span style="color: #339933;">,</span> markers<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'map'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
        baseLayer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">WMS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;OpenLayers VMAP0&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://labs.metacarta.com/wms/vmap0&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>layers<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;basic&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>baseLayer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">LonLat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">98</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">39</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        markers <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">Markers</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Cities&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   			
        map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>markers<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Within the <em>init()</em> function, the markers layer is added to the map.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">markers <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">Markers</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Cities&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   			
map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>markers<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Below that we need to add the <em>jumpTo()</em> function to place a marker on the selected city.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> jumpTo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    markers.<span style="color: #660066;">clearMarkers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                
    <span style="color: #003366; font-weight: bold;">var</span> selectBox <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'jumpTo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        		
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>selectBox.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;NA&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> parse <span style="color: #339933;">=</span> selectBox.<span style="color: #660066;">value</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> location <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">LonLat</span><span style="color: #009900;">&#40;</span>parse<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>parse<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 			
    <span style="color: #003366; font-weight: bold;">var</span> size <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Size</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">21</span><span style="color: #339933;">,</span><span style="color: #CC0000;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Pixel</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>size.<span style="color: #660066;">w</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span>size.<span style="color: #660066;">h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> icon <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Icon</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://www.openlayers.org/dev/img/marker.png'</span><span style="color: #339933;">,</span>size<span style="color: #339933;">,</span>offset<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    markers.<span style="color: #660066;">addMarker</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span>location<span style="color: #339933;">,</span>icon.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>               			
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The code first accesses the select box and makes sure the user selected a city.  It next collects the coordinates and parses them based on the comma in between.  It then creates a <a href="http://dev.openlayers.org/docs/files/OpenLayers/BaseTypes/LonLat-js.html">LonLat</a> object based on the parsed coordinates.</p>
<p>The next three lines define the marker&#8217;s icon and ensures that the marker point is placed exactly on the location (this code comes from the <a href="http://openlayers.org/dev/examples/markers.html">OpenLayers marker example</a>).  OpenLayers has markers in several colors which you can view <a href="http://www.openlayers.org/dev/img/" target="_blank">here</a>.  All of them are 21&#215;25 pixels in size but if you were to use your own image, be sure to change the <em>size</em> definition in the code.</p>
<p>The entire HTML code should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>OpenLayers Tutorial - Place a Marker<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://openlayers.org/api/OpenLayers.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
        var map, baseLayer, markers;
        function init(){
            map = new OpenLayers.Map('map');            
            baseLayer = new OpenLayers.Layer.WMS(&quot;OpenLayers VMAP0&quot;, &quot;http://labs.metacarta.com/wms/vmap0&quot;, {layers:&quot;basic&quot;});
            map.addLayer(baseLayer);
            map.setCenter(new OpenLayers.LonLat(-98, 39),3); 
   	    markers = new OpenLayers.Layer.Markers(&quot;Cities&quot;);   			
            map.addLayer(markers);            
        }
&nbsp;
        function jumpTo()
        {
            markers.clearMarkers();        	
            var selectBox = document.getElementById('jumpTo');        		
   	    if (selectBox.value == &quot;NA&quot;) return;
   	    var parse = selectBox.value.split(',');
   	    var location = new OpenLayers.LonLat(parse[0],parse[1]); 			
   	    var size = new OpenLayers.Size(21,25);
            var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
            var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);   
            markers.addMarker(new OpenLayers.Marker(location,icon.clone()));               			 
          }
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
    @media screen
    {
        #map{width: 500px; height:300px; border: 2px solid black;}
    }
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">onload</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;init()&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>OpenLayers Tutorial - Place a Marker<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;map&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>Place a marker at this city: <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jumpTo&quot;</span> <span style="color: #000066;">onchange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jumpTo();&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;NA&quot;</span>&gt;</span>=== Select a City ===<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-84.42,33.65&quot;</span>&gt;</span>Atlanta<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-104.87,39.75&quot;</span>&gt;</span>Denver<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>  
    	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-95.35,29.97&quot;</span>&gt;</span>Houston<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-81.32,28.43&quot;</span>&gt;</span>Orlando<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span> 
    	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-121.50,38.52&quot;</span>&gt;</span>Sacramento<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;-95.62,39.07&quot;</span>&gt;</span>Topeka<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span> 
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>Opening the web page should produce something like this:</p>
<div id="map"></div>
<p>
    <label>Place a marker at this city: </label><br />
<select id="jumpTo" onchange="jumpTo();" style="width:150px;">
<option value="NA">=== Select a City ===</option>
<option value="-84.42,33.65">Atlanta</option>
<option value="-104.87,39.75">Denver</option>
<option value="-95.35,29.97">Houston</option>
<option value="-81.32,28.43">Orlando</option>
<option value="-121.50,38.52">Sacramento</option>
<option value="-95.62,39.07">Topeka</option>
</select>
<h3><a href="http://spatialhorizons.com/examples/openlayers/place-a-marker.html">Click here to view the final result in a new window</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2011/03/27/openlayers-place-a-marker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenLayers Tutorial – Basic Map Setup</title>
		<link>http://spatialhorizons.com/2011/03/16/openlayers-basic-map-setup/</link>
		<comments>http://spatialhorizons.com/2011/03/16/openlayers-basic-map-setup/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 12:11:16 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[OpenLayers]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/?p=233</guid>
		<description><![CDATA[OpenLayers is a open source, javascript framework for generating dynamic maps. It&#8217;s incredibly powerful once you understand how to use it. But before we can tackle the more advanced applications, we need to lay some groundwork. This tutorial provides the basic code (HTML, CSS and JavaScript) needed to understand how to embed an OpenLayers map [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://openlayers.org/" target="_blank">OpenLayers</a> is a open source, javascript framework for generating dynamic maps. It&#8217;s incredibly powerful once you understand how to use it. But before we can tackle the more advanced applications, we need to lay some groundwork. This tutorial provides the basic code (HTML, CSS and JavaScript) needed to understand how to embed an OpenLayers map in a website.</p>
<h3>HTML Page Creation</h3>
<p>Create a new html file using your favorite text editor.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>OpenLayers Tutorial - Basic Map Setup<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
    @media screen{}
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>OpenLayers Tutorial - Basic Map Setup<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>  
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p><span id="more-233"></span></p>
<h3>Reference OpenLayers Javascript</h3>
<p>OpenLayers is provided in a single JavaScript file that you can reference remotely or download to a local machine. Let&#8217;s keep it simple and just reference the freely available version online.  Add this line inside the &lt;head&gt; portion of the file.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://openlayers.org/api/OpenLayers.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<h3>Initialize OpenLayers</h3>
<p>Inside &lt;head&gt;, we need to define several variables and create an initializing function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #003366; font-weight: bold;">var</span> map<span style="color: #339933;">,</span> baseLayer<span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'map'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
            baseLayer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">WMS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;OpenLayers WMS&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://labs.metacarta.com/wms/vmap0&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>layers<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;basic&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>baseLayer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
            map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">LonLat</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         
        <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Inside the init function, the map will be created first. Then a WMS layer is defined using an existing map server. See <a href="http://en.wikipedia.org/wiki/Web_Map_Service">Wikipedia</a> for more information on WMS. In short, the WMS server in this example provides <a href="http://spatialhorizons.com/2007/07/15/map-tiles-1-introduction/">map tiles</a> of the world upon request. Fortunately, OpenLayers does this behind the scenes and no additional coding is needed. Lastly, the layer is added to the map and the map is centered on zero degrees longitude and latitude.</p>
<p>Call the initialize function from the onload event of the &lt;body&gt;.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">onload</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;init()&quot;</span>&gt;</span></pre></div></div>

<h3>Define the Map</h3>
<p>The next step is to add a &lt;div&gt; inside the &lt;body&gt; to serve as the container for the map. Most web programmers are already familiar with the broad uses of &lt;div&gt;&#8217;s and in the case of OpenLayers, it makes a perfect &#8220;map&#8221; representative.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;map&quot;</span> &gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>The size of the map can now be defined using CSS.  In the &lt;head&gt; portion, add some variation of the following style.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"> &lt;style<span style="color: #00AA00;">&gt;</span>
    <span style="color: #a1a100;">@media screen</span>
    <span style="color: #00AA00;">&#123;</span>
        <span style="color: #cc00cc;">#map</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">250px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
    <span style="color: #00AA00;">&#125;</span>
 &lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

<h3>Full Source Code</h3>
<p>Your final HTML page should look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>OpenLayers Tutorial - Basic Map Setup<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://openlayers.org/api/OpenLayers.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
        var map, baseLayer;
        function init(){
            map = new OpenLayers.Map('map');            
            baseLayer = new OpenLayers.Layer.WMS(&quot;OpenLayers WMS&quot;, &quot;http://labs.metacarta.com/wms/vmap0&quot;, {layers:&quot;basic&quot;});
            map.addLayer(baseLayer);
            map.setCenter(new OpenLayers.LonLat(0,0),1);             
        }
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
    @media screen
    {
        #map{width: 500px; height:250px; border: 2px solid black;}
    }
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">onload</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;init()&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>OpenLayers Tutorial - Basic Map Setup<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;map&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<h3>Working Demo</h3>
<p>Open the file in a web browser and the map should look like this:</p>
<div id="map"></div>
<p><strong><a href="http://spatialhorizons.com/examples/openlayers/basic-map-setup.html" target="_blank">Click here to view the final result in a new window</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2011/03/16/openlayers-basic-map-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Horizons in 2011</title>
		<link>http://spatialhorizons.com/2011/03/09/new-horizons-in-2011/</link>
		<comments>http://spatialhorizons.com/2011/03/09/new-horizons-in-2011/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 03:03:46 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Site News]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/?p=157</guid>
		<description><![CDATA[SpatialHorizons.com was started in 2006 to explore the world of geographic information systems (GIS) and application development. The focus then was on desktop applications (mainly Windows-based) and how to use free and open source GIS tools to make cool applications. Flash forward to 2011 where much has changed in GIS and technology. New software, tools [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://spatialhorizons.com">SpatialHorizons.com</a> was started in 2006 to explore the world of geographic information systems (GIS) and application development. The focus then was on desktop applications (mainly Windows-based) and how to use free and open source GIS tools to make cool applications.</p>
<p>Flash forward to 2011 where much has changed in GIS and technology. New software, tools and data sources are emerging to dramatically change how maps and geographic information are used. A new set of horizons are ready to be explored.  So SpatialHorizons.com is alive again with some great new tutorials lined up. Stay Tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2011/03/09/new-horizons-in-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenLayers Tutorial – Add MapServer Data</title>
		<link>http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/</link>
		<comments>http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 15:08:51 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[OpenLayers]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/</guid>
		<description><![CDATA[Update: This post was originally written in 2007. Please visit our newer OpenLayers Tutorials for more up-to-date information. This post introduces OpenLayers as a easy way to embed dynamic maps in a web page. First-time visitors are encouraged to read our previous posts on setting up MapServer and CGI MapServer for background information. OpenLayers is [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo"><strong>Update:</strong> This post was originally written in 2007. Please visit our newer <a href="http://spatialhorizons.com/openlayers-tutorials/">OpenLayers Tutorials</a> for more up-to-date information.</p>
<p></p>
<p>This post introduces <a href="http://www.openlayers.org/">OpenLayers</a> as a easy way to embed dynamic maps in a web page. First-time visitors are encouraged to read our previous posts on <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">setting up MapServer</a> and <a href="http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/">CGI MapServer</a> for background information.</p>
<p>OpenLayers is a javascript library for creating maps on a web page. In their own words,</p>
<p class="shquote">OpenLayers is a pure JavaScript library for displaying map data in most modern web browsers, with no server-side dependencies. OpenLayers implements a (still-developing) JavaScript API for building rich web-based geographic applications, similar to the Google Maps and MSN Virtual Earth APIs, with one important difference &#8212; OpenLayers is Free Software, developed for and by the Open Source software community. &#8211; <a href="http://www.openlayers.org/">http://www.openlayers.org/</a></p>
<p>Setting up OpenLayers is incredibly easy if you want to display data from other existing sources on the web. See their <a href="http://www.openlayers.org/QuickTutorial/">Quick Tutorial</a> page for lots of sample HTML showing how to add a basic map in a web page.  In this tutorial, we will focus on how to create a map that uses our own data from MapServer.<br />
<span id="more-62"></span><br />
<strong>Tutorial Requirements</strong></p>
<p>Before beginning, you should already have MapServer setup on your computer. See our <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">previous post</a> to complete this task using the <a href="http://www.maptools.org/ms4w/">MS4W package</a>. Additionally, we will use GIS data and a MapServer mapfile from our <a href="http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/">World Map sample dataset</a>.</p>
<p><strong>Download a Web Page from OpenLayers.org</strong></p>
<p>OpenLayers.org has a great <a href="http://openlayers.org/presentations/mappingyourdata/">screencast tutorial </a> showing how to setup and use OpenLayers. Accompanying the tutorial is a <a href="http://trac.openlayers.org/wiki/MappingYourData">wiki page</a> describing the steps covered in the video.  At the bottom of this page is a link to download an HTML document named lite.html that contains a good starting point for our tutorial.</p>
<p>Go ahead and download the file (<a href="http://trac.openlayers.org/attachment/wiki/MappingYourData/lite.html">direct link here</a>) to your desktop and open it in your favorite text editor. On line 10, note the reference to OpenLayers javascript file:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://openlayers.org/dev/lib/OpenLayers.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p><strong>Update:</strong> You can now reference OpenLayers using this location:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://openlayers.org/api/OpenLayers.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Further down, lines 13 through 20 contain the all the javascript code necessary to embed a MapServer map in the web page:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> map<span style="color: #339933;">,</span> layer<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'map'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   layer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">MapServer</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;OpenLayers WMS&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #3366CC;">&quot;http://labs.metacarta.com/wms/vmap0&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>layers<span style="color: #339933;">:</span> <span style="color: #3366CC;">'basic'</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>layer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   map.<span style="color: #660066;">zoomToMaxExtent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp;</p>
<p>In fact, without changing anything, you could open the web page in a browser and it will work fine because the data is coming from a remote server. The controls in the upper-left corner can be used to navigate around the map.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/openlayers_default.jpg" alt="&lt;br /&gt; OpenLayers" /></p>
<p><strong>Customizing the Javascript</strong></p>
<p>In order for the web page to display our own MapServer data, several changes need to be made to the Javascript in HTML file.</p>
<p>On line 17, the layer is initialized using the <a href="http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/MapServer-js.html">OpenLayers.Layer.MapServer</a> class. Several parameters are required for the layer to work correctly. In the default example, the layer is named OpenLayers WMS (<a href="http://en.wikipedia.org/wiki/Web_map_server">Web Map Server</a>) and the MapServer location is http://labs.metacarta.com/wms/vmap0. The third parameter is informing the server to request the &#8220;basic&#8221; layer.</p>
<p>For our demonstration, we need to change the three parameters. First we will change the name to World Map. Next, we need to change the location to point to MapServer running on our local machine. Remembering our <a href="http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/">last post</a> on CGI MapServer, we already know that the path is <strong>http://localhost/cgi-bin/mapserv.exe</strong>. And finally, instead of requesting a layer name, we can just provide a file path to a mapfile. The final result looks like this:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> map<span style="color: #339933;">,</span> layer<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'map'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    layer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OpenLayers.<span style="color: #660066;">Layer</span>.<span style="color: #660066;">MapServer</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;World Map&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #3366CC;">&quot;http://localhost/cgi-bin/mapserv.exe&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>map<span style="color: #339933;">:</span> <span style="color: #3366CC;">'C:/world_mapfile.map'</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    map.<span style="color: #660066;">addLayer</span><span style="color: #009900;">&#40;</span>layer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    map.<span style="color: #660066;">zoomToMaxExtent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp;</p>
<p>Save the file and open lite.html in a web browser. The map should now display your data described in the mapfile.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/openlayers_map1.jpg" alt="OpenLayers Map" /></p>
<p><strong>More to Come</strong></p>
<p>OpenLayers offers a wide range of functionality that can be added our simple example.  For a list of examples, see <a href="http://trac.openlayers.org/wiki/UserRecipes">here</a>.</p>
<p>Also, visit our new <a href="http://spatialhorizons.com/openlayers-tutorials/">OpenLayers tutorials</a> for more information.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/12/16/openlayers-1-10-minute-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MapServer (3) – CGI MapServer</title>
		<link>http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/</link>
		<comments>http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 15:15:44 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Mapserver]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/</guid>
		<description><![CDATA[This post is the third in a series on using MapServer. First-time visitors are encouraged to read part 1 to learn how to download and install MapServer on their computer. Additionally, the data layers used in this tutorial are available to download in this post. We&#8217;ve already introduced MapServer and showed how to create a [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo">This post is the third in a series on using <a href="http://mapserver.gis.umn.edu/">MapServer</a>. First-time visitors are encouraged to read <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">part 1</a> to learn how to download and install MapServer on their computer. Additionally, the data layers used in this tutorial are available to download in this <a href="http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/">post</a>.</p>
<p>We&#8217;ve already <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">introduced MapServer</a> and <a href="http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/">showed how to create a mapfile</a> using <a href="http://spatialhorizons.com/faqs#gis">GIS</a> data.  We will now introduce MapServer&#8217;s <a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI</a> functionality as a way to generate a map image. Later we will build on what we&#8217;ve learned to create a map using <a href="http://www.openlayers.org/">OpenLayers</a>, a web mapping interface.</p>
<p><strong>Introducing Mapserv.exe</strong></p>
<p>At the heart of MapServer is a single file referred to as &#8220;mapserv&#8221;. With the <a href="http://www.maptools.org/ms4w/">MS4W package</a>, it is a single executable found at <strong>C:\ms4w\Apache\cgi-bin\mapserv.exe</strong>. This file is the map production engine that uses a mapfile to generate a map image. </p>
<p>Mapserv.exe is usually accessed internally by MapServer-based packages such as <a href="http://ka-map.maptools.org/">ka-map</a> or <a href="http://spatialhorizons.com/2007/05/26/mapscript-demo-1/">Mapscript</a>. But it can also be called directly from a web browser as long as some required parameters are included.<br />
<span id="more-140"></span><br />
<strong>Mapping from the Web Browser Address Bar</strong></p>
<p>In order to demonstrate Mapserv.exe, we already need to have some data and a mapfile ready to use.  We will be using the data and mapfile from our <a href="http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/">World Map dataset</a>.</p>
<p>Open a web browser and enter the following: <strong>http://localhost/cgi-bin/mapserv.exe</strong>. If MapServer is correctly configured, you should see the following warning message:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_noinfo.jpg" alt="CGI MapServer" /></p>
<p>This means mapserv.exe is working correctly so we can next tell it that we want to draw a map. Add <strong>?mode=map</strong> to the address so the full address is <strong>http://localhost/cgi-bin/mapserv.exe?mode=map</strong>. Pressing enter again returns another message:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_nomap.jpg" alt="CGI MapServer" / ></p>
<p>This is expected because we have not provided a mapfile to display. The next variable to add is named &#8220;map&#8221; and it&#8217;s value is the file path to our mapfile. For example, it could be: <strong>http://localhost/cgi-bin/mapserv.exe?mode=map&#038;map=C:\world_mapfile.map</strong>.  If a valid mapfile is entered the browser will generate an image such as this:</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_map1.jpg" alt="CGI MapServer Map" /></p>
<p>A full list of CGI MapServer parameters can be found <a href="http://mapserver.gis.umn.edu/docs/reference/cgi/referencemanual-all-pages">here</a>.  For example, to generate an image of a specific map extent, the MAPEXT parameter can be used.  In our example, we added MAPEXT -20 -20 20 20 in the browser to get an address like this: <strong>http://localhost/cgi-bin/mapserv.exe?mode=map&#038; <br /> map=C:\James\GIS\Data\World\world_mapfile.map&#038;mapext=-20 -20 20 20</strong>. The image returned reflects the new extent.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_map2.jpg" alt="CGI MapServer Map" /></p>
<p><strong>Conclusion</strong></p>
<p>Understanding how MapServer uses mapserv.exe to generate images will become more useful in our next post where we will setup a basic web mapping site using <a href="http://www.openlayers.org/">OpenLayers</a> that will need to directly access the CGI functionality of MapServer.</p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample Dataset – World Map</title>
		<link>http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/</link>
		<comments>http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 14:59:32 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[GIS Data]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/</guid>
		<description><![CDATA[A number of our posts have covered downloading and using GIS data but it should be more beneficial to readers if a single post contained all the instructions needed to acquire the data layers in each dataset. Our first such dataset, named &#8220;World Map&#8221;, has already been introduced but will be discussed in more depth [...]]]></description>
			<content:encoded><![CDATA[<p>A number of our posts have covered downloading and using GIS data but it should be more beneficial to readers if a single post contained all the instructions needed to acquire the data layers in each dataset. Our first such dataset, named &#8220;World Map&#8221;, has already been introduced but will be discussed in more depth here for the sake of new readers.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/mapservercgi_map1.jpg" alt="CGI MapServer Map" /><br />
<span id="more-147"></span></p>
<p><strong>Dataset Details</strong></p>
<ul>
<li>Number of data layers: 2</li>
<li>Map Projection: Geographic (see <a href="http://en.wikipedia.org/wiki/Plate_carr%C3%A9e_projection">Equirectangular projection</a>)
<li>Map Units: Decimal degrees</li>
<li>Map Extent(min x, min y, max x, max y): -180 -90 180 90</li>
</ul>
<p><strong>Layer 1: Countries Shapefile</strong></p>
<p>The first layer in this dataset is a polygon <a href="http://spatialhorizons.com/faqs#shapefile">shapefile</a> containing world countries.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/countries_shapefile.jpg" alt="Countries Shapefile" /></p>
<p>Source: <a href="http://www.cipotato.org/diva/data/MoreData.htm">http://www.cipotato.org/diva/data/MoreData.htm</a><br />
Direct download link: <a href="http://www.cipotato.org/diva/data/misc/world_adm0.zip">http://www.cipotato.org/diva/data/misc/world_adm0.zip</a></p>
<p>For more on using this shapefile, see our posts on <a href="http://spatialhorizons.com/2007/09/23/using-qgis-3-more-layer-symbology/">using QGIS</a>.</p>
<p><strong>Layer 2: World Raster</strong></p>
<p>The second data layer is a raster image of the entire world. The original image was very large but we downloaded it and resized to 600 x 300 pixels. Additionally, we had to create a world file to ensure it would spatially align correctly with our countries shapefile (see <a href="http://spatialhorizons.com/2007/09/26/using-qgis-4-raster-images/">this post</a> for more instructions).</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/12/world_raster.jpg" alt="World Raster" /></p>
<p>Source: <a href="http://commons.wikimedia.org/wiki/World_map">http://commons.wikimedia.org/wiki/World_map</a><br />
Direct link to full-size image (8 MB):<a href="http://upload.wikimedia.org/wikipedia/commons/c/cf/WorldMap-A_non-Frame.png"> http://upload.wikimedia.org/wikipedia/commons/c/cf/WorldMap-A_non-Frame.png</a><br />
Resized Image: <a href="http://www.spatialhorizons.com/downloads/world_raster.tif">http://www.spatialhorizons.com/downloads/world_raster.tif</a><br />
World File: <a href="http://www.spatialhorizons.com/downloads/world_raster.tfw">http://www.spatialhorizons.com/downloads/world_raster.tfw</a></p>
<p><strong>Mapfile Creation</strong></p>
<p>The World Map dataset has been used for several of our projects involving MapServer.  Since MapServer requires a configuration file called a mapfile, one was generated using QGIS in <a href="http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/">this post</a>.  Some minor modifications were made later on so the final version can be downloaded <a href="http://www.spatialhorizons.com/downloads/world_mapfile.map">here</a>.</p>
<p>In the mapfile, the file paths to the data layers should be changed though to reflect your directory structure.</p>
<p>
<pre code="csharp"> LAYER
    NAME 'world_raster'
    TYPE RASTER
    DATA 'C:\\Data\\World\\world_raster.tif'
  ...</pre>
</p>
<p>
<pre code="csharp">LAYER
    NAME 'world_adm0'
    TYPE POLYGON
    DATA 'C:\\Data\\World\\world_adm0.shp'
  ...</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/12/09/sample-dataset-world-map/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using MapServer (2) – Generating Map Tiles</title>
		<link>http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/</link>
		<comments>http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 23:44:06 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Map Tiles]]></category>
		<category><![CDATA[Mapserver]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/</guid>
		<description><![CDATA[This post is the second in a series on using MapServer. First-time visitors are encouraged to read part 1 which details how to download, setup, and create a web mapping site using MapServer. Additionally, the topic of map tiles has already been introduced in a previous series. Once the MapServer for Windows (MS4W) package with [...]]]></description>
			<content:encoded><![CDATA[<p class="moreinfo">This post is the second in a series on using <a href="http://mapserver.gis.umn.edu/">MapServer</a>. First-time visitors are encouraged to read <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">part 1</a> which details how to download, setup, and create a web mapping site using MapServer. Additionally, the topic of map tiles has already been introduced in a <a href="http://spatialhorizons.com/category/map-tiles/">previous series</a>.</p>
<p>Once the <a href="http://www.maptools.org/ms4w/">MapServer for Windows (MS4W)</a> package with <a href="http://ka-map.maptools.org/">ka-Map</a> is installed on your local machine, some new mapping functionality becomes available. One area that interests us is the ability to automatically generate a set of map tiles.</p>
<p><strong>ka-Map Configuration</strong></p>
<p>The first step in creating a set of map tiles is to configure ka-Map to point to a valid MapServer mapfile (see <a href="http://spatialhorizons.com/2007/10/06/using-qgis-5-export-to-mapserver/">here</a> for more on a mapfile). Navigate to this directory: <strong>C:\ms4w\apps\ka-map-1.0\include</strong> and open the file named <strong>config.php</strong> in any text editor.</p>
<p>This configuration file contains several parameters which you should be familiar with before creating our map tiles. We won&#8217;t change any of their values yet but it is important to understand what they do. First, on lines 73 and 74, the pixel size of each tile to be generated is defined:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">$tileWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">256</span><span style="color: #008000;">;</span>
$tileHeight <span style="color: #008000;">=</span> <span style="color: #FF0000;">256</span><span style="color: #008000;">;</span></pre></div></div>

<p>&nbsp;</p>
<p>Lines 106 through 110 define the most important parameters:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">$aszGMap <span style="color: #008000;">=</span> array <span style="color: #008000;">&#40;</span>
         <span style="color: #666666;">'title'</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #666666;">'GMap 75'</span>,
         <span style="color: #666666;">'path'</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #666666;">'../../gmap/htdocs/gmap75.map'</span>,
         <span style="color: #666666;">'scales'</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span> array<span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">40000000</span>, <span style="color: #FF0000;">25000000</span>, <span style="color: #FF0000;">12000000</span>,
                                 <span style="color: #FF0000;">7500000</span>, <span style="color: #FF0000;">3000000</span>, <span style="color: #FF0000;">1000000</span> <span style="color: #008000;">&#41;</span>,
         <span style="color: #666666;">'format'</span> <span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #666666;">'PNG'</span>
 <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>&nbsp;</p>
<p><span id="more-134"></span><br />
By default, ka-Map is setup to use the GMap application that we downloaded and setup in the <a href="http://spatialhorizons.com/2007/05/19/mapserver-1-10-minute-tutorial/">first post</a>. So the values for the title, path, and scales reflect that.</p>
<p>The path variable is relative based on the location of config.php (config.php is in C:\ms4w\apps\ka-map-1.0\include and the gmap75.map file is in C:\ms4w\apps\gmap\htdocs).</p>
<p>The scales array contains all the map scales at which the tiles will be generated. Determining which scales and how many scale levels is completely configurable based on the user&#8217;s preference. For now we will leave them as-is.</p>
<p>Lastly, the output image format is defined as PNG.</p>
<p><strong>Precache.php</strong></p>
<p>ka-Map is a web-based interface for viewing MapServer-based maps using map tiles. Normally, ka-Map generates only the necessary map tiles needed to show in the browser&#8217;s window. But there is a separate file, named precache.php, that also comes with the ka-Map that does generate all the map tiles for every scale of the map.</p>
<p>Navigate to the following directory: <strong>C:\ms4w\apps\ka-map-1.0\htdocs</strong>. Scroll through the list of files to find the file <strong>precache.php</strong>. The good news is this file does not need to be modified in any way. It relies solely on the config.php settings described above to determine what mapfile and map scales to use when creating the map tiles.</p>
<p><strong>Running Precache.php</strong></p>
<p>Readers are encouraged to first read over <a href="http://ka-map.ominiverdi.org/wiki/index.php/Pre-caching_system" target="_blank">this article</a> in the ka-Map wiki about precache.php. You don&#8217;t have to understand everything it discusses &#8211; just glance over the parameters needed to run precache.php.</p>
<p>Running precache.php requires returning to the world of DOS prompts and command line. It is important to follow these steps exactly as listed otherwise it may not work correctly.</p>
<ol>
<li>Open a command prompt. On Windows, go to Start&#8230;Run and type <strong>cmd</strong>.</li>
<li>Type <strong>cd C:\ms4w\apps\ka-map-1.0\htdocs</strong> to go to the directory with precache.php.</li>
<li>Since precache.php is a PHP file, we need to run it using the PHP executable (php.exe). Fortunately this is already included with the MS4W package. Type <strong>C:\ms4w\Apache\cgi-bin\php.exe precache.php</strong> in the command prompt. We left out the required parameters on purpose here so you can see the usage instructions:</li>
</ol>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/11/precache_usage.jpg" alt="Precache.php Usage" /></p>
<p>We won&#8217;t need to use -f, -m, or -s options but we do need to add the tile_url parameter. This is the web address (hence &#8220;_url&#8221;) to ka-Map&#8217;s <strong>tile.php</strong> file. Even though the file is stored locally at <strong>C:\ms4w\apps\ka-map-1.0\htdocs\tile.php</strong>, we need to enter a valid URL. The usage instructions suggest using http://localhost/ka-map/htdocs/tile.php but that didn&#8217;t work for us. Instead we will use <strong>http://localhost/kamap/tile.php</strong>.</p>
<ol>
<li>Type <strong>C:\ms4w\Apache\cgi-bin\php.exe precache.php http://localhost/kamap/tile.php</strong>. Press enter the map tiles will be generated.</li>
</ol>
<p>This process will take several minutes as all the tiles at each of the scale levels are generated. The command prompt will display information on each scale level. This information on meta tiles and tile counts is informative but not necessary to understand right now. In short, precache.php requests larger tiles (&#8220;meta tiles&#8221;) and then cuts them up to arrive at the final set of tiles.</p>
<p><strong>Viewing the Map Tile Cache</strong></p>
<p>Navigate to <strong>C:\ms4w\tmp\ms_tmp\kacache\gmap</strong>. Inside this folder should be a folder named for each scale level in the map. Inside each scale level folder our folders named __base__ and then a sub-folder named def. This is where the tile images can be found.</p>
<p>Because ka-Map tiles are generally only used internally and not designed for end-user interaction, there is a potentially confusing way to name tiles and tile folders. Anytime a folder or file contains the letters &#8220;t&#8221; or &#8220;l&#8221;, it means top or left. So instead of naming tiles with X/Ys or Row/Columns, ka-Map uses the &#8220;Left/Top&#8221; naming convention.</p>
<p>It also names each tile based on it&#8217;s pixel location and tile size. Since the config.php was set to output 256&#215;256 tiles, each tile image will include top and left numbers based on multiples of 256. So if one tile is named t0l0.png, the adjacent tiles on each side would be named t0l256.png and t0l-256.png. Glance through the folders and view some of the individual tiles to get a sense of the tiling structure.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/11/kamap_tile_t-256l0.png" alt="kaMap Tile Example" /></p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/11/kamap_tile_t-256l-256.png" alt="kaMap Tile Example" /></p>
<p><strong>What&#8217;s the Benefit?</strong></p>
<p>Traditional usage of precache.php is for improving the load times on a web mapping site by caching all the tiles ahead of time.  For our objectives, having a complete set of pre-compiled map tiles means we can create a desktop application without including a GIS code library or GIS data. It also eliminates the extra processing time and would make deploying our applications easier. Instead of including extra DLLs and shapefiles, we simply need to include a folder of map tiles to run the application.</p>
<p><strong>Conclusion</strong></p>
<p>This post is probably the most technical topic we&#8217;ve covered to date. For now, simply understanding how to generate map tiles using precache.php is a what&#8217;s important. In the next post we will discuss the map tiles in some more depth, including how we can use them in other applications.</p>
<p><a title="Using MapServer (3) – CGI MapServer" href="http://spatialhorizons.com/2007/12/09/using-mapserver-3-cgi-mapserver/">Continue to part 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/11/14/using-mapserver-2-generating-map-tiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SharpMap (4)</title>
		<link>http://spatialhorizons.com/2007/11/07/using-sharpmap-4/</link>
		<comments>http://spatialhorizons.com/2007/11/07/using-sharpmap-4/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 23:55:19 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[SharpMap]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://spatialhorizons.com/2007/11/07/using-sharpmap-4/</guid>
		<description><![CDATA[This post concludes our tutorial introducing SharpMap and how to use it in a mapping application. We were planning to explore it in some more depth by demonstrating some additional functionality, but we are working on another project that will be discussed in the near future. In short, SharpMap has tremendous potential as a lightweight [...]]]></description>
			<content:encoded><![CDATA[<p>This post concludes our tutorial introducing <a href="http://www.codeplex.com/SharpMap">SharpMap</a> and how to use it in a mapping application. We were planning to explore it in some more depth by demonstrating some additional functionality, but we are working on another project that will be discussed in the near future. In short, SharpMap has tremendous potential as a lightweight component for adding mapping capabilities to desktop and web applications.</p>
<p>Our sample application&#8217;s source code is available to download below. It includes everything needed to compile and run the application using <a href="http://msdn2.microsoft.com/en-us/express/aa700756.aspx">Visual C# Express</a>. The SharpMap library, included in the download, is released under the GNU Lesser General Public License. For more information on that, see <a href="http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=Is%20SharpMap%20free%20with%20no%20strings%20attached&#038;referringTitle=FAQ">here</a>.</p>
<p><img src="http://spatialhorizons.com/wp-content/uploads/2007/10/sharpmap_coloredmap.jpg" alt="SharpMap Demo Application" /></p>
<p><a href="http://spatialhorizons.com/downloads/SharpMapDemo.zip"><img border="0" alt="Download Source Code" src="http://spatialhorizons.com/downloads/code_download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://spatialhorizons.com/2007/11/07/using-sharpmap-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
