function xml_load(){ $.ajax({ url:"shoplist.xml",//外部ファイル cache:false, dataType:"xml", success:function(xml){ var data=xmlRequest(xml); initialize(data); } }); } function xmlRequest(xml){ var data=[]; $(xml).find("markers > marker").each(function(){ var dat={}; dat.lat=this.getElementsByTagName("lat"); dat.lng=this.getElementsByTagName("lng"); $(this).children().each(function(){ if(this.childNodes.length>0)dat[this.tagName]=this.childNodes[0].nodeValue; }); data.push(dat); }); return data; } function attach_message(map, marker, msg, iw){ google.maps.event.addListener(marker,'click',function(event){ iw.setContent(msg);iw.open(map,marker); }); } function initialize(data) { var current = 48; /*----- マップ中心座標 -----*/ // var latlng = new google.maps.LatLng(41.2, 140); // var latlng = new google.maps.LatLng(36.6, 138); //長野中心(本州広域) // var latlng = new google.maps.LatLng(36, 135.7); //大阪中心(関西周辺) var latlng = new google.maps.LatLng(35, 132.5); //広島中心(中国四国周辺) // var latlng = new google.maps.LatLng(30, 128); // 九州~沖縄 var myOptions = { zoom: 6, center: latlng, overviewMapControl:true, overviewMapControlOptions:{opened:true}, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, panControl:false, zoomControl:false, streetViewControl: false, disableDoubleClickZoom:true, scrollwheel:false }; map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); /* スタイル付き地図 */ var styleOptions = [ { 'elementType': 'labels', 'stylers': [ { 'visibility': 'off' } ] },{ 'elementType': 'geometry', 'stylers': [ { 'hue': '#ff4d00' }, { 'gamma': 0.8 } ] },{ 'featureType': 'water', 'elementType': 'geometry', 'stylers': [ { 'hue': '#00ccff' }, { 'saturation': 10 }, { 'lightness': 20 } ] },{ 'featureType': 'road.arterial', 'elementType': 'geometry', 'stylers': [ { 'lightness': 100 }, { 'visibility': 'on' } ] },{ 'featureType': 'landscape', 'elementType': 'geometry', 'stylers': [ { 'visibility': 'simplified' }, { 'lightness': -5 }, { 'saturation': 50 }, { 'hue': '#ffe500' } ] },{ 'featureType': 'transit.line', 'elementType': 'geometry', 'stylers': [ { 'visibility': 'on' }, { 'gamma': 0.6 }, { 'lightness': 30 }, { 'saturation': 40 } ] },{ 'featureType': 'landscape.man_made', 'elementType': 'geometry', 'stylers': [ { 'hue': '#ff0000' }, { 'lightness': 40 }, { 'visibility': 'off' } ] },{ 'featureType': 'poi', 'elementType': 'geometry', 'stylers': [ { 'visibility': 'off' } ] },{ 'featureType': 'poi.park', 'elementType': 'geometry', 'stylers': [ { 'visibility': 'simplified' }, { 'hue': '#ccff00' }, { 'lightness': 10 }, { 'saturation': 30 } ] },{ 'featureType': 'road.highway', 'elementType': 'geometry', 'stylers': [ { 'visibility': 'on' }, { 'saturation': 100 }, { 'gamma': 0.8 }, { 'lightness': 50 }, { 'hue': '#ff8800' } ] },{ 'featureType': 'road.local', 'stylers': [ { 'hue': '#ff0000' }, { 'visibility': 'simplified' }, { 'lightness': 100 } ] },{ 'featureType': 'transit.station', 'elementType': 'geometry', 'stylers': [ { 'saturation': 50 }, { 'lightness': 20 }, { 'visibility': 'on' }, { 'hue': '#ff0000' } ] },{ 'featureType': 'poi.business', 'elementType': 'geometry', 'stylers': [ { 'hue': '#ff0000' }, { 'saturation': 80 }, { 'visibility': 'on' } ] },{ 'featureType': 'road', 'elementType': 'labels.text', 'stylers': [ { 'visibility': 'on' }, { 'lightness': 10 }, { 'hue': '#ff8000' }, { 'saturation': 80 }, { 'gamma': 0.8 } ] },{ 'featureType': 'road', 'elementType': 'labels.text.stroke', 'stylers': [ { 'color': '#ffffff' }, { 'weight': 3 } ] } ]; var styledMapOptions = { name: 'test' } var fancyType = new google.maps.StyledMapType(styleOptions, styledMapOptions); map.mapTypes.set('fancy', fancyType); map.setMapTypeId('fancy'); // map base var imageBounds = new google.maps.LatLngBounds( new google.maps.LatLng(-85,0), new google.maps.LatLng(85,-1) ); var mapbase = new google.maps.GroundOverlay( 'images/map_bg.gif', imageBounds ); mapbase.setMap(map); // map image var imageBounds2 = new google.maps.LatLngBounds( new google.maps.LatLng(19.2823192,114.305393), new google.maps.LatLng(53.018881,166.647047) ); var mapimg = new google.maps.GroundOverlay( 'images/map_img48.gif', imageBounds2 ); mapimg.setMap(map); if (data!=null){ var i=data.length; } var iw=new google.maps.InfoWindow(); while(i-->0){ if(i < current-1){ pinimg = 'images/marker_complete.png'; }else{ pinimg = 'images/marker_complete.png'; } var dat=data[i]; var thisLatLng = new google.maps.LatLng(dat.lat,dat.lng); var pinimgIco = pinimg; var obj={ position:thisLatLng, map:map, icon: pinimgIco }; var popup = new String(); var popup=dat.name; var marker=new google.maps.Marker(obj); attach_message(map, marker, popup,iw); google.maps.event.addListener(map, 'click', function(e){ iw.close(); }); } } function reset_map(){ xml_load(); initialize(); $('#map_zoomout').addClass('off'); $('#map_zoomin').removeClass('off'); } function zoomin_map(){ var level = map.getZoom(); if(level<8){ level++; map.setZoom(level); if($('#map_zoomout').hasClass('off')){ $('#map_zoomout').removeClass('off'); } if(level==8){ $('#map_zoomin').addClass('off'); } } } function zoomout_map(){ var level = map.getZoom(); if(level>6){ level--; map.setZoom(level); if($('#map_zoomin').hasClass('off')){ $('#map_zoomin').removeClass('off'); } if(level==6){ $('#map_zoomout').addClass('off'); } } } $(function(){ xml_load(); $('#map_zoomout').addClass('off'); $('#map_reset').click(function(){ reset_map(); }); $('#map_zoomin').click(function(){ zoomin_map(); }); $('#map_zoomout').click(function(){ zoomout_map(); }); });