Topic: Support/Comments for GoogleMapMarker  (Read 53773 times)

Pages: 1 2 3 [4] 5 6 ... 11   Go Down

#61: 3-Mar-2007, 02:45 AM

BB2
Posts: 70

I've used the Document Setting panel and filled the Description in as School, the Title in as 52.347072,-1.136109.


I believe it is the other way around: description=52.347072,-1.136109 and title=School

#62: 3-Mar-2007, 03:46 AM


bunk58
Posts: 1,790

David Bunker

WWW
I've used the Document Setting panel and filled the Description in as School, the Title in as 52.347072,-1.136109.


I believe it is the other way around: description=52.347072,-1.136109 and title=School


Sorry that was a typo by me that I've corrected in my previous post I do have it the right way round but no markers!
So I still need help.
Thanks
David

#63: 3-Mar-2007, 04:04 AM

BB2
Posts: 70

Snippet call is...
Code:
[!GoogleMapMarker? &apiKey=`ABQIAAAAYcoc9A-duXiuiTXWZoAygxRD_hqpplOZCJsBCiUszznx5GU1KBRd839DOLY7gxsfcd_g4Dor5G0qZw` &mapControl=`large` &mapType=`hybrid` &defaultZoom=`12` &centerPos=`52.347216,-1.135519` &tpl=`GoogleMapMarker`&startId=`123`!]


I notice two small typos in your call: there is no space between `GoogleMapMarker` and &startId
+ I also have the call &startID with capitals instead of Id

#64: 3-Mar-2007, 04:19 AM


bunk58
Posts: 1,790

David Bunker

WWW
I have the lower case d in ID as a fix from a previous post in this thread for getting stuck at "loading map".
I tried adding the space before
Code:
&startId
but it made no difference.
Thanks for trying!
David

#65: 3-Mar-2007, 04:30 AM

BB2
Posts: 70

The only difference i also see is a param to the css ...

I have my call as follows:
Code:
[[GoogleMapMarker? &apiKey=`ABQIAAAAUY1UzZYFyZwBaK_-KjylfBSkzulCMhGJfukUGz2zyDKajesJgxR31YTclEdWiZMt-lQB_SPJhlpWbQ` &tpl=`GoogleMapMarker` &startID=`44` &linksClass=`maplink`]]

+ the css:
Code:
/* maplinks */

.maplink a {

clear: both;
font-weight: bold;
font-size: 100%;
padding: 4px 0px 4px 0px;

}

.maplink a:hover {

color: #8A2337;

font-weight: bold;
font-size: 100%;
padding: 4px 0px 4px 0px;

}


Do you have the chunk GoogleMapCode??
 with
Code:
var point = new GLatLng([+description+]);
var marker = createMarker(point, '[+title+]', '[+summary+]');
map.addOverlay(marker);

I also have the 0.9.5 version, perhaps the upgrade will solve your problem ...

#66: 3-Mar-2007, 04:50 AM

BB2
Posts: 70

What I'm also thinking of now is:the structure of maps/documents in your tree:

DocumentwithcallandMap (ID=40) - published and in show in menu
   - subfolder unpublished - container for markers (ID=41)
         -- children with markers (ID=42 etc)

Then the call to Googlemap is on page 40 with &startID=41

Is this how you have it?

Then I'm at a loss ....   Huh


#67: 3-Mar-2007, 05:04 AM


bunk58
Posts: 1,790

David Bunker

WWW
I haven't bothered with the css yet, thought I'd do it if and when it's running correctly.
Yes I do have the GoogleMapCode chunk.
I have the folder setup just as you suggest, I  have tried with the template set to blank and not, cached and not.
It must be me!
I'll see if the v09.5 upgrade helps.
Thanks
David

#68: 3-Mar-2007, 05:52 AM

BB2
Posts: 70

ok, good luck!

#69: 3-Mar-2007, 08:01 AM

Coding Team

doze
Posts: 4,091

....Boom!

