IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

IGN API Géoportail Discussion :

IGN Maps and Firefox


Sujet :

IGN API Géoportail

  1. #1
    Membre à l'essai
    Inscrit en
    Septembre 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 21
    Points : 14
    Points
    14
    Par défaut IGN Maps and Firefox
    Problem with click control code at: https://api.ign.fr/geoportail/api/do...er/center.html.

    OpenLayers click control does not work e.g. www.system.co.uk/igntest.html

    It only works with a reference to OpenLayers as at www.system.co.uk/igntestb.html including

    <script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>

    Is there a simple reason?

    Also the click control and API do not always seem to work in Firefox.

    Any suggestions in French or English?

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 35
    Points : 29
    Points
    29
    Par défaut
    Hi,

    If your problem is the error message "OpenLayers is not defined" then it's completely normal.

    On your page, if you remove the reference to <script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script> then firefox does not have any reference to OpenLayers when it reaches the line "ClickControl= OpenLayers.Class( OpenLayers.Control, {" because the OpenLayers API is not yet loaded.

    When you use the GeoportalApi with <script type="text/javascript" src="http://api.ign.fr/geoportail/api?v=1.0beta4-e&key=MY_KEY&instance=myMap"> you first load a small javascript file that will then load the full GeoportalExtended script containing OpenLayers.

    What you have to do is "delay" the javascript analysis of ClickControl creation, maybe using a function like this http://pastie.org/610755. You will see in that code the function "initClickControlClass()" wrapping your ClickControl creation, and the call to this new function inside the "initGeoportalMap" function.


    Note : The funny thing in your current page using http://openlayers.org/api/OpenLayers.js is that this script is never used. It is loaded on the browser, preventing the error message, but all his code will be overloaded when GeoportalExtended.js will be downloaded by the browser.

  3. #3
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut Onload magic
    A workaround is as follows :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script
            type="text/javascript"
            src="http://api.ign.fr/geoportail/api?v=VERSION&amp;key=YOUR_LICENSE&amp;instance=myMap&amp;">
        <!--
          -->
        </script>
        <script type="text/javascript">
        <!--
            function initGeoportalMap() {
                // call on body's onLoad
                OpenLayers.Control.Click= OpenLayers.Class( OpenLayers.Control, {
                    defaultHandlerOptions:{
                        'single': true,
                        'double': false,
                        'pixelTolerance': 0,
                        'stopSingle': false,
                        'stopDouble': false
                    },
    
                    /**
                     * Constructor
                     */
                    initialize: function(options) {
                        OpenLayers.Control.prototype.initialize.apply(this,arguments);
                        this.handlerOptions= OpenLayers.Util.extend({},this.defaultHandlerOptions);
                        this.handler= new OpenLayers.Handler.Click(
                            this, {'click': this.trigger}, this.handlerOptions);
                    },
    
                    /**
                     * APIMethod: trigger
                     */
                    trigger: function(e) {
                        var lonlat= this.map.getLonLatFromViewPortPx(e.xy).transform(
                            this.map.getProjection(), OpenLayers.Projection.CRS84
                        );
                        alert("You clicked near " + lonlat.lon + "N, " + lonlat.lat + " E");
                    }
                });
    
                // the map must be created and configured here
                geoportalLoadmyMap("layerDiv", "normal" );
                myMap.addGeoportalLayers(myMap.allowedGeoportalLayers);
                // creating and inserting the new control
                var myClick= new OpenLayers.Control.Click();
                myMap.getMap().addControl(myClick);
                myClick.activate();
            }
          -->
        </script>
      </head>
      <body>
        <div id="layerDiv" style="width:800px;height:600px;"></div>
      </body>
    </html>
    Including the class definition in the callback seems to prevent "OpenLayers is not defined" (especially with IE)

  4. #4
    Membre à l'essai
    Inscrit en
    Septembre 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 21
    Points : 14
    Points
    14
    Par défaut
    Thanks for response. I have changed the code at www.system.co.uk/igntestb.html. The error stops in firefox but still does not work. The control works fine in Safari, IE and Chrome.

  5. #5
    Expert confirmé
    Homme Profil pro
    Ingénieur cartographe
    Inscrit en
    Avril 2009
    Messages
    3 173
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur cartographe
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2009
    Messages : 3 173
    Points : 4 224
    Points
    4 224
    Par défaut
    Just tested with FF2, FF3 and FF3.5 works pretty weel on all of them ...

  6. #6
    Membre à l'essai
    Inscrit en
    Septembre 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 21
    Points : 14
    Points
    14
    Par défaut
    Thanks for your help again. I wrote programmes for astro navigation 20 years ago for old-fashioned Basic and Excel and script seems much more complicated.

    The full map with gps etc is at www.system.co.uk/sysmaps_ign.html which is one of four maps (UK OS, CloudMade/OpenStreetMap, IGN and BKG Germany). This IGN one still does not work in Firefox but I will look at it later

Discussions similaires

  1. Ext.Ajax.request : IE8 OK and FIREFOX/CHROME erreur
    Par locas dans le forum Ext JS / Sencha
    Réponses: 1
    Dernier message: 03/04/2011, 20h01
  2. [Google Code] SVG inline pour firefox comme Google Maps
    Par moumoune65 dans le forum APIs Google
    Réponses: 2
    Dernier message: 01/07/2008, 17h07
  3. drag and drop march pas sous firefox+joomla!
    Par tecap dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 02/10/2007, 10h16
  4. utilisateur FireFox sur google map
    Par aityahia dans le forum Firefox
    Réponses: 0
    Dernier message: 19/09/2007, 12h10
  5. Map sous Firefox
    Par amika dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 22/02/2006, 17h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo