[OpenLayers-Users] Error in markers location on zooming

david delannoy david.delannoy at avignon.inra.fr
Tue Jun 5 11:43:39 EDT 2007


david delannoy a écrit :
> Hi all,
>
> I just realize that I have a problem with the locations on my markers 
> after zooming. First Time, when I display my map with my markers, all is 
> ok : my markers are at the right place. If I zoom in the map, some 
> markers are placed at a different location and it seems that the marker 
> is placed randomly on the map. Have you heard about a bug on zooming action?
>
> My config is :
> mapserver for the map repository
> the locations of my markers comes from an oracle Database.
>
> Best regards,
> David
>
>   
In fact, the location of the markers after zooming is not random. The 
markers are well placed in relative but not in absolute. More I zoom, 
more the markers are well placed. After few zooming, the markers seem to 
be well placed.

could anyone help me?

Here is a part of my init code :

function init(){

    /* Définition d'un ensemble de résolutions */
    var options = {
        resolutions:[1700, 850,425,222.5,111.25,55.125,27.0625,13]
    };

    var options1 = {
        resolutions:[1700, 850,425],
        minResolution: 1700,
        maxResolution: 425
    };

    /* Définition d'un résolution mini et d'une résolution maxi */
    var options2 = {
        resolutions:[222.5,111.25,55.125,27.0625,13],
        minResolution: 222.5,
        maxResolution: 13
    };
   
    var options3 = {
        resolutions:[1700, 850,425,222.5,111.25,55.125,27.0625,13],
        minResolution: 1700,
        maxResolution: 13
    };

    /* Définition de la carte de base avec ses options :
        - résolution maximum automatique
        - projection lambert II
        - unité en mètre
        - nombre de niveaux de zoom
    */
    map = new OpenLayers.Map("map",{
        maxResolution:"auto",
        maxExtent: new OpenLayers.Bounds(50000,1586013,1160964,2771788),
        units:"meters",
        projection:"EPSG:27582",
        numZoomLevels: 5
    });
    //activitylayerinit();

    /* Carte blanche de base*/
    baseLayer = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS",
                
"http://147.100.1.249/cgi-bin/mapserv?&SRS=EPSG:27572&map=climatik.map&mode=map", 

                {layers: "basic"},options);

    /* Création du layer geofla avec départements et limites de 
département*/
    geoflaLayer = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS",
           
"http://147.100.1.249/cgi-bin/mapserv?&SRS=EPSG:27572&map=climatik.map&mode=WMS", 

        {layers: "dep,nom_dep,lim", transparent: "true", format: 
"image/png"}, options1);

    /* Création du layer de la france en raster, échelle 1/1000000 */
    franceLayer = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS",
           
"http://147.100.1.249/cgi-bin/mapserv?&SRS=EPSG:27572&map=climatik.map&mode=WMS", 

        {layers: "france1000,redlim", transparent: "true", format: 
"image/png"}, options2);

    markers = new OpenLayers.Layer.Markers( "Markers", options3);
    /*geoflaLayer.events.register( 'loadend', this, decreasecounter);
    geoflaLayer.events.register( 'loadcancel', this, decreasecounter);
    geoflaLayer.events.register( 'loadstart', this, increasecounter);
    franceLayer.events.register( 'loadend', this, decreasecounter);
    franceLayer.events.register( 'loadcancel', this, decreasecounter);
    franceLayer.events.register( 'loadstart', this, increasecounter);*/

    map.addLayers([baseLayer, geoflaLayer, franceLayer, markers]);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.zoomToMaxExtent();
}

