var Map = Class.create ({ initialize: function (element, options) { this.element = $(element) if (this.compatible()) { this.options = Object.extend ({ center: { ns: Map.DEFAULT_NS, ew: Map.DEFAULT_EW }, zoom: Map.DEFAULT_ZOOM, type: G_NORMAL_MAP }, options) this.load() } else this.element.update ('

Nie udało się załadować mapy — nieobsługiwana przeglądarka.

') this.__place_edit_setup() }, get_bbox: function() { with (this.map.getBounds()) { return { n: getNorthEast().lat(), e: getNorthEast().lng(), s: getSouthWest().lat(), w: getSouthWest().lng() } } }, dump_geometry: function() { return "#{lat},#{lng},#{zoom}".interpolate ({ lat: this.map.getCenter().lat(), lng: this.map.getCenter().lng(), zoom: this.map.getZoom() }) }, restore_geometry: function (geometry) { var g = geometry.substr (1).split (',') this.map.setCenter (new GLatLng (parseFloat (g[0]), parseFloat (g[1]))) this.map.setZoom (parseInt (g[2])) }, remove_all_hover_titles: function() { Mapcia.places && Mapcia.places.list.each (function (place) { place.marker.mouseout() }) }, compatible: function() { return typeof GBrowserIsCompatible == 'function' && GBrowserIsCompatible() }, load: function (position_ns) { this.default_point = new GLatLng (this.options.center.ns, this.options.center.ew) this.map = new GMap2 (this.element) this.map.enableContinuousZoom() this.map.enableScrollWheelZoom() this.map.setCenter (this.default_point, this.options.zoom, this.options.type) this.map.addControl (new GSmallMapControl()) this.map.addControl (new GMapTypeControl()) GEvent.addListener (this.map, 'dragstart', this.__dragstart.bind (this)) if (Mapcia.action != 'places#create') this.map.addControl (new Map.NewPlaceControl()) GEvent.addDomListener (this.map, 'click', this.__map_click.bind (this)) GEvent.addListener (this.map, 'singlerightclick', this.__map_right_click.bind (this)) }, show_geocode_marker: function (draggable, position, reload_on_drop) { var bbox = this.get_bbox() var point = new GLatLng ((bbox.n + bbox.s) / 2.0, (bbox.e + bbox.w) / 2.0) if ($('place_geo_ns') && $('place_geo_ew') && $F('place_geo_ns') && $F('place_geo_ew')) { point = new GLatLng ($F('place_geo_ns'), $F('place_geo_ew')) this.map.setZoom (Map.EDIT_ZOOM) this.map.setCenter (point) } if (position) { point = new GLatLng (position.ns, position.ew) this.map.setZoom (Map.EDIT_ZOOM) this.map.setCenter (point) } // Add draggable marker: if (this.geocode_marker) this.map.removeOverlay (this.geocode_marker, true) this.geocode_marker = new GMarker (point, { icon: Map.PLACE_ICON, draggable: draggable }) this.geocode_marker.reload_on_drop = reload_on_drop // Marker drop event: GEvent.addListener (this.geocode_marker, 'dragend', this.__dragend.bind (this)) this.map.addOverlay (this.geocode_marker) this.__update_inputs() if (draggable && reload_on_drop && Mapcia.action != 'places#create') Mapcia.flash.notice ('Przeciągnij znacznik na docelowe miejsce') }, hide_geocode_marker: function() { if (this.geocode_marker) this.map.removeOverlay (this.geocode_marker, true) }, geocode: function (text, after) { Map.geocode (text, function (position) { this.move_geocode_marker (position) after && after() }.bind (this)) }, move_geocode_marker: function (position) { if (position.ns && position.ew) { var point = new GLatLng (position.ns, position.ew) Mapcia.map.geocode_marker.setPoint (point) Mapcia.map.map.setZoom (Map.EDIT_ZOOM) Mapcia.map.map.panTo (point) this.__update_inputs() } else { Mapcia.flash.notice ('Nie udało się zlokalizować miejsca.') } }, create_marker: function (position) { var point = new GLatLng (position.ns, position.ew) var marker = new GMarker (point, { icon: Map.PLACE_ICON, draggable: false, zIndexProcess: function (marker) { return 99999999 } }) GEvent.addListener (marker, "mouseover", marker.mouseover.bind (marker)) GEvent.addListener (marker, "mouseout", marker.mouseout.bind (marker)) this.map.addOverlay (marker) return marker }, destroy_marker: function (marker) { this.map.removeOverlay (marker) }, __place_edit_setup: function() { this.place_edit = {} var map = this if (this.place_edit.geocode_by_address_button = $('geocode_by_address_button')) { this.place_edit.geocode_by_address_button.momencik = new Momencik ('geocode_by_address_indicator', 'Momencik…') this.place_edit.geocode_by_address_button.observe ('click', function() { this.momencik.wait() map.geocode ($F('place_street') + ', ' + $F('place_city') + ', Poland', function() { this.momencik.done() }.bind (this)) }) } if (this.place_edit.geocode_by_text_button = $('geocode_by_text_button')) { this.place_edit.geocode_by_text_button.momencik = new Momencik ('geocode_by_text_indicator', 'Momencik…') this.place_edit.geocode_by_text_button.observe ('click', function() { this.momencik.wait() map.geocode ($F('geocode_by_text_input') + ', Poland', function() { this.momencik.done() }.bind (this)) }) } if (this.place_edit.geocode_by_text_input = $('geocode_by_text_input')) { this.place_edit.geocode_by_text_input.observe ('keydown', function (event) { if (event.keyCode == 13) { event.preventDefault() $('google_map_search_button').click() } }) } }, __map_click: function (marker, point) { this.__destroy_menu() marker && marker.popup && marker.popup() }, __map_right_click: function (point, element, overlay) { var menu if (overlay && overlay.place) { menu = { 'Pokaż': overlay.place.data.urls.show, 'Edytuj': overlay.place.data.urls.edit, 'Historia': overlay.place.data.urls.history } if (overlay.place.data.has_images) menu['Zdjęcia'] = overlay.place.data.urls.images else menu['Dodaj pierwsze zdjęcie'] = overlay.place.data.urls.image_create } else menu = { 'Dodaj tutaj nowe miejsce': Mapcia.new_place_at_latlng_url (Mapcia.map.map.fromDivPixelToLatLng (point)) } this.__create_menu (point, menu) }, __update_inputs: function() { var point = this.geocode_marker.getLatLng() if ($('place_geo_ns')) $('place_geo_ns').value = point.lat() if ($('place_geo_ew')) $('place_geo_ew').value = point.lng() }, __dragstart: function() { this.__destroy_menu() }, __dragend: function (marker) { if (this.geocode_marker.reload_on_drop) Mapcia.new_place_at_latlng (this.geocode_marker.getLatLng()) else if (Mapcia.action == 'places#create' || Mapcia.action == 'places#edit') this.__update_inputs() }, __create_menu: function (point, menu) { this.__destroy_menu() this.popup_menu = new Element ('ul', { 'class': 'popup-menu' }) this.popup_menu.setPosition (point.x, point.y) this.element.appendChild (this.popup_menu) $H(menu).each (function (pair) { var item = new Element ('li') if (typeof pair.value == 'function') { item.update (pair.key) item.onclick = function (event) { this.__destroy_menu() pair.value() }.bind (this) } else { var a = new Element ('a', { href: pair.value }) a.update (pair.key) a.onclick = function() { this.__destroy_menu() return true }.bind (this) item.appendChild (a) } this.popup_menu.appendChild (item) }.bind (this)) }, __destroy_menu: function() { if (this.popup_menu) { this.popup_menu.parentNode.removeChild (this.popup_menu) delete this.popup_menu } } }) Object.extend (GMarker.prototype, { set_active: function (set) { this.active = set this.update_icon() }, set_hovered: function (set) { this.hovered = set this.update_icon() }, update_icon: function() { this.setImage ((this.active? Map.PLACE_ACTIVE_ICON : this.hovered? Map.PLACE_HOVER_ICON : Map.PLACE_ICON).image) }, mouseover: function (latlng) { this.set_hovered (true) if (this.place) this.place.hover (true) if (this.hover_title) { this.highlight_element = new Element ('p', { 'class': 'title' }) this.highlight_element.update (this.hover_title) var pos = Mapcia.map.map.fromLatLngToDivPixel (latlng) Mapcia.map.map.getPane (G_MAP_FLOAT_PANE).appendChild (this.highlight_element) var dim = this.highlight_element.getDimensions() this.highlight_element.setPosition (pos.x, pos.y + 1) this.highlight_element.style.minWidth = this.hover_title.length * 3 + 'px' } }, mouseout: function (marker) { this.set_hovered (false) if (this.place) this.place.hover (false) var e if (e = this.highlight_element) { e.fade ({ duration: 0.15, delay: 0.05, afterFinish: function() { e.parentNode.removeChild (e) }.bind (this) }) } this.highlight_element = null } }) Map.NewPlaceControl = function() { } Map.NewPlaceControl.prototype = Object.extend (new GControl(), { initialize: function (gmap) { this.container = new Element ('div', { style: '-moz-user-select: none; z-index: 0; color: black; font-family: Arial,sans-serif; font-size: small; height: 18px' }) this.button = new Element ('div', { style: 'border: 1px solid black; background-color: white; width: 7em; text-align: center; cursor: pointer' }) this.text = new Element ('div', { style: 'border-style: solid; border-color: white rgb(176, 176, 176) rgb(176, 176, 176) white; border-width: 1px; font-size: 12px' }) this.text.update ('Nowe miejsce') this.button.update (this.text) this.container.update (this.button) this.button.observe ('click', this.exec.bind (this)) gmap.getContainer().appendChild (this.container) return this.button }, getDefaultPosition: function() { return new GControlPosition (G_ANCHOR_TOP_RIGHT, new GSize (220, 7)) }, printable: function() { return false }, selectable: function() { return false }, exec: function() { Mapcia.set_mode (Mapcia.MODE_GEOCODE, { reload_on_drop: true }, function() { /* on dragend */ }) } }) G_DEFAULT_ICON.iconSize = new GSize(12, 20) G_DEFAULT_ICON.iconAnchor = new GPoint(6, 20) //G_DEFAULT_ICON.shadowSize = new GSize(22, 20) //G_DEFAULT_ICON.shadow = '/images/marker-shadow.png' G_DEFAULT_ICON.shadow = null G_DEFAULT_ICON.shadowSize = null Map.PLACE_ICON = Object.clone (G_DEFAULT_ICON) Map.PLACE_ICON.image = '/images/marker-red.png' Map.PLACE_HOVER_ICON = Object.clone (G_DEFAULT_ICON) Map.PLACE_HOVER_ICON.image = '/images/marker-green.png' Map.PLACE_ACTIVE_ICON = Object.clone (G_DEFAULT_ICON) Map.PLACE_ACTIVE_ICON.image = '/images/marker-blue.png' Map.ZOOM_TO_EXTENTS = [ { ns: 178.32484392034547000, ew: 360.0000000000000000 }, { ns: 159.69419870619174000, ew: 360.0000000000000000 }, { ns: 110.69193193821152000, ew: 193.3593750000000000 }, { ns: 55.149007658791355000, ew: 96.67968750000000000 }, { ns: 24.651533139736422000, ew: 48.33984375000000000 }, { ns: 11.634087841872052000, ew: 24.16992187500000000 }, { ns: 5.7595775801995615000, ew: 12.08496093750000000 }, { ns: 2.8085760982878085000, ew: 6.042480468750000000 }, { ns: 1.3870269881884596000, ew: 3.021240234374998200 }, { ns: 0.6933773690465301000, ew: 1.510620117187500000 }, { ns: 0.3465585095075880400, ew: 0.755310058593750000 }, { ns: 0.1732807647183278700, ew: 0.377655029296875000 }, { ns: 0.0866415814035832500, ew: 0.188827514648437500 }, { ns: 0.0433229106859869260, ew: 0.094413757324218750 }, { ns: 0.0216621623612169860, ew: 0.047206878662109375 }, { ns: 0.0108312579626783640, ew: 0.023603439331054688 }, { ns: 0.0054156526578168500, ew: 0.011801719665527344 }, { ns: 0.0027078275125091977, ew: 0.005900859832763672 }, { ns: 0.0013539118815515394, ew: 0.002950429916381836 }, { ns: 0.0006769557434509466, ew: 0.001475214958190918 } ] Object.extend (Map, { geocode: function (query, callback) { new Ajax.Request (URL.place_geocode, { method: 'get', parameters: { query: query }, onSuccess: function (transport) { var pos = transport.responseText.evalJSON (false) callback ({ ns: pos.ns, ew: pos.ew }) }, onFailure: function (transport) { callback (null) } }) } }) // Default position is Poland: Map.DEFAULT_NS = 52.07950600379697 Map.DEFAULT_EW = 19.0283203125 Map.DEFAULT_ZOOM = 6 Map.EDIT_ZOOM = 15