mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
200 lines
6.4 KiB
JavaScript
200 lines
6.4 KiB
JavaScript
/* Location Data */
|
|
var getCountry = $('.country-data').data('content');
|
|
if(getCountry == ""){getCountry = default_country;}
|
|
var getCity = $('.city-data').data('content');
|
|
if(getCity == ""){getCity = default_city;}
|
|
var getDistrict = $('.district-data').data('content');
|
|
if(getDistrict == ""){getDistrict = default_district;}
|
|
var getNeighborhood = $('.neighborhood-data').data('content');
|
|
if(getNeighborhood == ""){getNeighborhood = default_neighborhood;}
|
|
var getVillage = $('.village-data').data('content');
|
|
var citySelectName = "city";
|
|
var districtSelectName = "district";
|
|
var neighborhoodSelectName = "neighborhood";
|
|
var villageSelectName = "village";
|
|
var countrySelectName = "country";
|
|
jQuery( document ).ready(function( $ ) {
|
|
|
|
}).promise().done(function() {
|
|
$('select[name="country"]').val(getCountry);
|
|
}).promise().done(function() {
|
|
var cat = getCountry;
|
|
var level = 1;
|
|
var name = citySelectName;
|
|
Locations(cat, level, name);
|
|
}).promise().done(function() {
|
|
var cat = getCity;
|
|
var level = 2;
|
|
var name = districtSelectName;
|
|
Locations(cat, level, name);
|
|
}).promise().done(function() {
|
|
var cat = getDistrict;
|
|
var level = 3;
|
|
var name = neighborhoodSelectName;
|
|
Locations(cat, level, name);
|
|
}).promise().done(function() {
|
|
var cat = getNeighborhood;
|
|
var level = 4;
|
|
var name = villageSelectName;
|
|
Locations(cat, level, name);
|
|
});
|
|
|
|
$(document).on('change', 'select[name="'+countrySelectName+'"]', function(){
|
|
var cat = $(this).val();
|
|
var level = 1;
|
|
var name = citySelectName;
|
|
Locations(cat, level, name);
|
|
});
|
|
$(document).on('change', 'select[name="'+citySelectName+'"]', function(){
|
|
var cat = $(this).val();
|
|
var level = 2;
|
|
var name = districtSelectName;
|
|
Locations(cat, level, name)
|
|
});
|
|
$(document).on('change', 'select[name="'+districtSelectName+'"]', function(){
|
|
var cat = $(this).val();
|
|
var level = 3;
|
|
var name = neighborhoodSelectName;
|
|
Locations(cat, level, name)
|
|
});
|
|
$(document).on('change', 'select[name="'+neighborhoodSelectName+'"]', function(){
|
|
var cat = $(this).val();
|
|
var level = 4;
|
|
var name = villageSelectName;
|
|
Locations(cat, level, name)
|
|
});
|
|
function Locations(cat, level, name){
|
|
$.ajax({
|
|
type: "GET",
|
|
data: "cat=" + cat + "&level=" + level,
|
|
url: "/class/ajax",
|
|
success: function(msg){
|
|
hideLoader()
|
|
$('select[name="'+name+'"]').find('option').remove();
|
|
$('select[name="'+name+'"]').append('<option value="">Choose an option...</option>');
|
|
$.each(msg, function(key, value){
|
|
$('select[name="'+name+'"]').append('<option value="'+value.id+'">'+value.name+'</option>');
|
|
});
|
|
},
|
|
beforeSend: function () {
|
|
showLoader()
|
|
}
|
|
}).promise().done(function() {
|
|
setLocation(level)
|
|
if(level==3){
|
|
console.log(level);
|
|
haritaIslem(0);
|
|
}
|
|
});
|
|
}
|
|
|
|
function setLocation(level){
|
|
if(level == 1){
|
|
$('select[name="'+citySelectName+'"]').val(getCity);
|
|
}else if(level == 2){
|
|
$('select[name="'+districtSelectName+'"]').val(getDistrict);
|
|
}else if(level == 3){
|
|
$('select[name="'+neighborhoodSelectName+'"]').val(getNeighborhood);
|
|
}else if(level == 4){
|
|
$('select[name="'+villageSelectName+'"]').val(getVillage);
|
|
}
|
|
}
|
|
|
|
var locationedit = $('input[name="map_Val"]').val();
|
|
if(locationedit){
|
|
var coordcenter = new google.maps.LatLng(locationedit);
|
|
}else{
|
|
var coordcenter = new google.maps.LatLng(38.9573415, 35.2415759);
|
|
}
|
|
console.log(locationedit);
|
|
var mapOptions = {
|
|
|
|
center: coordcenter,
|
|
zoom: 6,
|
|
mapTypeId: google.maps.MapTypeId.STREET
|
|
};
|
|
var secildi = 0;
|
|
var marker;
|
|
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
|
|
|
|
function haritaIslem() {
|
|
var str = '';
|
|
if ($('select[name="'+countrySelectName+'"]').val() != "") {
|
|
str += $('select[name="'+countrySelectName+'"] :selected').text() + ' ';
|
|
}
|
|
if ($('select[name="'+citySelectName+'"]').val() != "") {
|
|
str += $('select[name="'+citySelectName+'"] :selected').text() + ' ';
|
|
}
|
|
if ($('select[name="'+districtSelectName+'"]').val() != "") {
|
|
str += $('select[name="'+districtSelectName+'"] :selected').text() + ' ';
|
|
}
|
|
if ($('select[name="'+neighborhoodSelectName+'"]').val() != "") {
|
|
str += $('select[name="'+neighborhoodSelectName+'"] :selected').text() + ' ';
|
|
}
|
|
|
|
if (!str) {
|
|
return true;
|
|
}
|
|
str = str.replace(/\(.+\)/g, "").replace(' ', ' ');
|
|
|
|
var geocoder = new google.maps.Geocoder();
|
|
geocoder.geocode({'address': str}, function (results, status) {
|
|
if (status == google.maps.GeocoderStatus.OK) {
|
|
var searchLoc = results[0].geometry.location;
|
|
var lat = results[0].geometry.location.lat();
|
|
var lng = results[0].geometry.location.lng();
|
|
var latlng = new google.maps.LatLng(lat, lng);
|
|
var bounds = results[0].geometry.bounds;
|
|
|
|
if (bounds != undefined) {
|
|
map.fitBounds(bounds);
|
|
}
|
|
}
|
|
if ($('select[name="'+neighborhoodSelectName+'"]').val() != "" && $('select[name="'+neighborhoodSelectName+'"]').val() != 0 && secildi == 0) {
|
|
secildi = 1;
|
|
google.maps.event.addListener(map, 'click', function (event) {
|
|
placeMarker(event.latLng);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function placeMarker(location) {
|
|
console.log(location);
|
|
var lat = location.lat();
|
|
var lng = location.lng();
|
|
$(".mapVal").val(lat + "," + lng);
|
|
if (marker) {
|
|
marker.setPosition(location);
|
|
$("#map").data(lat+","+lng);
|
|
} else {
|
|
marker = new google.maps.Marker({
|
|
position: location,
|
|
map: map
|
|
|
|
});
|
|
}
|
|
}
|
|
|
|
editMarket();
|
|
function editMarket() {
|
|
console.log($('input[name="map_Val"]'));
|
|
var locationedit = $('input[name="map_Val"]').val();
|
|
if($('input[name="map_Val"]')){
|
|
var lat = locationedit.split(",")[0];
|
|
var lng = locationedit.split(",")[1];
|
|
var location = new google.maps.LatLng(lat, lng);
|
|
$(".mapVal").val($('input[name="map_Val"]'));
|
|
if (marker) {
|
|
marker.setPosition(location);
|
|
$("#map").data(lat+","+lng);
|
|
} else {
|
|
marker = new google.maps.Marker({
|
|
position: location,
|
|
map: map
|
|
|
|
});
|
|
}
|
|
}
|
|
}
|