Last active
August 29, 2015 14:03
-
-
Save MhdSyrwan/ed88e621f1da048c344e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function ($) { | |
//MAPS | |
app.maps.tools = { | |
centerOnUser: function () { | |
return { | |
getgeoloc: { | |
callback: function (latLng) { | |
if (latLng) { | |
$(this).gmap3({ | |
map: { | |
options: { | |
center: latLng, | |
zoom: 15 | |
} | |
} | |
}); | |
} | |
} | |
} | |
} | |
}, | |
addMarker: function () { | |
var $map = app.maps.map; | |
// add marker and store it | |
$map.gmap3({ | |
marker: { | |
latLng: app.maps.current_marker.latLng, | |
options: { | |
draggable: true | |
//,icon: new google.maps.MarkerImage("http://maps.gstatic.com/mapfiles/icon_green" + (isM1 ? "A" : "B") + ".png") | |
//TODO : change color by issue state | |
}, | |
events: { | |
dragend: function (marker) { | |
//updateMarker(marker); | |
}, | |
rightclick: function(map, event,data){ | |
var current = app.maps.current_marker = event; | |
current.id = data.id; // attaching marker id | |
app.maps.marker_menu.open(current); | |
} | |
}, | |
callback: function (marker) { | |
//updateMarker(marker); | |
} | |
} | |
}); | |
}, | |
createMenu: function () { | |
var $map = app.maps.map; | |
menu = new Gmap3Menu($map); | |
// MENU : ITEM 1 | |
menu.add("Add a Marker", "centerHere", | |
function () { | |
menu.close(); | |
app.maps.tools.addMarker(); | |
}); | |
// MENU : ITEM 3 | |
menu.add("Zoom in", "zoomIn", | |
function () { | |
var map = $map.gmap3("get"); | |
map.setZoom(map.getZoom() + 1); | |
menu.close(); | |
}); | |
// MENU : ITEM 4 | |
menu.add("Zoom out", "zoomOut", | |
function () { | |
var map = $map.gmap3("get"); | |
map.setZoom(map.getZoom() - 1); | |
menu.close(); | |
}); | |
return menu; | |
}, | |
createMarkerMenu: function () { | |
var marker_menu = new Gmap3Menu(app.maps.map); | |
marker_menu.add("Remove Marker", "remove", function () { | |
marker_menu.close(); | |
app.maps.map.gmap3({clear:{name:'marker', id:app.maps.current_marker.id}}); | |
}); | |
return marker_menu; | |
} | |
}; | |
$("form#save_markers_form").submit(function () { | |
var markers_array = app.maps.map.gmap3({get:{name:'marker', all:true}}); | |
markers_array = markers_array.map(function(v){return {lat:v.position.lat(),lng:v.position.lng()}}); | |
var output = JSON.stringify(markers_array); | |
$("#markers").val(output); // #markers is hidden input html element in the form (used to put json marker data) | |
return true; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment