



eddy.CenterMapControl = function(app) {
this.app = app;
}
eddy.CenterMapControl.prototype = new google.maps.Control();
eddy.CenterMapControl.prototype.initialize = function(map) {
var container = document.createElement("div");
var centerDiv = document.createElement("div");
var thisObj = this;
this.setButtonStyle_(centerDiv);
container.appendChild(centerDiv);
centerDiv.appendChild(document.createTextNode("Keskitä"));
google.maps.Event.addDomListener(centerDiv, "click", function() {
if(thisObj.app.marker != null) {
thisObj.app.map.setCenter(thisObj.app.marker.getLatLng());
}
});
var removeDiv = document.createElement("div");
this.setButtonStyle_(removeDiv);
container.appendChild(removeDiv);
removeDiv.appendChild(document.createTextNode("Poista"));
google.maps.Event.addDomListener(removeDiv, "click", function() {
if(thisObj.app.marker != null) {
thisObj.app.removeMarker();
}
});
map.getContainer().appendChild(container);
return container;
}
eddy.CenterMapControl.prototype.getDefaultPosition = function() {
return new google.maps.ControlPosition(google.maps.ANCHOR_TOP_LEFT, new google.maps.Size(75, 7));
}
eddy.CenterMapControl.prototype.setButtonStyle_ = function(button) {
button.style.textDecoration = "underline";
button.style.color = "#0000cc";
button.style.backgroundColor = "white";
button.style.font = "small Arial";
button.style.border = "1px solid black";
button.style.padding = "2px";
button.style.marginBottom = "3px";
button.style.textAlign = "center";
button.style.width = "6em";
button.style.cursor = "pointer";
button.style.display = "inline";
}
eddy.LocationSelector = function(canvas,cb) {
var thisObject = this; 
var extendMarker = function(marker, html, result) {
var divs = html.getElementsByTagName('div');
for (var i=0; i<divs.length;i++) {
var div = divs[i];
if (div.className=='gels-directions') {
div.style.display = "none";
break;
}
}
thisObject.result = marker.getLatLng();
div = document.createElement("div");
div.innerHTML = '<a href="javascript:void(eddy.locationSelectorApplication().selectThis())">Valitse tämä sijainti</a>';
html.appendChild(div);
return html;
}
var mapOptions = {
googleBarOptions: {
style: "new",
onGenerateMarkerHtmlCallback : extendMarker
}
}
thisObject.map = new google.maps.Map2(eddy.e(canvas), mapOptions);
//thisObject.map.addMapType(google.maps.PHYSICAL_MAP);
thisObject.cb = cb;
thisObject.large_map_control = new google.maps.LargeMapControl3D();
thisObject.map.addControl(thisObject.large_map_control);
// thisObject.map_type_control = new google.maps.MapTypeControl();
thisObject.center_map_control = new eddy.CenterMapControl(thisObject);
thisObject.map.enableScrollWheelZoom();
thisObject.map.enableDragging();
var myEventListenerCb = 
function(overlay, latlng) {
if(thisObject.editing) {
if (latlng) {
thisObject.setMarker(latlng);
} else if (overlay == thisObject.marker) {
thisObject.removeMarker();
}
}
};
var myEventListener = google.maps.Event.bind(thisObject.map, "click", thisObject, myEventListenerCb);
thisObject.marker = null;
thisObject.map.setCenter(new google.maps.LatLng(20.0000, 15.0000), 1);
thisObject.removeMarker();
thisObject.stopEdit();
}
eddy.LocationSelector.prototype.startEdit = function() {
var thisObject = this; 
thisObject.editing = true;
// thisObject.map.enableScrollWheelZoom();
// thisObject.map.addControl(thisObject.large_map_control);
// thisObject.map.addControl(thisObject.map_type_control);
thisObject.map.addControl(thisObject.center_map_control);
thisObject.map.enableGoogleBar();
// thisObject.map.enableDragging();
}
eddy.LocationSelector.prototype.stopEdit = function() {
var thisObject = this; 
thisObject.editing = false;
// thisObject.map.disableScrollWheelZoom();
// thisObject.map.removeControl(thisObject.large_map_control);
// thisObject.map.removeControl(thisObject.map_type_control);
thisObject.map.removeControl(thisObject.center_map_control);
thisObject.map.disableGoogleBar();
// thisObject.map.disableDragging();
};
eddy.LocationSelector.prototype.isEditing = function() {
return this.editing;
}
eddy.LocationSelector.prototype.removeMarker = function(center, zoom) {
if(this.marker != null) {
this.map.removeOverlay(this.marker);
this.marker = null;
this.cb(null,null);
}
if(center)
this.map.setCenter(center);
if(zoom)
this.map.setZoom(zoom);
}
eddy.LocationSelector.prototype.setMarker = function(latlng, center, zoom) {
this.removeMarker();
var myIcon = new google.maps.Icon();
myIcon.imageMap = [25,0, 0,0, 0,25, 9,25, 12,31, 13,31, 16,25, 25,25];
myIcon.image = "http://fi.equaldreams.com/ed/images/maps/profile-marker.png";
myIcon.shadow = "http://fi.equaldreams.com/ed/images/maps/marker-shadow.png";
myIcon.transparent = "http://fi.equaldreams.com/ed/images/maps/profile-marker-transparent.png";
myIcon.iconSize = new google.maps.Size(38, 32);
myIcon.shadowSize = new google.maps.Size(38, 32);
myIcon.iconAnchor = new google.maps.Point(13, 32);
myIcon.infoWindowAnchor = new google.maps.Point(13, 1);
var markerOptions = { icon:myIcon };
this.marker = new google.maps.Marker(latlng, markerOptions);
this.map.addOverlay(this.marker);
if(center)
this.map.setCenter(center);
if(zoom)
this.map.setZoom(zoom);
this.cb(latlng.lat(), latlng.lng());
}
eddy.LocationSelector.prototype.selectThis = function() {
this.map.disableGoogleBar();
this.map.clearOverlays();
this.setMarker(this.result);
this.map.enableGoogleBar();
}
eddy.LocationSelector.prototype.getCenter = function() {
return this.map.getCenter();
}
eddy.LocationSelector.prototype.getZoom = function() {
return this.map.getZoom();
}
