I have problem with markers, actually with clicking on it.
I want to achive that, when i click on a marker, on a left side in a div show name of that marker. Problem is that I always get name from last marker. I guess, that is a problem in the loop, but i don't know what... here is a code:

var paramId = window.params.id;
var paramType = window.params.type;
var map;
var mainType;
var info;
var feedId;
var showPopupOnHover = false;
var markers2;
var position;


function drawmap() {
    var lat            = 44.691701;
    var lon            = 20.519972;
    var zoom           = 18;

    var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
    var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
    var position       = new OpenLayers.LonLat(lon, lat).transform( fromProjection, toProjection);
    map = new OpenLayers.Map("map");

    var mapnik         = new OpenLayers.Layer.OSM();
    map.addLayer(mapnik);





    downloadUrl("includes/feed/"+paramType+".php?id="+paramId, function(data) {
        var markers = data.documentElement.getElementsByTagName("zoom");
        for (var i = 0; i < markers.length; i++) {
            zoom = markers[i].getAttribute("zoom");
            lat = parseFloat(markers[i].getAttribute("lat"));
            lng = parseFloat(markers[i].getAttribute("lng"));

            var position = new OpenLayers.LonLat(lng, lat).transform( fromProjection, toProjection);

            map.setCenter(position, zoom);
        }

        var markers = data.documentElement.getElementsByTagName("feed");
        for (var i = 0; i < markers.length; i++) {
            name = markers[i].getAttribute("name");
            link = markers[i].getAttribute("jumpto");
            id = markers[i].getAttribute("id");
            lat = parseFloat(markers[i].getAttribute("lat"));
            lng = parseFloat(markers[i].getAttribute("lng"));
            type = markers[i].getAttribute("type");
            info = markers[i].getAttribute("info");
            mainType = markers[i].getAttribute("main_type");
    // Add used maker icons..
            icons = new Array();
            icons[i] = new Array('gui/icons/'+type+'.png','21','25','0.5','1');
            var size = new OpenLayers.Size(21,25);
            var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
            var icon = new OpenLayers.Icon('gui/icons/'+type+'.png', size, offset);
    // Add markers
            var position = new OpenLayers.LonLat(lng, lat).transform( fromProjection, toProjection);
            var markers2 = new OpenLayers.Layer.Markers( "Markers" );
            markers2.addMarker(new OpenLayers.Marker(position, icon));
            //markers2.events.register('mousedown', markers2, function() { $('.main_info').html(name);  });
            map.addLayer(markers2);
        }
            markers2.events.register('mousedown', markers2, function() { $('.main_info').html(name);  });
            map.addLayer(markers2);


    });

}

//]]>*/
</script>
</head>
<body onload="drawmap()">
<div id="layer"><div class="" id="layer_layerMapnik" onclick="setLayer(0)">Mapnik</div></div>
<div id="map"></div>
<div class='main_info'></div>

thanks in advance.

Member Avatar for LastMitch

I want to achive that, when i click on a marker, on a left side in a div show name of that marker. Problem is that I always get name from last marker. I guess, that is a problem in the loop, but i don't know what... here is a code:

Is this related or connected with Google Map?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.