forked from 3liz/lizmap-javascript-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ign-altimetrie.js
153 lines (138 loc) · 5.14 KB
/
ign-altimetrie.js
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
var lizmapIgnAltimetrie = function() {
//IGN KEYS MUST BE DEFINED inside credencial json file !
var ignServiceKey;
var ignServiceUrl;
var ignEntryPoints;
var help = 'Veuillez cliquer sur la carte <br />pour connaitre l\'altitude';
lizMap.events.on({
'uicreated': function(e) {
lizMap.addDock('ign_altimetrie', 'Altimétrie', 'minidock', help, 'icon-screenshot');
var credencial = OpenLayers.Util.urlAppend(
lizUrls.media,
OpenLayers.Util.getParameterString({
"repository": lizUrls.params.repository,
"project": lizUrls.params.project,
"path": "media/js/".concat(lizUrls.params.project,"/credencial.json")
})
);
$.getJSON(credencial, function(json) {
ignServiceKey = json.ignServiceKey;
ignServiceUrl = json.ignServiceUrl;
ignEntryPoints = json.services.alti.ignEntryPoints;
initIgnAltiView();
});
}
});
function getIgnJsonResponse(service, params, aCallback){
var fullUrl = '';
var ep = ignEntryPoints;
var fullUrl = ignServiceUrl + ignServiceKey + ep;
$.get(
fullUrl,
params,
function(data) {
if(aCallback){
aCallback(data);
}
}
,'json'
);
}
function getIgnAlti(lon,lat){
//IGN Web Service only allows coordinates in 4326
if(lizMap.map.projection.projCode != "EPSG:4326"){
var fromProjection = new OpenLayers.Projection(lizMap.map.projection.projCode);
var toProjection = new OpenLayers.Projection("EPSG:4326");
var convertedPoint = new OpenLayers.LonLat(lon, lat);
convertedPoint.transform(fromProjection, toProjection);
lon = convertedPoint.lon;
lat = convertedPoint.lat;
}
var qParams = {
'lon': lon,
'lat':lat,
'srs': lizMap.map.projection.projCode
}
getIgnJsonResponse('alti', qParams, function(data){
var alt = data['elevations'][0]['z'];
$('#ign_altimetrie .menu-content').html('Altitude :'.concat(' ',alt));
});
}
function initIgnAltiView() {
var map = lizMap.map;
//Layer to display clic location
var ignLayerAlti = map.getLayersByName('ignLayerAlti');
if ( ignLayerAlti.length == 0 ) {
ignLayerAlti = new OpenLayers.Layer.Vector('ignLayerAlti',{
styleMap: new OpenLayers.StyleMap({
graphicName: 'cross',
pointRadius: 6,
fill: true,
fillColor: 'white',
fillOpacity: 1,
stroke: true,
strokeWidth: 2,
strokeColor: 'red',
strokeOpacity: 1
})
});
map.addLayer(ignLayerAlti);
ignLayerAlti.setVisibility(true);
}
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function(e) {
ignLayerAlti.destroyFeatures();
$('#ign_altimetrie .menu-content').html( 'Altitude :'.concat(' ', '...') );
var lonlat = map.getLonLatFromPixel(e.xy);
ignLayerAlti.addFeatures([
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
)
]);
getIgnAlti(lonlat.lon,lonlat.lat)
}
});
var click = new OpenLayers.Control.Click();
map.addControl(click);
lizMap.events.on({
minidockopened: function(e) {
if ( e.id == 'ign_altimetrie' ) {
click.activate();
}
},
minidockclosed: function(e) {
if ( e.id == 'ign_altimetrie' ) {
$('#ign_altimetrie .menu-content').html(help);
ignLayerAlti.destroyFeatures();
ignLayerAlti.setVisibility(false);
click.deactivate();
}
}
});
}
return {
'serviceKey': ignServiceKey,
'serviceUrl': ignServiceUrl,
'entryPoints': ignEntryPoints
};
}();