Commit f97f0a91 by Uros Spasojevic

- implemented add marker to database

- implemented load marker from database
- removed ugly setTimeout
- listening to mapready event
parent a8efed89
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -30,7 +30,10 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -30,7 +30,10 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
width: 300, width: 300,
center: { center: {
lat: marker.lat, // Marker latitude lat: marker.lat, // Marker latitude
lng: marker.lng // Marker longitude lng: marker.lng, // Marker longitude
marker: {
title: marker.title
}
}, },
mapOptions: { mapOptions: {
mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeId: google.maps.MapTypeId.ROADMAP,
...@@ -59,37 +62,48 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -59,37 +62,48 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
click: function(evt) { click: function(evt) {
var me = this; var me = this;
var map = me.getView();
var key = dbref.ref().child('data').push().key;
var map = me.getView(), var marker = {
marker = { access: key,
lat: evt.latLng.lat(), lat: evt.latLng.lat(),
lng: evt.latLng.lng(), lng: evt.latLng.lng(),
title: "Marrakesh", title: "",
url: 'https://en.wikipedia.org/wiki/Marrakesh', description: "",
animation: google.maps.Animation.DROP animation: google.maps.Animation.DROP
}; };
var updates = {};
updates['/data/'+key] = marker;
me.markers.push(map.addMarker(marker)); dbref.ref().update(updates);
/* TODO; request to add */
/*
var newData = {
lat: 10.5,
lng: 10.5,
title: 'gtfo',
url: 'rtfm.com'
};
var ddd = dbref.ref().child('data').push().key; markers.push(map.addMarker(marker));
},
var updates = {}; mapready: function() {
var me = this;
var map = me.getView();
google.maps.event.addListener(map.gmap, 'click', function(e) {
map.fireEvent('click', e);
});
updates['/data/'+ddd] = newData; Ext.Ajax.request({
url: dataURL,
scope:this,
success: function(data) {
var info = Ext.decode(data.responseText);
dbref.ref().update(updates); if (info != null) {
*/ Ext.Object.each(info, function(obj, index) {
// index.animation = google.maps.Animation.DROP;
markers.push(map.addMarker(index));
});
}
}
});
} }
} }
} }
...@@ -99,27 +113,6 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', { ...@@ -99,27 +113,6 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
var me = this, var me = this,
map = me.getView(); map = me.getView();
me.markers = [];
/* TODO: request to get */
/*
Ext.Ajax.request({
url: testURL,
scope:this,
success: function (data) {
var info = Ext.decode(data.responseText);
}
});
*/
setTimeout(function() {
google.maps.event.addListener(map.gmap, 'click', function(e) {
map.fireEvent('click', e);
});
}, 5000);
}, },
doSomething: function() { doSomething: function() {
......
Ext.define('Evoksi.view.evoksi.EvoksiModel', { Ext.define('Evoksi.view.evoksi.EvoksiModel', {
extend: 'Ext.app.ViewModel', extend: 'Ext.app.ViewModel',
alias: 'viewmodel.evoksi', alias: 'viewmodel.evoksi'
stores: {
Markers: {
storeId: 'Markers',
autoLoad: true,
fields: ['lat', 'lng', 'title', 'url'],
proxy: {
type: 'ajax',
url: testURL,
reader: {
type: 'json',
rootProperty: 'data'
}
}
// data: [
// {lat: 47.605568, lng: -122.335907, title: "Seattle", url: 'https://en.wikipedia.org/wiki/Seattle'},
// {lat: 41.877120, lng: -87.633971, title: "Chicago", url: 'https://en.wikipedia.org/wiki/Chicago'},
// {lat: 40.711556, lng: -74.009213, title: "New York", url: 'https://en.wikipedia.org/wiki/New_York'},
// {lat: 51.516596, lng: -0.128383, title: "London", url: 'https://en.wikipedia.org/wiki/London'},
// {lat: 55.764156, lng: 37.617370, title: "Moscow", url: 'https://en.wikipedia.org/wiki/Moscow'},
// {lat: 37.558558, lng: 126.989548, title: "Seoul", url: 'https://en.wikipedia.org/wiki/Seoul'},
// {lat: 35.682805, lng: 139.756735, title: "Tokyo", url: 'https://en.wikipedia.org/wiki/Tokyo'},
// {lat: -33.867334, lng: 151.208053, title: "Sydney", url: 'https://en.wikipedia.org/wiki/Sydney'},
// {lat: -33.922646, lng: 18.407470, title: "Cape Town", url: 'https://en.wikipedia.org/wiki/Cape_Town'},
// {lat: -23.550230, lng: -46.628265, title: "Sao Paulo", url: 'https://en.wikipedia.org/wiki/S%C3%A3o_Paulo'}
// ]
}
}
}); });
...@@ -22,8 +22,10 @@ ...@@ -22,8 +22,10 @@
}; };
firebase.initializeApp(config); firebase.initializeApp(config);
var dbRoot = config.databaseURL; var dbRoot = config.databaseURL;
var testURL = dbRoot + '/data.json'; var dataURL = dbRoot + '/data.json';
var pollURL = dbRoot + '/evoksi-8d7a4.json';
var dbref = firebase.database(); var dbref = firebase.database();
var markers = [];
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment