/*  GMEasy3 version 1.0.0
 *  (c) 2010 kuwappa
 *
 *  GMEasy is freely distributable under the terms of an MIT-style license.
 *  For details, see my web site: http://d.hatena.ne.jp/oinusama/
 *----------------------------------------------------------------------------*/
var GMEasy3 = function(ID, LAT, LON, ZOOM)
{ this.id_lat = null; this.id_lon = null; this.id_zoom = null; this.id_geoLat = null; this.id_geoLon = null; this.arrayMarker = new Array(); this.arrayGeoMarker = new Array(); this.arrayDragMarker = new Array(); this.arrayDistanceMarker= new Array(); this.map; this.polylines; this.flg_scaleControl = true; this.flg_mobileMode = false; this.set_flg_scaleControl = function(flg_scaleControl)
{ this.flg_scaleControl = flg_scaleControl;}
this.flg_mobileMode = function(flg_mobileMode)
{ this.flg_mobileMode = flg_mobileMode;}
this.set_id_latLonZoom = function(id_lat, id_lon, id_zoom)
{ this.id_lat = id_lat; this.id_lon = id_lon; this.id_zoom= id_zoom;}
this.set_id_geoLatLon = function(id_geoLat, id_geoLon)
{ this.id_geoLat = id_geoLat; this.id_geoLon = id_geoLon;}
this.set_marker = function(object)
{ this.arrayMarker.push(object);}
this.set_geoMarker = function(object)
{ object.draggable= true; object.icon = "arrowSmall80"; object.draggable= true; object.idLat = this.id_geoLat; object.idLon = this.id_geoLon; this.arrayGeoMarker.push(object);}
this.set_dragMarker = function(object)
{ object.draggable = true; this.arrayDragMarker.push(object);}
this.set_distanceMarker = function(object)
{ object.draggable = true; this.arrayDistanceMarker.push(object);}
this.put_marker = function()
{ for(var y = 0, cnt = this.arrayMarker.length; y < cnt; y++)
{ this.put_marker_icon(this.arrayMarker, y); this.put_marker_event("this.arrayMarker", y);}
}
this.put_geoMarker = function()
{ for(var y = 0, cnt = this.arrayGeoMarker.length; y < cnt; y++)
{ this.put_marker_icon(this.arrayGeoMarker, y); this.put_marker_event("this.arrayGeoMarker", y);}
}
this.put_dragMarker = function()
{ for(var y = 0, cnt = this.arrayDragMarker.length; y < cnt; y++)
{ this.put_marker_icon(this.arrayDragMarker, y); this.put_marker_event("this.arrayDragMarker", y);}
}
this.put_distanceMarker = function()
{ var cnt = this.arrayDistanceMarker.length; var polylines = []; if(0 === cnt)
{ return;}
else if(0 !== cnt && 2 !== cnt)
{ alert("二点間距離計測マーカーは2つ設定した場合のみ機能します。"); return;}
for(var y = 0; y < cnt; y++)
{ this.put_marker_icon(this.arrayDistanceMarker, y); this.put_marker_event("this.arrayDistanceMarker", y);}
polylines[0] = new google.maps.LatLng(this.arrayDistanceMarker[0].lat, this.arrayDistanceMarker[0].lon); polylines[1] = new google.maps.LatLng(this.arrayDistanceMarker[1].lat, this.arrayDistanceMarker[1].lon); this.draw_polyline_distance(polylines);}
this.put_marker_icon = function(array, y)
{ var icon; var shadow; var position; if( GMEasy3.myEmpty(array[y].icon) )
{ array[y].icon = "red-dot";}
if( array[y].icon.match(/-dot$/) )
{ icon = new google.maps.MarkerImage
( "http://maps.google.co.jp/mapfiles/ms/icons/" + array[y].icon + ".png", new google.maps.Size(30,36), new google.maps.Point(0,0), new google.maps.Point(15,32) ); shadow = new google.maps.MarkerImage
( "http://maps.google.co.jp/mapfiles/ms/icons/msmarker.shadow.png", new google.maps.Size(59,32), new google.maps.Point(0,0), new google.maps.Point(15,32) );}
else if( array[y].icon.match(/^beachflag/) )
{ icon = new google.maps.MarkerImage
( "http://code.google.com/intl/ja/apis/maps/documentation/v3/examples/images/beachflag.png", new google.maps.Size(20,32), new google.maps.Point(0,0), new google.maps.Point(0,32) ); shadow = new google.maps.MarkerImage
( "http://code.google.com/intl/ja/apis/maps/documentation/v3/examples/images/beachflag_shadow.png", new google.maps.Size(37,32), new google.maps.Point(0,0), new google.maps.Point(0,32) );}
else if( array[y].icon.match(/-pushpin$/) )
{ icon = new google.maps.MarkerImage
( "http://maps.google.co.jp/mapfiles/ms/icons/" + array[y].icon + ".png", new google.maps.Size(32,32), new google.maps.Point(0,0), new google.maps.Point(10,32) ); shadow = new google.maps.MarkerImage
( "http://maps.google.co.jp/mapfiles/ms/icons/pushpin_shadow.png", new google.maps.Size(59,32), new google.maps.Point(0,0), new google.maps.Point(10,32) );}
else if( array[y].icon.match(/^mm_20_/) )
{ icon = new google.maps.MarkerImage
( "http://labs.google.com/ridefinder/images/" + array[y].icon + ".png", new google.maps.Size(12,20), new google.maps.Point(0,0), new google.maps.Point(6,20) ); shadow = new google.maps.MarkerImage
( "http://labs.google.com/ridefinder/images/mm_20_shadow.png", new google.maps.Size(22,20), new google.maps.Point(0,0), new google.maps.Point(6,20) );}
else if( array[y].icon.match(/^marker/) )
{ icon = new google.maps.MarkerImage
( "http://www.google.com/mapfiles/gadget/letters/" + array[y].icon + ".png", new google.maps.Size(16,27), new google.maps.Point(0,0), new google.maps.Point(8,27) ); shadow = new google.maps.MarkerImage
( "http://www.google.com/mapfiles/gadget/shadow50Small80.png", new google.maps.Size(30,28), new google.maps.Point(0,0), new google.maps.Point(8,27) );}
else if( array[y].icon.match(/^arrowSmall80/) )
{ icon = new google.maps.MarkerImage
( "http://www.google.com/mapfiles/gadget/arrowSmall80.png", new google.maps.Size(31,27), new google.maps.Point(0,0), new google.maps.Point(9,27) ); shadow = new google.maps.MarkerImage
( "http://www.google.com/mapfiles/gadget/arrowshadowSmall80.png", new google.maps.Size(31,28), new google.maps.Point(0,0), new google.maps.Point(9,27) );}
else
{ switch(array[y].icon)
{ case "blue" :
case "red" :
case "green" :
case "lightblue" :
case "yellow" :
case "purple" :
case "pink" :
case "orange" :
case "sekaicamera" :
case "toilets" :
icon = new google.maps.MarkerImage
( "http://www.ishigaki-island.com/sekaicamera/icons/" + array[y].icon + ".png", new google.maps.Size(30,36), new google.maps.Point(0,0), new google.maps.Point(15,32) );
shadow = new google.maps.MarkerImage
( "http://www.ishigaki-island.com/sekaicamera/icons/shadow.png", new google.maps.Size(59,30), new google.maps.Point(0,0), new google.maps.Point(15,32) ); break; case "restaurant" :
case "coffeehouse" :
case "bar" :
case "snack_bar" :
case "drinking_water" :
case "lodging" :
case "wheel_chair_accessible" :
case "shopping" :
case "movies" :
case "grocerystore" :
case "convienancestore" :
case "arts" :
case "homegardenbusiness" :
case "electronics" :
case "mechanic" :
case "pharmacy-us" :
case "realestate" :
case "salon" :
case "dollar" :
case "parkinglot" :
case "gas" :
case "cabs" :
case "bus" :
case "truck" :
case "rail" :
case "plane" :
case "ferry" :
case "helicopter" :
case "question" :
case "info" :
case "flag" :
case "earthquake" :
case "webcam" :
case "postoffice-us" :
case "police" :
case "firedept" :
case "hospitals" :
case "landmarks-jp" :
case "phone" :
case "caution" :
case "postoffice-jp" :
case "hotsprings" :
case "tree" :
case "campfire" :
case "picnic" :
case "campground" :
case "rangerstation" :
case "POI" :
case "hiker" :
case "cycling" :
case "motorcycling" :
case "horsebackriding" :
case "sportvenue" :
case "golfer" :
case "trail" :
case "water" :
case "snowflake_simple" :
case "marina" :
case "fishing" :
case "sailing" :
case "swimming" :
case "waterfalls" :
icon = new google.maps.MarkerImage
( "http://maps.google.co.jp/mapfiles/ms/icons/" + array[y].icon + ".png", new google.maps.Size(32,32), new google.maps.Point(0,0), new google.maps.Point(15,32) ); shadow = new google.maps.MarkerImage
( "http://maps.google.co.jp/mapfiles/ms/icons/" + array[y].icon + ".shadow.png", new google.maps.Size(59,32), new google.maps.Point(0,0), new google.maps.Point(15,32) ); break;}
}
if(true !== array[y].draggable)
{ array[y].draggable = false;}
if( GMEasy3.myEmpty(array[y].position) )
{ position = new google.maps.LatLng(array[y].lat, array[y].lon);}
else
{ position = array[y].position;}
array[y].object = new google.maps.Marker
( { position : position, map : this.map, icon : icon, shadow : shadow, title : array[y].title, draggable : array[y].draggable
} );}
this.put_marker_event = function(name, y)
{ var name1 = name.replace("this", "that"); var array = eval(name); var array1; var that = this; var latLon; var latLonS; var latLonE; var infowindow = new google.maps.InfoWindow
( { content : array[y].iw
} ); var fncLatLon = function()
{ latLon = array1[y].object.getPosition(); that.toId_generalPurpose(array1[y].idLat, latLon.lat() ); that.toId_generalPurpose(array1[y].idLon, latLon.lng() );}
var fncAddress = function()
{ latLon = array1[y].object.getPosition(); that.reverseGeocoder_search(latLon, array1[y].idAddress);}
array1 = eval(name1); google.maps.event.addListener
( array[y].object, "click", function()
{ infowindow.open(this.map, array[y].object);} ); if( !GMEasy3.myEmpty(array[y].idLat) && !GMEasy3.myEmpty(array[y].idLon) )
{ fncLatLon(); google.maps.event.addListener(array[y].object, "dragend", fncLatLon);}
if( !GMEasy3.myEmpty(array[y].idAddress) )
{ fncAddress(); google.maps.event.addListener(array[y].object, "dragend", fncAddress);}
}
this.toId_generalPurpose = function(field, value)
{ if( field.match(/^this/) )
{ field = eval(field);}
if( !document.getElementById(field) )
{ return
}
else if( "INPUT" === document.getElementById(field).nodeName )
{ document.getElementById(field).value = value;}
else
{ document.getElementById(field).innerHTML = value;}
}
this.toId_latLonZoom = function()
{ var zoom; var that = this; var latLon = this.map.getCenter(); this.toId_generalPurpose( "this.id_lat", latLon.lat() ); this.toId_generalPurpose( "this.id_lon", latLon.lng() ); this.toId_generalPurpose( "this.id_zoom", this.map.getZoom() ); google.maps.event.addListener
( this.map, "dragend", function()
{ latLon = that.map.getCenter(); that.toId_generalPurpose("this.id_lat", latLon.lat() ); that.toId_generalPurpose("this.id_lon", latLon.lng() );} ); google.maps.event.addListener
( this.map, "zoom_changed", function()
{ zoom = that.map.getZoom(); if(true === that.flg_mobileMode)
{ if(17 < zoom)
{ zoom = 17; that.map.setZoom(zoom);}
else if(8 > zoom)
{ zoom = 8; that.map.setZoom(zoom);}
}
that.toId_generalPurpose("this.id_zoom", zoom);} );}
this.draw_polyline_distance = function(polylines)
{ this.polylines = new google.maps.Polyline
( { path : polylines, strokeColor : "#ff00ff", strokeOpacity : 0.5, strokeWeight : 5
} ); this.polylines.setMap(this.map);}
this.geocoder_search = function(address)
{ var geocoder = new google.maps.Geocoder(); var that = this; geocoder.geocode
( {"address" : address}, function(results, status)
{ if(status === google.maps.GeocoderStatus.OK)
{ if( !GMEasy3.myEmpty(that.arrayGeoMarker[0]) )
{ that.arrayGeoMarker[0].object.setMap(null);}
var iw =address + "<br /><br />"+ "緯度：" + results[0].geometry.location.Ra + "<br />" + "経度：" + results[0].geometry.location.Sa; that.map.setCenter(results[0].geometry.location); that.arrayGeoMarker = Array
( { position : results[0].geometry.location, title : "address", iw : iw, icon : "arrowSmall80", draggable : true, idLat : that.id_geoLat, idLon : that.id_geoLon
} ); that.put_geoMarker();}
else
{ alert("『" + address + "』は見つかりませんでした。");}
} );}
this.reverseGeocoder_search = function(latLon, id)
{ var that = this; var geocoder = new google.maps.Geocoder(); geocoder.geocode
( {'latLng' : latLon}, function(results, status)
{ if(status == google.maps.GeocoderStatus.OK)
{ if(results[1])
{ var str = results[1].formatted_address; str = str.replace(/^日本/, "");}
else
{ var str = "該当する住所がありませんでした。";}
}
else
{ var str = "該当する住所がありませんでした。";}
that.toId_generalPurpose(id, str);} );}
this.disp = function()
{ var myOptions = { zoom : ZOOM, center : new google.maps.LatLng(LAT, LON), mapTypeId : google.maps.MapTypeId.ROADMAP, scaleControl: this.flg_scaleControl
}
this.map = new google.maps.Map( document.getElementById("map"), myOptions ); this.toId_latLonZoom(); this.put_marker(); this.put_geoMarker(); this.put_dragMarker(); this.put_distanceMarker();}
}
GMEasy3.myEmpty = function(value)
{ if("undefined" === typeof value) return true; if(null === value ) return true; if(false === value ) return true; if("" === value ) return true; return false;}

