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', {
width: 300,
center: {
lat: marker.lat, // Marker latitude
lng: marker.lng // Marker longitude
lng: marker.lng, // Marker longitude
marker: {
title: marker.title
}
},
mapOptions: {
mapTypeId: google.maps.MapTypeId.ROADMAP,
......@@ -59,37 +62,48 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
click: function(evt) {
var me = this;
var map = me.getView();
var key = dbref.ref().child('data').push().key;
var map = me.getView(),
marker = {
var marker = {
access: key,
lat: evt.latLng.lat(),
lng: evt.latLng.lng(),
title: "Marrakesh",
url: 'https://en.wikipedia.org/wiki/Marrakesh',
title: "",
description: "",
animation: google.maps.Animation.DROP
};
me.markers.push(map.addMarker(marker));
/* 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;
var updates = {};
updates['/data/'+key] = marker;
dbref.ref().update(updates);
updates['/data/'+ddd] = newData;
markers.push(map.addMarker(marker));
},
dbref.ref().update(updates);
*/
mapready: function() {
var me = this;
var map = me.getView();
google.maps.event.addListener(map.gmap, 'click', function(e) {
map.fireEvent('click', e);
});
Ext.Ajax.request({
url: dataURL,
scope:this,
success: function(data) {
var info = Ext.decode(data.responseText);
if (info != null) {
Ext.Object.each(info, function(obj, index) {
// index.animation = google.maps.Animation.DROP;
markers.push(map.addMarker(index));
});
}
}
});
}
}
}
......@@ -98,27 +112,6 @@ Ext.define('Evoksi.view.evoksi.EvoksiController', {
init: function () {
var me = this,
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);
},
......
Ext.define('Evoksi.view.evoksi.EvoksiModel', {
extend: 'Ext.app.ViewModel',
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'}
// ]
}
}
alias: 'viewmodel.evoksi'
});
......@@ -22,8 +22,10 @@
};
firebase.initializeApp(config);
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 markers = [];
</script>
<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