<?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>Webmonkey &#187; mapstraction</title>
    <atom:link href="http://www.webmonkey.com/tag/mapstraction/feed/" rel="self" type="application/rss+xml" />
    <link>http://www.webmonkey.com</link>
    <description>The Web Developer&#039;s Resource</description>
    <lastBuildDate>Fri, 05 Apr 2013 20:20:46 +0000</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <generator>http://wordpress.org/?v=3.4.2</generator>
    
    <item>
        <title>Personalize Your Map With a Custom Map Marker</title>
        <link>http://www.webmonkey.com/2010/10/personalize-your-map-with-a-custom-map-marker/</link>
        <comments>http://www.webmonkey.com/2010/10/personalize-your-map-with-a-custom-map-marker/#comments</comments>
        <pubDate>Thu, 07 Oct 2010 17:35:51 +0000</pubDate>

                <dc:creator>Michael Calore</dc:creator>

        <guid isPermaLink="false">http://www.webmonkey.com/?p=48912</guid>
        		<category><![CDATA[Location]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[mapstraction]]></category>
		<category><![CDATA[Tutorials]]></category>
            <enclosure url="http://www.webmonkey.com/wp-content/uploads/2010/10/AdamD3.jpg" type="image/jpeg" length="48000" />
                    <description><![CDATA[<div class="rss_thumbnail"><img src="http://www.webmonkey.com/wp-content/uploads/2010/10/AdamD3.jpg" alt="Personalize Your Map With a Custom Map Marker" /></div>If you&#8217;re adding a map to your website, why settle for the vanilla design when you can customize it and leave your own personal mark? This tutorial will show you how to create a custom map from scratch, then add a little unique flavor to it by replacing the standard &#8220;map pin&#8221; icon with a [...]]]></description>

            <content:encoded><![CDATA[<p><!-- wpautop enabled -->
<p><img src="http://www.webmonkey.com/wp-content/uploads/2010/10/AdamD1.jpg" alt="" title="AdamD1" />If you&#8217;re adding a map to your website, why settle for the vanilla design when you can customize it and leave your own personal mark?</p>
<p>This tutorial will show you how to create a custom map from scratch, then add a little unique flavor to it by replacing the standard &#8220;map pin&#8221; icon with a custom icon of your own design.</p>
<p>To do this, we&#8217;ll be using Mapstraction, a library that creates map code that can be reused across all the big mapping providers (Yahoo, Google, et al). Mapstraction also allows for multiple types of customization such as custom info bubbles and graphics like the one we&#8217;ll be dropping onto the map.</p>
<p><strong>Note:</strong> This tutorial is adapted from the book <a href="http://nostarch.com/mapscripting.htm">Map Scripting 101</a> by Adam DuVander. Adam is a former Webmonkey contributor and executive editor of <a href="http://www.programmableweb.com/">Programmable Web</a>. In his book, he shows how to use all of the features of the most popular mapping APIs, and how to mash them up with data from other sources like events calendars, weather services and restaurant review sites to make a variety of custom maps.</p>
<p>This exercise comes from chapters 1 and 2 of Adam&#8217;s book, and it is reprinted here with his permission and that of the book&#8217;s publisher, No Starch Press. It isn&#8217;t a word-for-word excerpt. It has been slightly adapted to work as a web tutorial. You&#8217;ll find dozens of in-depth exercises &#8212; including the full version of this one &#8212; in the book itself.</p>
<h3>Create a Mapstraction map</h3>
<p>Mapstraction is a little different from Google Maps and Yahoo Maps. Mapstraction is an open source JavaScript library that ties into other mapping APIs. If you use Mapstraction, you can switch from one type of map to another with very little work, as opposed to rewriting your code completely.</p>
<p>Using Mapstraction limits your risk to changes being made to an API. For example, if your site&#8217;s traffic takes you beyond the limit for your chosen provider, or the provider begins placing ads on the map, Mapstraction lets you switch providers quickly and inexpensively.</p>
<p>To use Mapstraction, you must first choose a provider. In this example, I&#8217;m using Mapstraction to create a Google Map.<br />
<span id="more-48912"></span></p>
<p>Open a new HTML file and type the following:</p>
<pre class="brush: js">
&lt;html> 
  &lt;head> 
    &lt;title>Basic Mapstraction Map&lt;/title> 
    &lt;script 
    src="http://maps.google.com/maps/api/js?sensor=false"   
      type="text/javascript">&lt;/script> 
    &lt;script type="text/javascript" src="mxn.js?(googlev3)">&lt;/script> 
    &lt;style type="text/css"> 
      div#mymap { 
        width: 400px; 
        height: 350px; 
      } 
    &lt;/style> 
    &lt;script type="text/javascript"> 
      function create_map() { 
           var mapstraction = new mxn.Mapstraction('mymap', 'googlev3'); 
        mapstraction.setCenterAndZoom( 
          new mxn.LatLonPoint(37.7740486,-122.4101883), 15); 
      } 
    &lt;/script> 
  &lt;/head> 
  &lt;body onload="create_map()"> 
    &lt;div id="mymap">&lt;/div> 
  &lt;/body> 
&lt;/html> 
</pre>
<p>Just like you would for a normal Google Map, we include Google&#8217;s JavaScript (line 4).</p>
<p>For this code to work, you also need to download the Mapstraction files. Go to <a href="http://mapstraction.com/">mapstraction.com</a> or the project&#8217;s <a href="http://github.com/mapstraction/mxn">github page</a>, and follow the instructions to save the files in the same directory as your HTML file. Best practices would dictate that you keep JavaScript files in their own directory, separate from your HTML, but I&#8217;m simplifying things for this example.</p>
<p>The Mapstraction files you should have, at minimum, are <code>mxn.js</code>, <code>mxn.core.js</code> and <code>googlev3.core.js</code>. You may also have files for other providers, such as <code>yahoo.core.js</code>. The only one we need to reference in our HTML code is <code>mxn.js</code>, which loads the other files that it needs, including those we pass it in the file name. Then, in the <code>create_map</code> function, we let it know which type of map we are creating.</p>
<p>Once you have your Mapstraction map, save your HTML file and load it in a browser. The result should look exactly like this.</p>
<p><img src="http://www.webmonkey.com/wp-content/uploads/2010/10/AdamD2.jpg" alt="" title="Google Map" /><br clear="all" /></p>
<p>This Google map, created via Mapstraction, should be centered on No Starch Press&#8217;s neighborhood in San Francisco.</p>
<p>As you can see, the HTML hooks are minimal. Some styling to determine the size of the map and an empty <code>div</code> tag with an <code>id</code> attribute are all that&#8217;s required. The JavaScript function <code>create_map()</code> takes over and makes calls to the API. This function can have any name you want.</p>
<p>The minimum amount of information needed within the <code>create_map()</code> function is a map type (googlev3), a center point (using a latitude/longitude pair) and a zoom level (Mapstraction&#8217;s tightest zoom level is 16, so I backed off one notch to 15, about six blocks across). Then, we pass those options and reference the <code>div</code> tag&#8217;s <code>id</code> to create a map.</p>
<h3>Add a marker to your map</h3>
<p>To add a simple marker to your map, you just need to use two Mapstraction functions. First, create the marker. Next, add it to the map. The reason for these two distinct steps will become clear in further projects when we start to use advanced options, such as custom marker icons.</p>
<p>Let&#8217;s see what creating the marker looks like in code. Start with the basic Mapstraction map you created and add these lines to the <code>create_map()</code> function:</p>
<pre class="brush: js">
marker = new mxn.Marker(new mxn.LatLonPoint(37.7740486,-122.4101883)); 
// marker options will go here 
mapstraction.addMarker(marker); 
</pre>
<p>The first line creates a marker object, passing latitude/longitude coordinates for the No Starch Press offices in San Francisco. By drawing attention to the graphical marker, we are essentially marking that spot as important.</p>
<p>The second line is a placeholder for any marker options we want to add later. (Any JavaScript line that begins with two slashes is a comment, and the browser ignores them.) The marker options are where we tell Mapstraction which icon to use or add a message to be displayed when the marker is clicked.</p>
<p>Finally, the third line adds the marker to the map. Once this happens, no additional options can be added. The reason is that the marker object is used only by Mapstraction. Once the marker is added to the map, however, Mapstraction makes the appropriate calls to the mapping provider. Mapstraction plots the marker based on all options set beforehand. In this case, we don&#8217;t have options to add, but we&#8217;ll add to this map in future projects.</p>
<p>If you&#8217;re using Google as your mapping provider, your new map will look like the picture below. The default Google icon sits in the center of the map. Although the marker is clickable, this marker is very simple and nothing actually happens if you click it.</p>
<h3>Create a custom icon marker</h3>
<p>The quickest way to make a map feel like your own is to change the default icon used for markers. Mapstraction has simple marker options that make the technical process of using custom icons a cinch. The more laborious part may be creating the icon file itself. To avoid this, you can find icons others have made online for free. I list several resources <a href="http://mapscripting.com/download-custom-markers">on my website</a>.</p>
<p>Still want to create your own? Read on.</p>
<p>To create your own marker icon, you just need to have a graphics program that can save a transparent .png file. The icon can be whatever size you want, but keeping each dimension between 20 and 50 pixels is probably best. If the icon is too small, clicking it becomes difficult; too big, and the icon obscures the location you&#8217;re attempting to call out. If you&#8217;re using Google as your mapping provider, you also want to create an image to use as your marker&#8217;s shadow. This step isn&#8217;t necessary if your marker is a similar shape to the Google default or if you&#8217;re using another provider.</p>
<p>Not much of an image magician? Use the free online <a href="http://www.cycloloco.com/shadowmaker/">Shadowmaker</a> service to create a shadow.</p>
<h3>Add your icon to the map</h3>
<p>Now that you have an icon, the easy part is adding it to the marker options. All it takes is setting a few values to tell Mapstraction where the icon image files resides. Your best bet is to keep custom marker icons in a special directory on your server. If you&#8217;re testing locally, you can use local copies, accessed by their location relative to the page containing the map. For simplicity, I have the HTML file and the icon files in the same directory in this example. In reality, you might prefer to be more organized.</p>
<p>I decided to use a teensy No Starch Press logo for my custom icon. It&#8217;s 27 pixels wide by 31 pixels high. Like I said, the icon is teensy. Then, I used the Shadowmaker service to create a file that is 43×31 including the marker&#8217;s shadow.</p>
<p>Finally, it&#8217;s time to code. Add these lines as marker options. These lines are inserted after a marker has been created but before the marker has been added to the map:</p>
<pre class="brush: js">
marker.setIcon('nostarch-logo.png', [27,31]); 
marker.setShadowIcon('nostarch-shadow.png', [43,31]); 
</pre>
<p>The only parameter you need to include is the path to the image for both the icon and the shadow. Notice that the dimensions of each graphic get passed as an inline array. This parameter is optional but recommended. If you leave it out, some providers will assume the dimensions of the default marker, which could mean a poorly scaled graphic.</p>
<p>The results of the custom marker code are shown below.</p>
<p><img src="http://www.webmonkey.com/wp-content/uploads/2010/10/AdamD3.jpg" alt="" title="Map with a custom logo" /><br clear="all" /></p>
<p>The No Starch Press office is marked by the company&#8217;s logo, a little iron icon. Notice the shadow, as well, which makes the graphic pop out from the map.</p>
<p>Omit the shadow icon at your own risk. Some mapping providers will assume the default shadow, which might look silly with your icon. Not every mapping provider uses shadows, but planning for one is good. If you really don&#8217;t want a shadow, consider using a completely transparent graphic. I show an example of shadowless icons in the weather map example in chapter 10 of my book.</p>
<p><strong>See also:</strong><br/></p>
<ul>
<li><a href="http://www.webmonkey.com/2010/02/multi-map-with-mapstraction/">Multi-map with Mapstraction</a></li>
<li><a href="http://www.webmonkey.com/2010/08/microsoft-adds-openstreetmap-layer-to-bing-maps/">Microsoft Adds OpenStreetMap Layer to Bing Maps</a></li>
<li><a href="http://www.webmonkey.com/2010/03/google-gets-a-new-geocoder/">Google Gets a New Geocoder</a></li>
</ul>
<div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2010/10/personalize-your-map-with-a-custom-map-marker/feed/</wfw:commentRss>
        <slash:comments>8</slash:comments>

        
    </item>
    
    <item>
        <title>New Tools Help You Build Better Maps</title>
        <link>http://www.webmonkey.com/2008/11/new_tools_help_you_build_better_maps/</link>
        <comments>http://www.webmonkey.com/2008/11/new_tools_help_you_build_better_maps/#comments</comments>
        <pubDate>Mon, 24 Nov 2008 23:37:49 +0000</pubDate>

                <dc:creator>Adam Duvander</dc:creator>

        <guid isPermaLink="false">http://www.webmonkey.com/blog/newtoolshelpyoubuildbettermaps</guid>
        		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[mapstraction]]></category>
        <description><![CDATA[What&#8217;s cooler than Google Maps? Tools built on top of it. Developers from the Netherlands have released some helpful libraries to make more usable, interactive Google Maps. Google hosts an open source utility library with several useful examples. Among them, a drag-to-zoom feature and a way to create dynamic labeled markers. A progress bar is [...]]]></description>

            <content:encoded><![CDATA[<p><!-- wpautop enabled --><img class="blogimg" src="http://howto.wired.com/mediawiki/images/Gmaps-progressbar.jpg" alt="Example of progressbarcontrol" class="full" /></p>
<p>What&#8217;s cooler than Google Maps? Tools built on top of it. Developers from the Netherlands have <a href="http://googlegeodevelopers.blogspot.com/2008/11/2-more-libraries-released.html">released some helpful libraries</a> to make more usable, interactive Google Maps.</p>
<p>Google hosts an <a href="http://code.google.com/p/gmaps-utility-library/">open source utility library</a> with several useful examples. Among them, a drag-to-zoom feature and a way to create dynamic labeled markers.</p>
<p>A progress bar is among the new additions to the libraries. When adding more than just a few markers, it can take some time. Rather than make your users sit through the slow-down, this library shows the progress via a popup status bar that fills as it completes.</p>
<p>The other new library, SnapToRoute, allows developers to restrict some actions to just along a polyline. The <a href="http://gmaps-utility-library.googlecode.com/svn/trunk/snaptoroute/1.0/examples/detailzoom.html">example included</a> shows zooming along a specific route.</p>
<p>I love these sorts of libraries that make creating advanced maps easy. Of course, I&#8217;d love to see platform-independent examples, so developers of any map API could benefit. These libraries would be great to see as a part of <a href="http://mapstraction.com/">Mapstraction</a>, the multi-map I <a href="/2010/02/Multi-map_with_Mapstraction">covered in a tutorial</a>.</p>
<p><strong>See also:</strong></p>
<ul>
<li><a href="http://www.webmonkey.com/blog/OpenStreetMap">OpenStreetMap: Free, Editable Map of the World</a></li>
<li><a href="http://www.webmonkey.com/blog/Take_Your_Geo-Mashups_Beyond_Google_Maps">Take Your Geo-Mashups Beyond Google Maps</a></li>
<li><a href="http://www.webmonkey.com/blog/Pipes_Mashup_Turns_Google_Maps_into_a_Blogging_Tool">Pipes Mashup Turns Google Maps into a Blogging Tool</a></li>
</ul>
<div id='linker_widget' class='contextly-widget'></div>]]></content:encoded>
            <wfw:commentRss>http://www.webmonkey.com/2008/11/new_tools_help_you_build_better_maps/feed/</wfw:commentRss>
        <slash:comments>0</slash:comments>

        
    </item>
    </channel>
</rss>