This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Mosets tree google maps

0

I am using joomla components mosetstree with Google Maps positioning for companies. Unfortunately Google Maps does not have a map of my town, but OpenStreetMap does. I don't know how to incorporate the OpenStreetMap layer, so could you please help me? Here is the code of the map page from mosetstree:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $this->mtconf['gmaps_api_key']; ?>" type="text/javascript"></script>
<script type="text/javascript">
    var map = null;
    var geocoder = null;
    function initialize() {
        if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        <?php
        echo 'var center = new GLatLng(' . $this->link->lat . ', ' . $this->link->lng . ');' . "\n";
        echo 'map.setCenter(center, ' . ($this->link->zoom?$this->link->zoom:13) . ');' . "\n";
        if( $this->mtconf['map_control'] != '' ) {
            $mapcontrols = explode(',',$this->mtconf['map_control']);
            foreach( $mapcontrols AS $mapcontrol ) {
                echo 'map.addControl(new '.$mapcontrol.'());' . "\n";
            }
        }
        ?>
        marker = new GMarker(center);
        map.addOverlay(marker);
        }
    }
    jQuery(document).ready(function(){initialize();});
    jQuery(document).unload(function(){GUnload();});
</script>

asked 12 Nov '12, 18:45

Mile's gravatar image

Mile
11112
accept rate: 0%

edited 13 Nov '12, 00:24

SomeoneElse's gravatar image

SomeoneElse ♦
36.9k71370866


One Answer:

1

GMap, OpenLayers, and Leaflet are all used in pretty much the same way. You create a map object, initialize it with an html object to draw into and a latitude/longitude/zoom, and the rest (for your usecase) are optional niceties.

See the two previous links for examples, and adapt them to your php code.

Note that you don't need an API key to use OSM tiles. Alsom the map_controls are probably named differently between libraries, so you should either :

  • Change the mtconf config values
  • Let php translate between the gmap names and the openlayers/leaflet names
  • Use a hardcoded set of map controls

answered 13 Nov '12, 10:10

Vincent%20de%20Phily's gravatar image

Vincent de P... ♦
17.3k18152249
accept rate: 19%

I was hopping someone will help me just to insert openstreet layer within existing map file. I have basic knowledge of coding, meaning im not able to do it alone without detail instructions. However thank you !

(13 Nov '12, 15:24) Mile

It really is quite straightforward. Follow one of the examples or tutorials on openlayer of leaflet website.

The only two changes you need to make is to leave the "jQuery(document).ready(function(){initialize();});" line at the end of the script, and use php code like "<?php echo $this->link->lat ?>" instead of the lat/long/zoom values.

If it doesn't work, check for javascript errors in your borwser's debug console (for example the "firebug" extension of firefox) and check for php errors in your server logs.

(13 Nov '12, 22:51) Vincent de P... ♦

Source code available on GitHub .