/*     Objet : Ajout d'un marker sur la carte. Un marker correspond à 
une station météorologique.
    Paramètres :
        long            longitude
        lat                latitude
        city            Commune
        place            Lieu-dit
        startDate        Date de mise en service de la station
        endDate            Date de fin d'exlpoitation de la station
        number            N° de la station
        managerName        Nom du reponsable de la station
        ownerName        Nom du propriétaire de la station
        altitude        Altitude de la station
        coefficient        Coefficient de vent
        chgDate            Date de changement de station
        type            Station INRA ou METEO-FRANCE (METEO)
*/
function addMarker(long, lat, city, place, startDate, endDate, number, 
managerName, ownerName, altitude, coefficient, chgDate, type) {
    /* Conversion from lon lat coordinates in ° to lambert II coordinates */
    var longitude = -long*0.9;
    var latitude = lat*0.9;
    convertLL2LCC (longitude,latitude);
    var lambert_longitude = getLambertX();
    var lambert_latitude = getLambertY();

    var size = new OpenLayers.Size(20,34);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    //icon.style.cursor='hand';
   
    if (type == 'INRA')
        var icon = new 
OpenLayers.Icon(contextPath+'/images/markers/RED.png',size,offset);
    else if (type == 'METEO')
        var icon = new 
OpenLayers.Icon(contextPath+'/images/markers/WHITE.png',size,offset);
    marker = new OpenLayers.Marker(new 
OpenLayers.LonLat(lambert_longitude,lambert_latitude),icon);
           
    markers.addMarker(marker);
//    marker.events.register("mouseout", marker, mouseout);
/*    marker.events.register("mouseover", marker, function(evt) {
        //if (popup != null) markers.map.removePopup(popup);
//        var icon = new 
OpenLayers.Icon(contextPath+'/images/markers/WHITE.png',size,offset);
//        alert(marker.icon.imageDiv.style.backgroundImage);
//        marker.icon.imageDiv.style.backgroundImage = 
'url(http://localhost:8080/climatik/images/markers/WHITE.png)';
//        alert(marker.icon.imageDiv.style.backgroundImage);
        //this.style.cursor='hand';
        popup = new OpenLayers.Popup(    "chicken",
                                        new 
OpenLayers.LonLat(lambert_longitude,lambert_latitude),
                                        new OpenLayers.Size(200,200),
                                        "exemple",
                                        true);
        if (city.length < 13) {
            var texte = "<table cellspacing=0 cellpadding=0 
width=\"190\" height=\"190\">";
            popup.setSize(new OpenLayers.Size(200,130));
        } else {
            var texte = "<table cellspacing=0 cellpadding=0 
width=\"290\" height=\"190\">";
            popup.setSize(new OpenLayers.Size(300,130));
        }
        texte = texte + "<tr height=\"20\"><td class=cityInPopup 
colspan=\"2\">"+city+ "</td></tr>";
        texte = texte + "<tr height=\"20\" 
class=numberInPopup><td>Numéro</td><td>"+number+ "</td></tr>";
        texte = texte + "<tr height=\"20\" 
class=placeInPopup><td>Lieu-dit</td><td>"+place+ "</td></tr>";
        texte = texte + "<tr height=\"20\" 
class=longitudeInPopup><td>Longitude</td><td>"+Math.round(longitude*100)/100+ 
"</td></tr>";
        texte = texte + "<tr height=\"20\" 
class=latitudeInPopup><td>Latitude</td><td>"+Math.round(latitude*100)/100+ 
"</td></tr>";
        texte = texte + "<tr height=\"*\"><td 
colspan=\"2\">&nbsp;</td></tr>";
        texte = texte +"</table>";
        popup.setContentHTML(texte);
        popup.setBackgroundColor("white");
        popup.setOpacity(1);
        popup.setBorder("black 1px solid");
//        marker.display(false);
        markers.map.addPopup(popup);
    });
    marker.events.register("click", marker, function(evt) {
        document.getElementById("station").innerHTML = number;
        document.getElementById("city").innerHTML = city;
        document.getElementById("place").innerHTML = place;
        document.getElementById("longitude").innerHTML = 
Math.round(longitude*100)/100;
        document.getElementById("latitude").innerHTML = 
Math.round(latitude*100)/100;
        document.getElementById("manager").innerHTML = managerName;
        document.getElementById("owner").innerHTML = ownerName;
        document.getElementById("startDate").innerHTML = startDate;
        document.getElementById("endDate").innerHTML = endDate;
        document.getElementById("chgDate").innerHTML = chgDate;
        document.getElementById("coefficient").innerHTML = coefficient;
    });*/
}



-- 
David DELANNOY
Ingénieur en Bioinformatique
Unité Agroclim
Site Agroparc
INRA AVIGNON
david.delannoy at avignon.inra.fr
04 32 72 24 13




More information about the Users mailing list