Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dandrayne 1138 posts 2262 karma points
    Jun 21, 2010 @ 15:00
    dandrayne
    4

    Macro for map display using v3 maps api (umb 4.1)

    Howdy

    Just thought I'd share a quick macro for displaying the maps using the new v3 embed code and perhaps save someone 10 minutes

    First off is the "initialiase" function to go inside the <body> tag (ie <body <umbraco:macro.... )

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="text" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:if test="string($currentPage/yourMapAlias) != ''">
    <xsl:text>onload="initialize()"</xsl:text>
    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

    Then we have the rendering function to stick the map out on the page. This goes in the <head> section

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="html" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">


    <xsl:if test="string($currentPage/yourMapAlias) != ''">

    <xsl:variable name="mapData" select="umbraco.library:Split($currentPage/yourMapAlias,',')"/>

    <xsl:variable name="mapLat" select="$mapData/value[position() = 1]" />
    <xsl:variable name="mapLong" select="$mapData/value[position() = 2]" />
    <xsl:variable name="mapZoom" select="$mapData/value[position() = 3]" />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">

    <![CDATA[
    function initialize() {
    var myLatlng = new google.maps.LatLng(]]><xsl:value-of select="$mapLat" /><![CDATA[,]]><xsl:value-of select="$mapLong" /><![CDATA[);
    var myOptions = {
    zoom: ]]><xsl:value-of select="$mapZoom" /><![CDATA[,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map"), myOptions);

    var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title:"Hello World!"
    });
    }
    ]]>
    </script>

    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

    You'll probably want to change or get rid of "hello world"

    Dan

  • John 115 posts 150 karma points
    Aug 06, 2010 @ 01:19
    John
    0

    You're a helpful guy Dandrayne. Everywhere on the forum :) I'd karma you up but I don't have enough karma myself yet :) Thank you for this, you did indeed save some one10 minutes (well, lots more actually).

  • Lachlann 344 posts 626 karma points
    Feb 07, 2011 @ 12:49
    Lachlann
    0

    Hey in case anyone is adding mutliple markers to the map here is some usefull code (not written by me) for stretching the zoom level of the map ot fit all markers.

     

    http://blog.shamess.info/2009/09/29/zoom-to-fit-all-markers-on-google-maps-api-v3/

     

    L

     

  • Fredrik Esseen 610 posts 906 karma points
    Apr 12, 2011 @ 08:44
    Fredrik Esseen
    0

    Hi!

    Im trying to make this work but get the error:

    Detaljerad information om felet på webbsidan

    Message: 'null' is null or not an object
    28
    1462
    Code 0
    URI: http://maps.gstatic.com/intl/sv_ALL/mapfiles/api-3/4/8b/main.js

    What gets rendered is this:

    function initialize() {
    3 var myLatlng = new google.maps.LatLng(
    4 60.8862628,
    5 15.118497299999945);
    6 var myOptions = {
    7 zoom: 13
    8 ,
    9 center: myLatlng,
    10 mapTypeId: google.maps.MapTypeId.ROADMAP
    11 }
    12 var map = new google.maps.Map(document.getElementById("map"), myOptions);
    13 var marker = new google.maps.Marker({
    14 position: myLatlng,
    15 map: map,
    16 title:"Hello World!"
    17 });
    18 }

     

    Ive added the two macros above to the body and the head, added the datatype result to the page.

    What am i missing?

Please Sign in or register to post replies

Write your reply to:

Draft