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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
|
<?php
function lirefichier() {
$monfichier = fopen(utf8_decode("fichiersGPX/".$_POST['Nom_Rando'].".gpx"), "r");
$tampon = fread($monfichier, filesize(utf8_decode("fichiersGPX/".$_POST['Nom_Rando'].".gpx")));
$tampon = str_replace(array("\n","\r","'"),"",$tampon);
echo $tampon;
fclose($monfichier);
}
?>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" debug="true">
<head>
<title>RandoBase-Affichage-Edition</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="/API version 1.3/fichiersCSS/affiche_edite.css"/>
</head>
<body>
<?php include("menu.php"); ?>
<div id="carte"><div id="viewerDiv"></div></div>
<script type="text/javascript" src="http://depot.ign.fr/geoportail/api/js/1.3/lib/geoportal/lib/Geoportal.js"><!-- --></script>
<script type="text/javascript">
<!--
function openPopup(f) {
if (f) {
// Préparation du html inclus dans le popup
html = "<div style='font-size:.75em; font-family:\"Courier New, monospace\"; font-weight:bold; color:#000000;'>";
if (f.attributes['name'] != null) {
html = html + f.attributes['name'];
}
if (f.attributes['desc'] != null) {
html = html + '<br /><br />' + f.attributes['desc'];
}
if (f.attributes['ele'] != null) {
html = html + '<br /><br />' + f.attributes['ele'];
}
html = html + "</div>";
var popup = new OpenLayers.Popup.FramedCloud(
"chicken",
f.geometry.getBounds().getCenterLonLat(),
null,
html,
null,
true,
closeBoxCallback = function(){
viewer.getMap().removePopup(popup);
//popup.destroy();
popup = null;
}
);
f.popup = popup;
f.popup.panMapIfOutOfView= false;//true by default in OpenLayers.Popup.FramedCloud
f.autoSize= true;
f.maxSize= new OpenLayers.Size(200,200);
f.minSize= new OpenLayers.Size(100,100);
f.popup.contentDiv.style.overflow= 'auto';
viewer.getMap().addPopup(popup, true);
}
}
/*
* Fonction qui ajoute l'altitude au fichier gpx avant l'enregistrement.
*/
function ajoutAltitude (datagpx) {
if (window.DOMParser) {
parser=new DOMParser();
xmlDoc=parser.parseFromString(datagpx,"text/xml");
}
else {// Internet Explorer
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(datagpx);
}
// Pour les trkpt
trkpt = xmlDoc.getElementsByTagName('trkpt');
nbTrkpt = trkpt.length;
if (trkpt && nbTrkpt>0) {
for (i=0;i<nbTrkpt;i++) {
lon= trkpt[i].attributes['lon'].value;
lat= trkpt[i].attributes['lat'].nodeValue;
elevation(xmlDoc, trkpt[i], lat, lon);
}
}
// Pour les rtept
rtept = xmlDoc.getElementsByTagName('rtept');
nbRtept = rtept.length;
if (rtept && nbRtept>0) {
for (j=0;j<nbRtept;j++) {
lon= rtept[j].attributes['lon'].nodeValue;
lat= rtept[j].attributes['lat'].nodeValue;
elevation(xmlDoc, rtept[j], lat, lon);
}
}
// Pour les wpt
wpt = xmlDoc.getElementsByTagName('wpt');
nbWpt = wpt.length;
if (wpt && nbWpt>0) {
for (l=0;l<nbWpt;l++) {
lon= wpt[l].attributes['lon'].value;
lat= wpt[l].attributes['lat'].value;
elevation(xmlDoc, wpt[l], lat, lon);
}
}
// Fonctions communes aux trkpt rtept et wpt
function altitudeFailure() {
alert("echec de la recherche d'altitude");
}
function removeXmlns(feature) {
var ele = feature.getElementsByTagName("ele")[0];
if (ele.hasAttribute("xmlns")) {
ele.removeAttribute("xmlns");
}
}
function elevation(xmlDoc, feature, lat, lon) {
var rz= new OpenLayers.Request.GET({
url:'http://ws.geonames.org/srtm3JSON',
params : {lng:lon,lat:lat,username:"trukker"},
async: false,
success:function(r) {
if (feature.getElementsByTagName("ele")[0]) {
removeXmlns(feature);
return;
}
if (!r.responseText || r.responseText.length==0) { altitudeFailure(); return; }
eval('var data= '+r.responseText+';');
var altitude= data.srtm3;
if (altitude.length==0) { altitudeFailure(); return; }
altitude= parseFloat(altitude);
eleAlt=xmlDoc.createElement('ele');
if (feature.getElementsByTagName("name")[0]) {
feature.insertBefore(eleAlt, feature.getElementsByTagName("name")[0]);
}
else {
feature.appendChild(eleAlt);
}
txtEle=xmlDoc.createTextNode(altitude);
eleAlt.appendChild(txtEle);
},
failure:altitudeFailure
});
}
function serializeXmlNode(xmlNode) {
if (typeof window.XMLSerializer != "undefined") {
return (new window.XMLSerializer()).serializeToString(xmlNode);
} else if (typeof xmlNode.xml != "undefined") {
return xmlNode.xml;
}
return "";
}
var xmlString = serializeXmlNode(xmlDoc);
return xmlString;
}
/*
* Petite fonction pour envoyer la trace à la page de traitement et d'enregistrement en simulant la méthode POST.
* Vous pourrez trouver la source et des explications ici :
* http://camille.descombes.free.fr/blog/index.php/envoyer-des-donnees-post-en-javascript/
*/
var page = 'traitementGPX.php';
function openWithPostData(page,datagpx) {
var form = document.createElement('form');
form.setAttribute('action', page);
form.setAttribute('method', 'post');
var inputvar = document.createElement('input');
inputvar.setAttribute('type', 'text');
inputvar.setAttribute('name', 'datagpx');
inputvar.setAttribute('value', datagpx);
form.appendChild(inputvar);
document.body.appendChild(form);
form.submit();
}
/*
* Fonction de sauvegarde
*/
this.saveFeatures = function () {
/*
* Les 2 lignes suivantes désactivent l'outil de modification, lors de l'appui sur le bouton de suvegarde.
* Cela évite l'enregistrement des points virtuels ajoutés pour les modifications
*/
var mfCntrl= viewer.getMap().getControlsByClass('OpenLayers.Control.ModifyFeature')[0];
mfCntrl.deactivate(mfCntrl.layer.selectedFeatures[0]);
/*
* section qui transforme la couche gpx en fichier gpx
*/
Geoportal.Format.GPX.v1_1.prototype.writers.gpx.link= function(obj) {
var onlineResource= (obj.attributes || obj.metadata || obj).onlineResource;
if (onlineResource) {
var node= this.createElementNSPlus('link', {
uri:this.gpxns,
attributes:{
href:onlineResource.href
}
});
this.writeNode('text', onlineResource, node);
var mc= this.mappingContext;
this.mappingContext= "link";
this.writeNode('type', onlineResource, node);
this.mappingContext= mc;
return node;
}
return null;
};
var gpxF= new Geoportal.Format.GPX({
version:'1.1',
stringifyOutput:true,
internalProjection: viewer.map.getProjection().clone(),
externalProjection: new OpenLayers.Projection('EPSG:4326')
});
var datagpx= gpxF.write(vectors.features);
openWithPostData(page,ajoutAltitude(datagpx));
}
function deserialize() {
var in_options = {
internalProjection: viewer.map.getProjection().clone(),
externalProjection: new OpenLayers.Projection('EPSG:4326')
};
formats = new Geoportal.Format.GPX(in_options);
var element = '<?php lirefichier(); ?>';
var features = formats.read(element);
var bounds;
if(features) {
if(features.constructor != Array) {
features = [features];
}
for(var i=0; features.length > i; ++i) {
if (!bounds) {
bounds = features[i].geometry.getBounds();
} else {
bounds.extend(features[i].geometry.getBounds());
}
}
vectors.addFeatures(features);
viewer.getMap().zoomToExtent(bounds);
}
}
var viewer= null;
function initGeoportalMap() {
viewer= new Geoportal.Viewer.Default(
"viewerDiv",
OpenLayers.Util.extend({
mode:'normal',
territory:'FXX',
proxy:'proxyign2.php?url='},
window.gGEOPORTALRIGHTSMANAGEMENT===undefined? {apiKey:['4091047292815514941']}:gGEOPORTALRIGHTSMANAGEMENT
)
);
if (!viewer) {
OpenLayers.Console.error('Creation de la carte echouee');
return;
}
viewer.addGeoportalLayers(['ORTHOIMAGERY.ORTHOPHOTOS:WMSC', 'GEOGRAPHICALGRIDSYSTEMS.MAPS:WMSC'],
{'ORTHOIMAGERY.ORTHOPHOTOS:WMSC':{visibility:false},
global:{opacity:1.0}});
vectors = new OpenLayers.Layer.Vector("Vector Layer",
{
styleMap:new OpenLayers.StyleMap({
"default": new OpenLayers.Style(
OpenLayers.Util.applyDefaults({
fillColor: "#FF358B",
fillOpacity: 0.75,
strokeColor: "#FF0033",
strokeWidth: 2,
graphicZIndex: "${zIndex}",
graphicName: "circle",
pointRadius: 6,
label:"${getName}",
labelAlign: "rb",
labelXOffset: -20,
labelYOffset: -20,
labelBackgroundColor: "#FFCC00",
labelBorderColor: "black",
labelBorderSize: "1px",
fontColor: "black",
fontWeight: "bold",
fontSize: "12px",
fontFamily: "Courier New, monospace",
cursor: "pointer"
},OpenLayers.Feature.Vector.style["default"]),{
context:{
getName: function(f) {
if (f.attributes['typeName']=='wpt') {
return f.attributes['name'];
}
return '';
}
}
}),
"select": new OpenLayers.Style(
OpenLayers.Util.applyDefaults({
fillColor: "#AEEE00",
fillOpacity: 0.75,
strokeColor: "#FFCC00",
strokeWidth: 3,
pointRadius: 8,
cursor: "pointer"
},OpenLayers.Feature.Vector.style["select"])
)
})
}
);
viewer.getMap().addLayer(vectors);
var panelControls = [
new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.Point, {
title : 'ajout point',
displayClass: 'olControlDrawFeaturePoint'
}),
new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.Path, {
title : 'ajout ligne',
displayClass: 'olControlDrawFeaturePath'
}),
new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.Polygon, {
title : 'ajout polygone',
displayClass: 'olControlDrawFeaturePolygon'
}),
new Geoportal.Control.DeleteFeature(vectors, {
title: "Suppression",
displayClass: 'olControlDeleteFeature'
}),
new OpenLayers.Control.Button({
uis:[OpenLayers.UI],
uiOptions:{
title:"Sauvegarde",
displayClass:"olControlSaveFeatures"
},
trigger:saveFeatures
}),
new OpenLayers.Control.DragFeature(vectors,{
title: "Déplacement",
displayClass: 'olControlDragFeature'
}),
new OpenLayers.Control.ModifyFeature(vectors,{
title: "Modification",
displayclass: 'olControlModifyFeature'
})
];
var toolbar = new OpenLayers.Control.Panel({
displayClass: 'customEditingToolbar',
allowDepress: true
});
toolbar.addControls(panelControls);
viewer.getMap().addControl(toolbar);
deserialize();
var popupCtrl= new OpenLayers.Control.SelectFeature(vectors);
viewer.getMap().addControl(popupCtrl);
popupCtrl.activate();
popupCtrl.onSelect = function (feature) {
openPopup(feature);
}
popupCtrl.onUnselect = function (feature) {
viewer.getMap().removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
/*
* Astuce pour changer la couleur et l'opacité des popup framedCloud qui sont basés sur l'image cloud-popup-relative.png.
*
* Si vous chargez l'api depuis votre serveur vous pouvez aussi le faire par CSS
*/
OpenLayers.ImgPath = "geoportal/img/";
}
if (window.__Geoportal$timer===undefined) {
var __Geoportal$timer= null;
}
/**
* Function: checkApiLoading
* Assess that needed classes have been loaded.
*
* Parameters:
* retryClbk - {Function} function to call if any of the expected classes
* is missing.
* clss - {Array({String})} list of classes to check.
*
* Returns:
* {Boolean} true when all needed classes have been loaded, false otherwise.
*/
function checkApiLoading(retryClbk,clss) {
if (__Geoportal$timer!=null) {
//clearTimeout: cancels the timer "__Geoportal$timer" before its end
//clearTimeout: annule le minuteur "__Geoportal$timer" avant sa fin
window.clearTimeout(__Geoportal$timer);
__Geoportal$timer= null;
}
/**
* It may happen that the init function is executed before the API is loaded
* Addition of a timer code that waits 300 ms before running the init function
*
* Il se peut que l'init soit exécuté avant que l'API ne soit chargée
* Ajout d'un code temporisateur qui attend 300 ms avant de relancer l'init
*/
var f;
for (var i=0, l= clss.length; i<l; i++) {
try {
f= eval(clss[i]);
} catch (e) {
f= undefined;
}
if (typeof(f)==='undefined') {
__Geoportal$timer= window.setTimeout(retryClbk, 300);
return false;
}
}
return true;
}
/**
* Function: loadAPI
* Load the configuration related with the API keys.
* Called on "onload" event.
* Call <initMap>() function to load the interface.
*/
function loadAPI() {
// wait for all classes to be loaded
// on attend que les classes soient chargées
if (checkApiLoading('loadAPI();',['OpenLayers','Geoportal','Geoportal.Viewer','Geoportal.Viewer.Default'])===false) {
return;
}
// load API keys configuration, then load the interface
// on charge la configuration de la clef API, puis on charge l'application
Geoportal.GeoRMHandler.getConfig(['4091047292815514941'], null,null, {
onContractsComplete: initGeoportalMap
});
}
// assign callback when "onload" event is fired
// assignation de la fonction à appeler lors de la levée de l'évènement
// "onload"
window.onload= loadAPI;
-->
</script>
</body>
</html> |
Partager