-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
159 lines (129 loc) · 5.01 KB
/
main.js
File metadata and controls
159 lines (129 loc) · 5.01 KB
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
window.onload = init
function init(){
const defaultCenter = [8567632.418462602, 1216139.9929669618]
const map = new ol.Map({
view: new ol.View({
zoom: 1,
projection: 'EPSG:3857',
center: defaultCenter,
extent:[7671084.328048979, 653002.4943791988, 9229601.321082244, 1647148.8951564338 ]
}),
layers:[
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target:"openlayers-map"
})
// Waterfalls
const LocationBlue = new ol.style.Icon({
src:'./data/icon/g280.png',
oppacity:1,
scale:0.04
})
const Locationselect = new ol.style.Icon({
src: './data/icon/locationred.svg',
oppacity:1,
scale:0.05
})
const fallstyle = new ol.style.Style({
image:LocationBlue
})
const fallstyleselected = new ol.style.Style({
image: Locationselect
})
const kerWaterfalls = new ol.layer.Vector({
source:new ol.source.Vector({
format:new ol.format.GeoJSON(),
url:"./data/Geojson/KeralaWaterfalls.geojson"
}),
title:'Waterfalls',
style: fallstyle
})
map.addLayer(kerWaterfalls)
const overlayContainerelement = document.querySelector('.overlay-container')
const overlaylayer = new ol.Overlay({
element:overlayContainerelement
})
map.addOverlay(overlaylayer);
//Map click logic
const naviElements = document.querySelector(".column-navigation");
const sitenameElement = document.getElementById('fallname');
const siteImageElement = document.getElementById('infoimage');
const mapView = map.getView();
map.on('singleclick',function(evnt){
map.forEachFeatureAtPixel(evnt.pixel,function(feature,layer){
let sitename = feature.get('fallname');
let naviElement = naviElements.children.namedItem(sitename);
//console.log(naviElement)
mainLogic(feature,naviElement)
})
})
function mainLogic(feature,clickedNewElemnt){
let currentActiveElemnt = document.querySelector('.active');
//console.log(currentActiveElemnt)
currentActiveElemnt.className = currentActiveElemnt.className.replace('active','')
clickedNewElemnt.className = 'active'
// Selection
let fallfeatures = kerWaterfalls.getSource().getFeatures();
fallfeatures.forEach(function(feature){
feature.setStyle(fallstyle)
})
// Home button
if(clickedNewElemnt.id === 'Home'){
mapView.animate({center: defaultCenter},{zoom:4})
sitenameElement.innerHTML = 'Gorgeous Waterfalls of Kerala'
siteImageElement.setAttribute('src','./data/images/kerala_waterfalls.jpg')
}
// Change image
else{
feature.setStyle(fallstyleselected)
let featurecoordinate = feature.get('geometry').getCoordinates();
mapView.animate({center: featurecoordinate},{zoom:9})
let NameOfFall = feature.get('fallname');
let NameOfImage = feature.get('ImageName')
let NameOfDistrict = feature.get('District')
sitenameElement.innerHTML = NameOfFall + ' : ' + NameOfDistrict;
siteImageElement.setAttribute('src','./data/images/kerala waterfalls/'+NameOfImage+'.jpg');
}
}
// NavBar
const navElements = document.querySelectorAll('.column-navigation > img');
for(let navElement of navElements){
navElement.addEventListener('click',function(event2){
let clickednavelement = event2.currentTarget;
let clickednavelementID = clickednavelement.id;
let Kerfallfeature = kerWaterfalls.getSource().getFeatures();
Kerfallfeature.forEach(function(feature){
let fallfeaturename = feature.get('fallname');
if(clickednavelementID === fallfeaturename){
mainLogic(feature, clickednavelement);
}
})
if(clickednavelementID==='Home'){
mainLogic(undefined,clickednavelement)
}
})
}
//Map pointer
const overlayFeatName = document.getElementById('waterfall-name');
map.on('pointermove', function(e){
overlaylayer.setPosition(undefined)
map.getViewport().style.cursor = 'default'
map.forEachFeatureAtPixel(e.pixel,function(feature,layer){
let coordinateclicked = e.coordinate;
let WFName = feature.get('Name');
overlaylayer.setPosition(coordinateclicked);
overlayFeatName.innerHTML = WFName;
map.getViewport().style.cursor = 'pointer'
},{
layerFilter: function(layerCandidate){
return layerCandidate.get('title') === 'Waterfalls'
}
}
)
})
/*map.on("click",function(e){
console.log(e.coordinate)
})*/
}