yavsc/web/Scripts/jquery.googlemaps.min.js

1 line
30 KiB
JavaScript

$.fn.GoogleMapEditor = function (options) { function addSearchBox(e) { var t = "q" + e.id; $(e.container).parent().prepend('<input id="' + t + '" style="margin-top:4px" type="text" placeholder="Search Box" />'); var n = document.getElementById(t); if (n != null) { e.controls[google.maps.ControlPosition.TOP_RIGHT].push(n); var r = new google.maps.places.SearchBox(n); google.maps.event.addListener(r, "places_changed", function () { var t = r.getPlaces(); var n = new google.maps.LatLngBounds; for (var i = 0, s; s = t[i]; i++) { n.extend(s.geometry.location) } e.fitBounds(n); e.setZoom(15) }); google.maps.event.addListener(e, "bounds_changed", function () { var t = e.getBounds(); r.setBounds(t) }) } } function addStylesList(map) { if (settings.editMode) { var selectId = "s" + map.id; $(map.container).parent().prepend('<select id="' + selectId + '" class="map-style" />'); var select = document.getElementById(selectId); $(select).append($("<option>", { value: JSON.stringify([]), text: "GoogleMaps Default" })); $.getJSON(settings.stylesPath, function (e) { $(e).each(function (e, t) { $(select).append($("<option>", { value: t.json, text: t.name })) }) }); if (select != null) { map.controls[google.maps.ControlPosition.TOP_LEFT].push(select); $(select).change(function () { map.setOptions({ mapTypeId: "Styled" }); var styledMapType = new google.maps.StyledMapType(eval($(this).val()), { name: "Styled" }); map.mapTypes.set("Styled", styledMapType); settings.style = eval($(this).val()); saveToJson(map) }) } } } function addFitBoundsButton(e) { var t = "c" + e.id; $(e.container).parent().prepend('<input id="' + t + '" class="fit-bound" type="button" title="Fit bounds" />'); var n = document.getElementById(t); if (n != null) { e.controls[google.maps.ControlPosition.TOP_CENTER].push(n); $(n).click(function () { var t = getMapLocationsBounds(e); if (t != null) { e.fitBounds(t); saveToJson(e) } }) } } function addCurrentLocationButton(e) { var t = "l" + e.id; $(e.container).parent().prepend('<input id="' + t + '" class="current-location" type="button" title="My Location" />'); var n = document.getElementById(t); if (n != null) { e.controls[google.maps.ControlPosition.TOP_CENTER].push(n); $(n).click(function () { if (navigator.geolocation) { var t = $(e.container).next(); t.width($(e.container).width()); t.height($(e.container).height()); t.offset({ top: $(e.container).offset().top, left: $(e.container).offset().left }); t.fadeIn("slow"); navigator.geolocation.getCurrentPosition(function (n) { t.fadeOut("fast"); if (settings.editMode) { var r = new Location([new Coordinate(n.coords.latitude, n.coords.longitude)], google.maps.drawing.OverlayType.MARKER, "", "", "", "", "", ""); initMapObject(e, r); e.locations.push(r); var i = new google.maps.LatLngBounds(new google.maps.LatLng(r.Coordinates[0].Latitude, r.Coordinates[0].Longitude)); e.fitBounds(i); e.setZoom(15); new google.maps.event.trigger(r.Overlay, "click"); saveToJson(e) } else { var i = new google.maps.LatLngBounds(new google.maps.LatLng(n.coords.latitude, n.coords.longitude)); e.fitBounds(i); e.setZoom(15) } }, function (e) { alert("Unable to fetch your current location!\n" + e); t.fadeOut("fast") }) } }) } } function arePopupTemplatesLoaded() { if (popupTemplateCircle != null && popupTemplateRectangle != null && popupTemplateMarker != null && popupTemplatePolyline != null && popupTemplatePolygon != null) { return true } else { return false } } function loadPopupTemplates() { $.ajax({ url: settings.editTemplatesPath + "popup-template-circle.html", method: "GET", dataType: "text html", success: function (e) { popupTemplateCircle = e } }); $.ajax({ url: settings.editTemplatesPath + "popup-template-rectangle.html", method: "GET", dataType: "text html", success: function (e) { popupTemplateRectangle = e } }); $.ajax({ url: settings.editTemplatesPath + "popup-template-marker.html", method: "GET", dataType: "text html", success: function (e) { popupTemplateMarker = e } }); $.ajax({ url: settings.editTemplatesPath + "popup-template-polyline.html", method: "GET", dataType: "text html",