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"));
        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);

asked 12 Nov '12, 18:45

Mile's gravatar image

accept rate: 0%

edited 13 Nov '12, 00:24

SomeoneElse's gravatar image

SomeoneElse ♦

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
permanent link

answered 13 Nov '12, 10:10

Vincent%20de%20Phily's gravatar image

Vincent de P... ♦
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... ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 12 Nov '12, 18:45

question was seen: 3,613 times

last updated: 13 Nov '12, 22:51

powered by OSQA