<?php $lang=Yii::app()->session['lang'] ;
header('Content-Type:text/javascript'); 
?>
 
var map;
	  var zoom=10;
	  var initial_lon = 36.2850706;
	  var initial_lat = 33.520296;
	  var markers = new Array();
	  var branchIconStyle = new ol.style.Style({
        image: new ol.style.Icon({
            src: "https://albaraka.com.sy/images/branch.png",
        })
    });
	function initMap()
	{
		
     map = new ol.Map({
        target: 'map',
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM()
            })
        ],
        view: new ol.View({
            center: ol.proj.fromLonLat([initial_lon, initial_lat]),
            zoom: 17
        })
	 });
	 console.log(map);
  var locations = [<?php 
  $branches=Branch::model()->findAll();
  $coun=1;
  foreach($branches as $branche)
  {
      if($lang=='ar'){
	  echo "['".$branche->name_ar."',".$branche->longitude.",".$branche->latitudes.",".$coun."],";
      }else
      {
          echo "['".$branche->name_en."',".$branche->longitude.",".$branche->latitudes.",".$coun."],";
      }
  }
  ?>
     
];
    var marker, i;

    for (i = 0; i < locations.length; i++) { 
	var lonLat = ol.proj.fromLonLat([locations[i][1], locations[i][2]]);
        var feature = new ol.Feature({
          geometry: new ol.geom.Point(lonLat),
        });
		feature.setStyle(branchIconStyle);
		markers[i] = feature;

      }

var layer = new ol.layer.Vector({
        source: new ol.source.Vector({
          features: markers
        })
      });

      map.addLayer(layer);
	  }


	function newLocation(newLat,newLng)
{
	setTimeout(function(){map.updateSize();}, 500);
	map.getView().setCenter(ol.proj.transform([newLng, newLat], 'EPSG:4326','EPSG:3857'));
}

$(window).on('load',initMap);