/*
* jQuery Plugin: JQuery GoogleMaps
* https://github.com/dejanstojanovic/JQuery-GoogleMaps
* Version 2.2.4
*
* Copyright (c) 2014 Dejan Stojanovic (http://dejanstojanovic.net)
*
* Released under the MIT license
*/
$.fn.GoogleMapEditor = function (options) {
var defaults = {
editMode: true, /* Allow editiong on the map */
editTemplatesPath: "../src/html/", /* Editor layouts html files location */
markerPinsPath: "../src/img/pin/", /* Custom marker icons path */
markerPinFiles: ["flag-azure.png", /* List of files to be available from custom marker icons path */
"flag-green.png",
"needle-pink.png",
"niddle-green.png",
"pin-azure.png",
"pin-green.png",
"pin-pink.png"],
drawingBorderColor: "#ff0000", /* Default border drawing color when drawing is initiated */
drawingBorderWidth: 2, /* Default border drawing width when drawing is initiated */
drawingFillColor: "#ffff00", /* Default fill drawing color when drawing is initiated */
zoom: 13, /* Default map zoom if not defined when initiating */
center: { /* Default map center */
latitude: 25.0417,
longitude: 55.2194
},
width: 800, /* Map width. If not set then container width will be used*/
height: 400, /* Map height. If not set then container height will be used*/
language: "en", /* List of supported languages https://spreadsheets.google.com/spreadsheet/pub?key=0Ah0xU81penP1cDlwZHdzYWkyaERNc0xrWHNvTTA1S1E&gid=1 */
singleLocation: false, /* Allow only one location present on the map */
searchBox: true, /* Add search box to the map */
richtextEditor: true, /* Use TinyMce editor for location messages */
drawingTools: ["marker", /* Tools to be availale for editing */
"polyline",
"polygon",
"circle",
"rectangle"],
zoomControl: true, /* Show zoom control */
panControl: true, /* Show pan control */
scaleControl: true, /* Show scale on the map */
streetViewControl: true, /* Show street view control */
scrollWheel: false, /* Use mouse wheel to zoom in and zoom out*/
style: null, /* Build custom syles at http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html */
stylesPath: "../src/styles.json", /* Url of JSON file with map styles definitions. Enpowered by snazzymaps.com */
locations: [], /* Locations to be loaded with the map */
dataChange: null, /* Event raised when anything on the map changed */
locationClick: null, /* Event raised when a location on the map is clicked */
locationNew: null, /* Event raised when new location is added on the map */
locationDelete: null, /* Event raised when location is deleted from the map */
locationMove: null /* Event reaised when location is moved on the map to a different position */
}
var settings = $.extend({}, defaults, options);
var tinyMceUrl = "//tinymce.cachefly.net/4.0/tinymce.min.js";
var mapApiUrl = "//maps.googleapis.com/maps/api/js?sensor=false&callback=mapApiLoaded&libraries=drawing,places";
if (settings.language != "") {
mapApiUrl += "&language=" + settings.language;
}
var popupTemplateCircle = null;
var popupTemplateRectangle = null;
var popupTemplateMarker = null;
var popupTemplatePolyline = null;
var popupTemplatePolygon = null;
var selector = $(this);
if ((typeof google !== "undefined" && google !== null ? google.maps : void 0) == null) {
$.getScript(mapApiUrl);
window.mapApiLoaded = function () {
selector.each(function (index) {
var container = selector.get(index);
if (settings.width == defaults.width) {
if ($(container).width() <= 0) {
$(container).width(defaults.width);
}
}
else {
$(container).width(settings.width);
}
if (settings.height == defaults.height) {
if ($(container).height() <= 0) {
$(container).height(defaults.height);
}
}
else {
$(container).height(settings.height);
}
initializeGoogleMapEditor(container);
});
};
}
else {
selector.each(function (index) {
var container = selector.get(index);
initializeGoogleMapEditor(container);
});
}
function addSearchBox(map) {
var inputId = "q" + map.id;
$(map.container).parent().prepend("");
var input = document.getElementById(inputId);
if (input != null) {
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(input);
var searchBox = new google.maps.places.SearchBox(input);
google.maps.event.addListener(searchBox, 'places_changed', function () {
var places = searchBox.getPlaces();
var bounds = new google.maps.LatLngBounds();
for (var i = 0, place; place = places[i]; i++) {
bounds.extend(place.geometry.location);
}
map.fitBounds(bounds);
map.setZoom(15);
});
google.maps.event.addListener(map, 'bounds_changed', function () {
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
}
}
function addStylesList(map) {
if (settings.editMode) {
var selectId = "s" + map.id;
$(map.container).parent().prepend("");
var select = document.getElementById(selectId);
$(select).append($('