-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
258 lines (227 loc) · 6.29 KB
/
app.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
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
//Harita ekleme
var script = document.createElement("script");
script.src = "https://openlayers.org/en/v3.20.1/build/ol.js";
script.type = "text/javascript";
script.defer = true;
script.async = true;
//Kayıtlı koordinat
var ankara = ol.proj.transform(
[32.7445451, 39.9305464],
"EPSG:4326",
"EPSG:3857"
);
//harita layers ayarlama
var layers = [];
layers.push(
new ol.layer.Tile({
visible: true,
preload: Infinity,
source: new ol.source.BingMaps({
key: "AsZpNEEdyW1wZ3__26CoXTYbsTOrw8Wgy4hTM1SoklCWfHosKzoJ4awh28CXsJMs",
imagerySet: "AerialWithLabelsOnDemand",
}),
})
);
//database
firebase.initializeApp({
apiKey: "AIzaSyBIfFSU2EffY572LKT7H0-efyylfZAcJg4",
authDomain: "geodotask.firebaseapp.com",
databaseURL: "https://geodotask.firebaseio.com",
projectId: "geodotask",
storageBucket: "geodotask.appspot.com",
messagingSenderId: "287984193571",
appId: "1:287984193571:web:ff7a056e1eb41ad405e196",
});
var db = firebase.firestore();
//popup ekleme
var container = document.getElementById("popup");
var content = document.getElementById("popup-content");
var closer = document.getElementById("popup-closer");
//overlay ayarları
var overlay = new ol.Overlay({
element: container,
autoPan: true,
autoPanAnimation: {
duration: 250,
},
});
//Harita ayarları
var map = new ol.Map({
layers: layers,
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false,
}),
}),
target: "map",
overlays: [overlay],
view: new ol.View({
center: ankara,
zoom: 6,
}),
});
//Pan butonu
var panToAnkara = document.getElementById("pan-to-ankara");
panToAnkara.addEventListener(
"click",
function () {
var pan = ol.animation.pan({
duration: 2000,
source: /** @type {ol.Coordinate} */ (map.getView().getCenter()),
});
map.beforeRender(pan);
map.getView().setCenter(ankara);
map.getView().setZoom(6);
},
false
);
var collection = new ol.Collection();
var source = new ol.source.Vector({
wrapX: false,
features: collection,
useSpatialIndex: false,
});
var vector = new ol.layer.Vector({
source: source,
});
//point ekleme
var savebuton = document.getElementById("save");
var featurething = new ol.Feature({
name: "Point",
});
var point;
function addPoint() {
point = new ol.interaction.Draw({
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: "#ffcc33",
width: 2,
}),
image: new ol.style.Circle({
// //nokta
radius: 5,
fill: new ol.style.Fill({
color: "#ffcc33",
}),
}),
}),
source: source,
type: "Point",
});
vector.setMap(map);
map.addInteraction(point);
point.setActive(false);
}
//popup kapatma
closer.onclick = function () {
container.style.display = "none";
closer.blur();
return false;
};
function activePoint() {
point.setActive(true);
map.on("click", function tıkla(e) {
var coordinate = e.coordinate;
var hdms = ol.coordinate.toStringHDMS(
ol.proj.transform(coordinate, "EPSG:3857", "EPSG:4326")
);
content.innerHTML =
"<p>Buraya tıkladınız:</p><code>" +
hdms +
"</code>" +
"<br></br>" +
'<label>Kapı No Giriniz: </label> <input type="text" id="kapı-no">' +
"<br></br>" +
'<label>Mahalle Kodunu Giriniz: </label> <input type="text" id="mahalle-kod">' +
"<br></br>" +
'<button id="save" value="KAYIT ">Kaydet</button>';
container.style.display = "block";
overlay.setPosition(coordinate);
var savebuton = document.getElementById("save");
savebuton.addEventListener("click", function (e) {
var kapnovalue;
kapnovalue = document.getElementById("kapı-no").value;
var mahallekodvalue;
mahallekodvalue = document.getElementById("mahalle-kod").value;
container.style.display = "none";
closer.blur();
//verileri database'e kayıt etme
db.collection("data")
.add({
Kapıno: kapnovalue,
mahallekodu: mahallekodvalue,
koordinatlar: hdms,
})
.then(function (docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function (error) {
console.error("Error adding document: ", error);
});
var coodi3 = coordinate[0];
var boylamdüz = ol.coordinate.toStringHDMS(
ol.proj.transform(coodi3, "EPSG:3857", "EPSG:4326")
);
var hdms3 = ol.coordinate.toStringHDMS(
ol.proj.transform(coordinate, "EPSG:3857", "EPSG:4326")
);
// console.log(hdms.replace(','));
// return false;
e.preventDefault();
});
map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
point.setActive(false);
});
return;
});
}
addPoint();
point.on("drawend", function cizim(e) {
var currentFeature = e.feature;
point.setActive(false);
});
//Polygon çizimi
var polygon;
function addPolygon() {
polygon = new ol.interaction.Draw({
source: source,
type: "Polygon",
});
map.addInteraction(polygon);
polygon.setActive(false);
}
function activePolygon() {
//point.setActive(false);
polygon.setActive(true);
}
addPolygon();
polygon.on("drawend", function (e) {
var currentFeature2 = e.feature;
polygon.setActive(false);
});
var pointsource = vector.getSource();
pointsource.addFeatures(collection);
//verileri çekme
var dbread= document.getElementById("db-read");
dbread.addEventListener("click",function(){
db.collection("data")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log("alınan koordinatlar:" + doc.data().koordinatlar+" koordinatı alınan kapı no,mahalle kodu: "+doc.data().Kapıno+" , "+doc.data().mahallekodu);
var readdata = doc.data().koordinatlar;
var template = "Coordinate is ({x},{y}).";
// markerekle(readdata);
});
});
})
// function markerekle(readdata){
// this.readdata= readdata;
// console.log("aswfdasas "+readdata)
// var lonLat = new ol.Coordinate( readdata )
// var zoom=8;
// var markers = new ol.Layer.Markers( "Markers" );
// map.addLayer(markers);
// markers.addMarker(new OpenLayers.Marker(lonLat));
// map.setCenter (lonLat, zoom);
// }