The reason why you don't have any markers is that you use &startId in the snippet call when it should be startID. And if using startID breaks your map, it means that there is some javascript error on the page. I would guess that it's either you are using line breaks in the marker document content or you have quotes in it and they are not escaped. In anycase, use &startID and give a link to the site so I can see what's going on..
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#70: 5-Mar-2007, 02:43 AM


bunk58
Posts: 1,790

David Bunker

WWW
I've got it working now.
The problem seemed to be :
Using 0.9.2 the map won't display with "startID" but will with "startId" but that means the markers won't display because that part of the snippet call fails.
With 0.9.5 the map won't diplay with "startId" because the whole snippet call fails. Once you use "startID" the map works.
I still couldn't get the markers working so I deleted all but one of them.
Suddenly it worked map and markers, obviously a problem with the other markers. I duplicated the good one and deleted the bad ones, still no go neither the map or markers!
I checked the rendered page source code and saw the javascript had a problem near the bottom after the word Finland....
Code:
// This function picks up the click and opens the corresponding info window
function myclick(i) {
gmarkers[i].openInfoWindowHtml(htmls[i]);
}var point = new GLatLng(52.347072,-1.136109);
var marker = createMarker(point, 'School', 'This is the marker for the school');
map.addOverlay(marker);var point = new GLatLng(63.098332,23.056698);
var marker = createMarker(point, 'Finland', 'Somewhere in Finland
');
I went back to the duplicated marker and found a space after the word Finland, deleted that in source view, didn't work, went back and deleted it with the editor turned off and now it works with multiple markers!
Thanks for the snippet Doze, didn't see your reply until afterwards!
Regards
David

#71: 5-Mar-2007, 09:06 AM

Coding Team

doze
Posts: 4,091

....Boom!

Yeah, I will update this snippet to newest Ditto version soon once I get the 0.5 final maxigallery together.

I will add the geocoding ability (you can enter just an address for the marker) and I'll also make it strip the newlines and escape quotes automatically so you can use RTE for doing the marker bubbles and newlines and quotes won't matter.. You don't also have to do the ditto chunk for this manually after the update.. But until then..
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#72: 10-Mar-2007, 12:34 PM

Coding Team
ApoXX
Posts: 132

WWW
Say, have you gotten this to work with Ditto 2 yet? I'm looking through it now and it appears the snippet call will need to be adjusted slightly.

#73: 10-Mar-2007, 12:59 PM

Coding Team
ApoXX
Posts: 132

WWW
Okay, I got it working by adding the 'extenders' => 'summary' param:

Code:
$script .= $modx->runSnippet($dittoName,array('extenders' => 'summary', 'descendentDepth' => $descendentDepth, 'sortBy' => $sortBy, 'sortDir' => $sortDir, 'summarize' => 'all', 'displayArchive' => '0', 'tpl' => $dittoChunk, 'startID' => $startID, 'showPublishedOnly' => '0', 'trunc' => '0'));

I also changed showPublishedOnly to 1 so it would work on my published documents.

Does anyone know if there is a way to get the text within the summary bubbles to wrap at a given point, or include html within the bubble?

BTW, great snippet - much easier to use than I expected.
« Last Edit: 10-Mar-2007, 01:47 PM by ApoXX »

#74: 10-Mar-2007, 03:11 PM

Coding Team

doze
Posts: 4,091

....Boom!

You can have html in the bubble just fine.. Just do html in the document content. But you need to escape quotes and have it in single line. I would suggest to use a PHx modifier by doing a snippet "phx:slashandstrip":

Code:
<?php
return addcslashes(preg_replace("~([\n\r\t\s]+)~"," ",$output), "'");
?>


Then in the GoogleMapCode chunk, use:
Code:
var point = new GLatLng([+description:slashandstrip+]);
var marker = createMarker(point, '[+title:slashandstrip+]', '[+summary:slashandstrip+]');
map.addOverlay(marker);

and you don't have to worry about newlines or quotes in your marker documents anymore.

EDIT: and content placeholder could be used instead of symmary, as there's trunc=`0` already to get the full content.. I guess that at the time i did this, there was no placeholder for full content or I had simply missed it.
« Last Edit: 10-Mar-2007, 03:29 PM by doze »
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#75: 6-Apr-2007, 08:43 AM


Sylvaticus
Posts: 489

I think, therefor I am. But what I am, and why...?

WWW
I really hope you can find time to update this snippet to newest Ditto version as soon as possible.  Cheesy I never got the markers to work with the "old" version of GoogleMapMarkers, and now I have Ditto 2.01 installed so i guess I'm stuck so far.  Undecided

#76: 6-Apr-2007, 02:59 PM

Coding Team

doze
Posts: 4,091

....Boom!

You can easily use it with newest Ditto. Here's a slightly modified code:

Code:
<?php
/* Snippet name: [[GoogleMapMarker]]
 * Version: 1.0c for ditto v2+
 * Author: doze <dozebox@gmail.com>
 * 
 * Snippet to generate goolemaps map and place markers 
 * to the maps from documents.
 * 
 * Installation:
 * -------------
 * 1. Create a snippet "phx:slashandstrip" with this content:
 *    return addcslashes(preg_replace("~([\n\r\t\s]+)~"," ",$output), "'");
 *
 * 2. Call the snippet in some document: [[GoogleMapMarker? &apikey=`ABQIA..`]]
 * 
 * How to place markers:
 * ---------------------
 * 1. Create a folder in MODx manager what will keep the marker documents, can be unpublished.
 * 2. Create a new document inside that folder what will be the marker
 *    - Title: Will be used as the marker "sidelink" text (example: My home)
 *    - Description: The coordinates for the marker (example: 63.098332,23.056698)
 *    - Document content: HTML to show in the marker popup. 
 *                        NOTE: You have to escape all ' characters by putting backslash before them, e.g. \'
 * 3. Add the &startID parameter to the snippet call pointing to the folder what has the marker documents
 *    example: [[GoogleMapMarker? &apikey=`ABQIA..` &startID=`52`]]
 *
 * Example GoogleMapMarker template chunk (&tpl)
 * ---------------------------------------------
 * The template must have 2 divs. A div for the map and div for the side links. That's it.
 *
 *  <div id="map" style="float:left; width: 350px; height: 350px;">Loading map...</div>
 *  <div id="maplinks" style="margin-left: 10px; padding-right: 10px; float: left; display: block; height: 350px; overflow: auto;"></div>
 *
 */

////////////////////////////////////////////////////////
// Parameter default values configuration
////////////////////////////////////////////////////////

// [text]
// The Google Maps api key to use (http://www.google.com/apis/maps/signup.html)
$apiKey = (isset($apiKey)) ? $apiKey "";

// [number]
// The ID number of the top folder that has google marker documents
$startID = (isset($startID)) ? $startID "";

// [number]
// Number of levels deep to go
$descendentDepth = (isset($descendentDepth)) ? $descendentDepth 1;

// [text]
// Field to sort by (recommended values include createdon, pub_date, editedon)
$sortBy = (isset($sortBy)) ? $sortBy "createdon";

// ["DESC" | "ASC"]
// Direction to sort by, either ASC (ascending) or DESC (descending)
$sortDir = (isset($sortDir)) ? $sortDir "ASC";

// [text]
// Chunk name to use as a template
$tpl = (isset($tpl)) ? $tpl "";

// [text]
// Id name of the div where the map will be rendered
$mapDiv = (isset($mapDiv)) ? $mapDiv "map";

// [text]
// Id name of the div where the marker links will be rendered
$linksDiv = (isset($linksDiv)) ? $linksDiv "maplinks";

// [text]
// Class name to use in the marker links
$linksClass = (isset($linksClass)) ? $linksClass "maplink";

// ["normal" | "satellite" | "hybrid"]
// Initial type of the map
$mapType = (isset($mapType)) ? $mapType "normal";

// [latitude,longitude]
// Coordinates to the initial center position of the map
$centerPos = (isset($centerPos)) ? $centerPos "63.098332,23.056698";

// [number]
// Initial zoomlevel for the map
$defaultZoom = (isset($defaultZoom)) ? $defaultZoom "8";

// ["large" | "small" | "zoomonly" | "none"]
// Look of the controls to navigate / zoom the map
$mapControl = (isset($mapControl)) ? $mapControl "large";

// ["large" | "small" | "none"]
// Look of the controls to change the map type
$mapTypeControl = (isset($mapTypeControl)) ? $mapTypeControl "large";

// [0 | 1]
// When mouse cursor is moved over the map marker, should the info box open on that marker?
$openMouseOverMarker = (isset($openMouseOverMarker)) ? $openMouseOverMarker 0;

// [0 | 1]
// When the map marker is clicked, should the info box open on that marker?
$openMouseClickMarker = (isset($openMouseClickMarker)) ? $openMouseClickMarker 1;

// [0 | 1]
// When mouse cursor is moved over the textual marker link, should the info box open on that marker?
$openMouseOverLink = (isset($openMouseOverLink)) ? $openMouseOverLink 0;

// [0 | 1]
// When the textual marker link is clicked, should the info box open on that marker?
$openMouseClickLink = (isset($openMouseClickLink)) ? $openMouseClickLink 1;

// [0 | 1]
// Show overview map in the right bottom corner of the map?
$showOverviewMap = (isset($showOverviewMap)) ? $showOverviewMap 1;

// [width,heigth]
// Size of the overview map
$overviewMapSize = (isset($overviewMapSize)) ? $overviewMapSize "150,150";

// [0 | 1]
// Should the overview map be hidden by default? (arrow indicator visible at the bottom right corner)
$hideOverviewMapByDefault = (isset($hideOverviewMapByDefault)) ? $hideOverviewMapByDefault 1;

// [text]
// Name of the Ditto snippet
$dittoName = (isset($dittoName)) ? $dittoName "Ditto";

////////////////////////////////////////////////////////
// Start of snippet code
////////////////////////////////////////////////////////

if($apiKey != "") {

    
$script '
        <script type="text/javascript">
        //<![CDATA[
            
            // addEvent scripts written by Dean Edwards, 2005
            // with input from Tino Zijdel, Matthias Miller, Diego Perini
            // http://dean.edwards.name/weblog/2005/10/add-event/

            function addEvent(element, type, handler) {
                if (element.addEventListener) {
                    element.addEventListener(type, handler, false);
                } else {
                    // assign each event handler a unique ID
                    if (!handler.$$guid) handler.$$guid = addEvent.guid++;
                    // create a hash table of event types for the element
                    if (!element.events) element.events = {};
                    // create a hash table of event handlers for each element/event pair
                    var handlers = element.events[type];
                    if (!handlers) {
                        handlers = element.events[type] = {};
                        // store the existing event handler (if there is one)
                        if (element["on" + type]) {
                            handlers[0] = element["on" + type];
                        }
                    }
                    // store the event handler in the hash table
                    handlers[handler.$$guid] = handler;
                    // assign a global event handler to do all the work
                    element["on" + type] = handleEvent;
                }
            };
            // a counter used to create unique IDs
            addEvent.guid = 1;

            function removeEvent(element, type, handler) {
                if (element.removeEventListener) {
                    element.removeEventListener(type, handler, false);
                } else {
                    // delete the event handler from the hash table
                    if (element.events && element.events[type]) {
                        delete element.events[type][handler.$$guid];
                    }
                }
            };

            function handleEvent(event) {
                var returnValue = true;
                // grab the event object (IE uses a global event object)
                event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
                // get a reference to the hash table of event handlers
                var handlers = this.events[event.type];
                // execute each event handler
                for (var i in handlers) {
                    this.$$handleEvent = handlers[i];
                    if (this.$$handleEvent(event) === false) {
                        returnValue = false;
                    }
                }
                return returnValue;
            };

            function fixEvent(event) {
                // add W3C standard event methods
                event.preventDefault = fixEvent.preventDefault;
                event.stopPropagation = fixEvent.stopPropagation;
                return event;
            };
            fixEvent.preventDefault = function() {
                this.returnValue = false;
            };
            fixEvent.stopPropagation = function() {
                this.cancelBubble = true;
            };
                
            addEvent(window, "unload", GUnload);

            if (GBrowserIsCompatible()) {
                // Display the map, with some controls
                var map = new GMap2(document.getElementById("'
.$mapDiv.'"));
                // set initial center position
                map.setCenter(new GLatLng('
.$centerPos.'),'.$defaultZoom.');
    
                //add controls to navigate / zoom
                '
;

    if (
$mapControl == "zoomonly") {
        
$script .= '
                map.addControl(new GSmallZoomControl());'
;
    } else if (
$mapControl == "large") {
        
$script .= '
                map.addControl(new GLargeMapControl());'
;
    } else if (
$mapControl == "small") {
        
$script .= '
                map.addControl(new GSmallMapControl());'
;
    }

    if (
$mapTypeControl == "large") {
        
$script .= '
                // add controls to change map type
                map.addControl(new GMapTypeControl(0));'
;
    } else if (
$mapTypeControl == "small") {
        
$script .= '
                // add controls to change map type
                map.addControl(new GMapTypeControl(1));'
;
    }

        
$script .= '
                //set initial map type
                '
;
    if (
$mapType == "normal") {
        
$script .= '
                map.setMapType(G_NORMAL_MAP);'
;
    } else if (
$mapType == "satellite") {
        
$script .= '
                map.setMapType(G_SATELLITE_MAP);'
;
    } else if (
$mapType == "hybrid") {
        
$script .= '
                map.setMapType(G_HYBRID_MAP);'
;
    }
        
$script .= '
                // arrays to hold copies of the markers and html used by the sidebar
                // because the function closure trick doesnt work there
                var sidebar_html = "";
                var gmarkers = [];
                var htmls = [];
                var i = 0;

                // a function to create the marker and set up the event window
                function createMarker(point,name,html) {
                    var marker = new GMarker(point);'
;

    if(
$openMouseClickMarker) {
        
$script .= '
                    // event listener to open info on click
                    GEvent.addListener(marker, "click", function(){
                        marker.openInfoWindowHtml(html);
                    });'
;
    }

    if(
$openMouseOverMarker) {
        
$script .= '
                    // The new marker "mouseover" listener
                    GEvent.addListener(marker,"mouseover", function(){
                        marker.openInfoWindowHtml(html);
                    });'
;
    }

        
$script .= '    
                    // save the info we need to use later for the sidebar
                    gmarkers[i] = marker;
                    htmls[i] = html;
                    // add a line to the sidebar html
                    sidebar_html += \'<div class="'
.$linksClass.'"><a href="javascript:void(0)" ';

    if(
$openMouseClickLink) {
        
$script .= 'onClick="myclick(\' + i + \')"';
    }

    if(
$openMouseOverLink) {
        
$script .= 'onMouseOver="myclick(\' + i + \')"';
    }

        
$script .= '>\' + name + \'</a></div>\';
                    i++;

                    return marker;
                }

                // This function picks up the click and opens the corresponding info window
                function myclick(i) {
                    gmarkers[i].openInfoWindowHtml(htmls[i]);
                }'
;
    if(
$startID != "") {

        
$script .= $modx->runSnippet($dittoName,array('depth' => $descendentDepth'sortBy' => $sortBy'sortDir' => $sortDir'summarize' => 'all''displayArchive' => '0''tpl' => '@CODE:var point = new GLatLng([+description+]); var marker = createMarker(point, \'[+title:slashandstrip+]\', \'[+content:slashandstrip+]\'); map.addOverlay(marker);''parents' => $startID'showPublishedOnly' => '0'));

        
$script .= '
                // put the assembled sidebar_html contents into the sidebar div
                document.getElementById("'
.$linksDiv.'").innerHTML = sidebar_html;';
    }

    if(
$showOverviewMap) {
        
$script .= '
                // ======== Add a map overview ==========
                var ovcontrol = new GOverviewMapControl(new GSize('
.$overviewMapSize.')); 
                map.addControl(ovcontrol,new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10)));'
;
    }
    if(
$hideOverviewMapByDefault) {
        
$script .= '
                //set hidden by default (without animation)
                ovcontrol.hide(1);'
;
    }
        
$script .= '
            } else { // !GBrowserIsCompatible()
                alert("Sorry, the Google Maps API is not compatible with this browser");
            }
    
            // This Javascript is based on code provided by the
            // Blackpool Community Church Javascript Team
            // http://www.commchurch.freeserve.co.uk/ 
            // http://www.econym.demon.co.uk/googlemaps/

        //]]>
        </script>
        '
;

    
//register scripts
    
$modx->regClientScript($script);
    
$modx->regClientStartupScript("http://maps.google.com/maps?file=api&amp;v=2&amp;key=".$apiKey);

    if(
$tpl == "") {
        
$returnstring '
            <div id="'
.$mapDiv.'" style="float:left; width: 350px; height: 350px;">Loading map...</div>
            <div id="'
.$linksDiv.'" style="margin-left: 10px; padding-right: 10px; float: left; display: block; height: 350px; overflow: auto;"></div>
            <noscript>
                <b>JavaScript must be enabled in order for you to use Google Maps.</b> 
                However, it seems JavaScript is either disabled or not supported by your browser.
                To view Google Maps, enable JavaScript by changing your browser options, and then
                try again.
            </noscript>
            '
;
    } else {
        
$returnstring $modx->getChunk($tpl);
    }
} else {
    if (
$apiKey == "") {
        
$returnstring '
                        You have to provide a Google Maps API key to use!<br />
                        If you don\'t have one yet, go <a href="http://www.google.com/apis/maps/signup.html" alt="Sign up for the Google Maps API">here</a> to get it. NOTE: the api key is site/directory specific!<br /><br />
                        '
;
    }

}

return 
$returnstring;
?>


You also need to create a snippet "phx:slashandstrip" with this content:
Code:
<?php
return addcslashes(preg_replace("~([\n\r\t\s]+)~"," ",$output), "'");
?>

And have PHx installed ofcourse.

You don't have to create the "GoogleMapCode" chunk anymore and no need to escape quotes + it can handle multi-line bubble texts.. I will do a bigger update later when I have time.
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#77: 6-Apr-2007, 05:08 PM


Sylvaticus
Posts: 489

I think, therefor I am. But what I am, and why...?

WWW
Thank you very much. I will try this as soon as I have time.

#78: 14-Apr-2007, 08:40 PM


rajfantastic
Posts: 55

WWW
can anyone enlighten me on how to change the icon for the gmaps? i got the following code from the API docs but i have no idea where or how to place it in the snippet:

Code:
// Create our "tiny" marker icon
var icon = new GIcon();
icon.image = "http://www.mysite.com/images/mapicon1.png";
icon.shadow = "http://www.mysite.com/images/mapicon1_shadow.png";
icon.iconSize = new GSize(20, 35);
icon.shadowSize = new GSize(29, 18);
icon.iconAnchor = new GPoint(10, 15);
icon.infoWindowAnchor = new GPoint(5, 1);
stevesunderland.com
GRAPHICS | INTERACTIVE | MARKETING
xhtml + ajax + seo websites powered by modx

#79: 14-Apr-2007, 09:14 PM

Coding Team

doze
Posts: 4,091

....Boom!

The line numbers in this post refers to the code in above post.

Put the lines you have starting from line 260 and then replace "new GMarker(point)" with "new GMarker(point,icon)". That should do it.
New MODx wiki! Please help up with documentation efforts! || Old Wiki

"He can have a lollipop any time he wants to. That's what it means to be a programmer."

#80: 14-Apr-2007, 09:25 PM


rajfantastic
Posts: 55

WWW
@doze: thanks so much for your almost-instant reply... my maps look great now!
stevesunderland.com
GRAPHICS | INTERACTIVE | MARKETING
xhtml + ajax + seo websites powered by modx
Pages: 1 2 3 [4] 5 6 ... 11   Go Up
0 Members and 1 Guest are viewing this topic.