/**

* @class Advext.modules.catalogs.peta.controller.Peta
* @extends Ext.app.Controller
* requires requires
* @autor Adnan Purwanto
*
*
* Description
*
*
**/
Ext.define("Advext.modules.catalogs.peta.controller.Peta_SD",{
extend : "Advext.abstract.Controller",
views : [
"Advext.modules.catalogs.peta.view.Viewport1",
"Advext.modules.catalogs.peta.view.PetaForm",
"Advext.modules.catalogs.peta.view.SekolahGrid"
],
models: ['Advext.modules.catalogs.peta.model.Peta'],
stores: ['Advext.modules.catalogs.peta.store.Peta'],
init : function(app){
var me = this;
this.callParent();
//this.buildItems();
//var store = this.win.down('grid').getStore();
//console.log(me.win.down('grid'));
/*
store.on({
scope: me,
load : me.onPetaStoreLoad
});
*/
this.control({
'cf_mappanel': {
'beforerender': this.onMapPanelBeforeRender
}
}, this);

},
onMapPanelBeforeRender: function(mapPanel, options) {
var me = this,
grid=this.win.down('grid');
//store = grid.getStore();
var layers = [];
// OpenLayers object creating
var base = new OpenLayers.Layer.WMS(
"Indonesia",
"http://localhost:8080/geoserver/wms",
{layers: "indonesia:Bengkalis", format: "image/png"}
);
layers.push(base);
var context = {
getColor: function(feature) {
if (feature.attributes.nama_kategori_sekolah=="Negeri") {
return 'red';
}
else
{
return 'black';
}

},
getBentuk: function(feature) {
//console.log(feature.attributes.nama_kategori_s
ekolah);
if (feature.attributes.nama_tipe_sekolah=="Sekolah Umum") {
return 'square';
}
if (feature.attributes.nama_tipe_sekolah=="Sekolah Keagamaan") {
return 'star';
}
if (feature.attributes.nama_tipe_sekolah=="Sekolah Luar Biasa")
{
return 'triangle';
}
if (feature.attributes.nama_tipe_sekolah=="Sekol
ah Kejuruan") {
return 'circle';
}
}
};
var template = {
cursor: "pointer",
fillOpacity: 1,
fillColor: "${getColor}",
pointRadius: 3,
strokeWidth: 1,
strokeOpacity: 1,
strokeColor: "${getColor}",
graphicName: "${getBentuk}"
};
var style = new OpenLayers.Style(template, {context: context});
var vecLayer = new OpenLayers.Layer.Vector("vector", {

styleMap: new OpenLayers.StyleMap({
'default': style
}),
protocol: new OpenLayers.Protocol.HTTP({
url: Advext.BASE_PATH+"index.php/catalogs/peta/getSD",
format: new OpenLayers.Format.GeoJSON()
}),
strategies: [new OpenLayers.Strategy.Fixed()]
});
var selectCtrl = new OpenLayers.Control.SelectFeature(vecLayer);
// define "createPopup" function
//var bogusMarkup = "Anda klik di"+feature+"";

function createPopup(feature,nama,alamat,kategori_sekolah,jenis_
sekolah,tipe_sekolah,desa,kecamatan) {
//var feature = feature;
var popupOpts = Ext.apply({
title: nama,
location: feature,
width:300,
//html: bogusMarkup,
maximizable: true,
collapsible: true,
anchorPosition: 'auto'
});
popup = Ext.create('GeoExt.window.Popup', popupOpts);
// unselect feature when the popup
// is closed
popup.add({
xtype: "box",
autoEl: {
html: "Alamat :" + alamat + "<br>"+
"Desa :" +desa+"<br>"+
"Kecamatan :" +kecamatan+"<br>"+
"Jenjang:" +jenis_sekolah+"<br>"
+
"Status :" +kategori_sekolah+"<b
r>"+
"Jenis :" +tipe_sekolah+"<br>"
//"Jumlah Guru :" +jumlah+"<br>"
}
});
popup.on({
close: function() {
if(OpenLayers.Util.indexOf(vecLayer.sele
ctedFeatures,
this.feature) > -1) {
selectCtrl.unselect(this.feature
);
}
}
});
popup.show();
}
// create popup on "featureselected"
vecLayer.events.on({
featureselected: function(e) {
//console.log(e);
var nama = e.feature.attributes.nama_sekolah;
var alamat = e.feature.attributes.alamat;
var kategori_sekolah = e.feature.attributes.nama
_kategori_sekolah;
var jenis_sekolah = e.feature.attributes.nama_je
nis_sekolah;
var tipe_sekolah = e.feature.attributes.nama_tip
e_sekolah;
var desa = e.feature.attributes.nama_desa;
var kecamatan = e.feature.attributes.nama_kecama
tan;
//var jumlah=e.feature.attributes.jumlah;
createPopup(e.feature,nama,alamat,kategori_sekol
ah,jenis_sekolah,tipe_sekolah,desa,kecamatan);
}
});
layers.push(vecLayer);
// manually bind store to layer
//store.bind(vecLayer);
//grid.getSelectionModel().bind(vecLayer);
mapPanel.map.addLayers(layers);
// some more controls
/*
mapPanel.map.addControls([new OpenLayers.Control.SelectFeature(
vecLayer, {
//autoActivate: true,
onSelect: function(evt) {
//var store = me.getSummitsStore();
console.log(store);
//store.fireEvent('update', store, store.getByFeature(feature));
}
})]);
mapPanel.map.addControls([new OpenLayers.Control.DragFeature(vecLayer, {
autoActivate: true,
onComplete: function(feature, px) {
//var store = me.getSummitsStore();
store.fireEvent('update', store, store.getByFeature(feature));
}
})]);
*/
// for dev purpose
mapPanel.map.addControl(selectCtrl);
selectCtrl.activate();
map = mapPanel.map;
mapPanel = mapPanel;
},
onLaunch: function() {
var me = this;
ctrl = this;
},
onPetaStoreLoad: function(store, records) {
// do custom stuff on summits load if you want, for example here we
// zoom to summits extent
var dataExtent = store.layer.getDataExtent();
if (dataExtent) {
store.layer.map.zoomToExtent(dataExtent);
}
},
setViewport : function(){
this.win.add(Ext.create("Advext.modules.catalogs.peta.view.Viewport1"));
}
});