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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/* The API key to use */
var APIkey= "CLE API";
*/
viewer= null;
/* Function: initMap - Load the application. Called when all information have been loaded by <loadAPI>() */
function initMap() {
/***** Traduction *****/
translate();
/***** Options *****/
var options= {
mode:'normal',
territory:'FXX',
proxy:'assets/proxy.php?url=' // Configurer les 2 variables dans le fichier PHP...
};
viewer= new Geoportal.Viewer.Default('viewerDiv', OpenLayers.Util.extend(
options,
// variable contenant la configuration des clefs API remplie par <Geoportal.GeoRMHandler.getConfig>
window.gGEOPORTALRIGHTSMANAGEMENT===undefined? {'apiKey':APIkey} : gGEOPORTALRIGHTSMANAGEMENT)
);
if (!viewer) {
// En cas de problème...
OpenLayers.Console.error(OpenLayers.i18n('new.instance.failed'));
return;
}
/***** Layers *****/
viewer.addGeoportalLayers(['GEOGRAPHICALGRIDSYSTEMS.MAPS','ORTHOIMAGERY.ORTHOPHOTOS'], {
'GEOGRAPHICALGRIDSYSTEMS.MAPS': {visibility:true, opacity:1},
'ORTHOIMAGERY.ORTHOPHOTOS': {visibility:false, opacity:1}
});
//viewer.setLayersPanelVisibility(false);
viewer.openLayersPanel(false);
/***** Centrage de la carte *****/
viewer.getMap().setCenterAtLonLat(6.359381720692934,44.92211050248759,13);
/***** Catalogue des couches *****/
//viewer.getMap().addControl(new Geoportal.Control.LayerCatalog());
/***** Récupération de la barre d'outils *****/
var tbx= viewer.getMap().getControlsByClass("Geoportal.Control.ToolBox")[0];
var panel= new Geoportal.Control.Panel({
div:OpenLayers.Util.getElement(tbx.id+"_search")
});
viewer.getMap().addControls([panel]);
/***** Barre de mesures *****/
var measurebar= new Geoportal.Control.MeasureToolbar({
div: OpenLayers.Util.getElement(tbx.id+"_measure"),
displaySystem:(viewer.getMap().getProjection().getProjName()=="longlat"?"geographic":"metric"),
targetElement: OpenLayers.Util.getElement(tbx.id+"_meares"),
elevationOptions: {
active: true,
targetElement: null
},
elevationPathOptions: {
active: false
},
});
viewer.getMap().addControl(measurebar);
// Désactivation des icônes de mesures non désirés
viewer.getMap().getControlsByClass("Geoportal.Control.MeasureToolbar")[0].controls[2].deactivate;
viewer.getMap().getControlsByClass("Geoportal.Control.MeasureToolbar")[0].controls[2].div.style.display="none";
viewer.getMap().getControlsByClass("Geoportal.Control.MeasureToolbar")[0].controls[1].deactivate;
viewer.getMap().getControlsByClass("Geoportal.Control.MeasureToolbar")[0].controls[1].div.style.display="none";
/***** Recherches par lieu *****/
var GeoNames= new Geoportal.Control.LocationUtilityService.GeoNames(
new Geoportal.Layer.OpenLS.Core.LocationUtilityService("PositionOfInterest:OPENLS;Geocode", {
maximumResponses:100,
formatOptions: {}
}),{
drawLocation:true,
setZoom: function() {return 16}, // Réglage du niveau de zoom
autoCompleteOptions: {},
}
);
panel.addControls([GeoNames]);
/***** Recherches par adresse *****/
var Geocode= new Geoportal.Control.LocationUtilityService.Geocode(
new Geoportal.Layer.OpenLS.Core.LocationUtilityService( "StreetAddress:OPENLS;Geocode", {
maximumResponses:100,
formatOptions: {}
}),{
drawLocation:true,
setZoom: Geoportal.Control.LocationUtilityService.GeoNames.setZoomForBDNyme,
autoCompleteOptions: {}
}
);
panel.addControls([Geocode]);
/* Début de la gestion du clic */
OpenLayers.Control.Click= OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
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);
},
trigger: function(e) {
var lonlat= this.map.getLonLatFromViewPortPx(e.xy).transform(
this.map.getProjection(), OpenLayers.Projection.CRS84);
alert(lonlat.lon + " N - " + lonlat.lat + " E");
var centerLonlat = this.map.getCenter().transform(this.map.getProjection(), OpenLayers.Projection.CRS84);
console.log('Centre de la carte', centerLonlat.lon, centerLonlat.lat);
}
});
// création et insertion du nouveau contrôleur
var monClic= new OpenLayers.Control.Click({autoActivate:true});
viewer.getMap().addControl(monClic);
/* Fin de la gestion du clic */
}
/* Function: loadAPI - Load the configuration related with the API keys. Called on "onload" event.
Call <initMap>() function to load the interface. */
function loadAPI() {
// On attend que les classes soient chargées
if (checkApiLoading('loadAPI();',['OpenLayers','Geoportal','Geoportal.Viewer','Geoportal.Viewer.Default'])===false) {
return;
}
Geoportal.GeoRMHandler.getConfig([APIkey], null,null, {
onContractsComplete: initMap
});
}
/* Assignation de la fonction à appeler lors de la levée de l'évènement "onload" */
window.onload= loadAPI; |
Partager