0

I feel really bad asking this question. If what I'm trying to do isn't possible, please advise.

I'm a graphic/web design student and so far only good at html. I'm using a google maps component and would like to style the maps using the API wizard. As Follows: http://pastebin.com/YsKbyS58

Problem is examples use static html and the component is php based: http://pastebin.com/XrEMmTVJ

Can I inject the JSON array into the PHP file? What would the syntax be like?

Thank you!

2 Answers 2

1

Google maps syntax for styling the map is like (with your php script) :

// Map creation
        var map = new google.maps.Map(document.getElementById('contentmap_<?php echo $owner; ?>_<?php echo $id; ?>'),
        {
                zoom: <?php echo $this->Params->get("zoom", 0); ?>,
                center: center,
                mapTypeId: google.maps.MapTypeId.<?php echo $this->Params->get("map_type", "ROADMAP"); ?>,
                styles : [
                    {
                     elementType: "geometry",
                     stylers: [
                          { visibility: "on" },
                          { hue: "#ff8800" }
                     ]
                    },{
                     elementType: "labels",
                     stylers: [
                           { hue: "#ffc300" }
                     ]
                    }
                ]
             });
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the quick response, unfortunately this breaks the map. (just white). Something must be conflicting somewhere.
Hum I miss a , before the styles key. I've edited my post.
AH! I did the same mistake, thank you. still no change though
Corrected another syntax fault on my side (stylez instead of styles) Thank you so much!
0

What I understood is that you want to apply those styles to your map? Since what you have posted is really just a static object, you can insert it right into your map options:

var map = new google.maps.Map(document.getElementById('contentmap_<?php echo $owner; ?>_<?php echo $id; ?>'),
    {
        zoom: <?php echo $this->Params->get("zoom", 0); ?>,
        center: center,
        mapTypeId: google.maps.MapTypeId.<?php echo $this->Params->get("map_type", "ROADMAP"); ?>,
            styles:  [ 
                       { 
                         elementType: "geometry",
                         stylers: [
                           { visibility: "on" },
                           { hue: "#ff8800" }
                         ] 
                       },{ 
                         elementType: "labels",
                         stylers: [
                           { hue: "#ffc300" }
                         ] 
                       } 
                     ]
    });

If you mean to make the styles dynamic the PHP tags can replace the values inside the styles objects too.

4 Comments

Thank you! Unfortunately the map stops working. Maybe a conflict with the rest of the component. (NEVER MIND, silly syntax error) No difference in styling though.
No, it must be my fault then. Let me see and try to fix it.
Found the problem. I used stylez instead of styles. SOLUTION WORKS! wish I could tick two answers as correct :) Thank you, Heitor
Good luck with your project :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.