var map = null;
var type = 'polygons';
var customControl = L.Control.extend({
options: {
position: 'topright'
},
onAdd: function (map) {
var container = L.DomUtil.create('input');
container.type = "button";
if(type == 'polygons'){
container.title = "Вместо значков будет отмечена территория";
container.value = "Показать территорию";
}
if(type == 'points'){
container.title = "Вместо очертаний будут значки, рекомендуется для iPad, планшетов и смартфонов";
container.value = "Показать метки";
}
container.style.backgroundColor = 'white';
container.style.backgroundSize = "30px 30px";
container.style.width = '200px';
container.style.height = '30px';
container.onmouseover = function(){
container.style.cursor = 'pointer';
}
container.onclick = function(){
if(type == 'polygons'){
getPolygons();
}else{
getPoints();
}
}
return container;
}
});
function getPoints(){
if(map){
map.remove();
}
map = L.map('map', {
center: [38.166778, -0.611072],
zoom: 10,
maxZoom: 18
});
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
type = 'polygons';
map.addControl(new customControl());
$.get("/lib/getMarker.php?action=map&d=search&month=jun", function(data) {
var markers = null;
markers = L.markerClusterGroup({
showCoverageOnHover: false,
maxClusterRadius: 20
});
var myIcon = L.icon({
iconSize: [25, 25],
iconUrl: '/images/dom.png',
});
for (marker in data) {
var lat = parseFloat(data[marker].lat);
var lng = parseFloat(data[marker].lng);
markers.addLayer(L.marker([lat,lng],{
icon: myIcon
}).bindPopup(''+data[marker].tip+data[marker].price+''));
map.addLayer(markers);
};
}, 'json');
}
function getPolygons(){
if(map){
map.remove();
}
map = L.map('map', {
center: [38.166778, -0.611072],
zoom: 10 });
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
type = 'points';
map.addControl(new customControl());
$.get("/lib/getMarker.php?action=map&d=search&month=jun", function(data) {
for (marker in data) {
var points = [];
if(data[marker].points){
for (point in data[marker].points) {
var lat = parseFloat(data[marker].points[point].lat);
var lng = parseFloat(data[marker].points[point].lng);
points.push([lat, lng]);
}
}
var customPolygone = L.Polygon.extend({
options: {
url: data[marker].url,
}
});
var polygon = new customPolygone(points, {
color: '#000000',
opacity: 0.8,
weight: 1,
fillColor: '#00FF00',
fillOpacity: 0.5
}).bindTooltip(data[marker].tip+data[marker].price, {direction: 'top'}).addTo(map);
polygon.on("click", function (event) {
id=window.open("","_blank");
id.location.href=this.options.url;
});
polygon.on("mouseout", function() {
this.closeTooltip();
});
polygon.on("mouseover", function(event) {
this.openTooltip();
});
};
}, 'json');
}
getPoints();