Newer
Older
Loremap / storymap / new_late_geojson.js
@natto natto on 19 Aug 2018 7 KB you can select season layers
var ltlg= [38.72859248614108,139.82239320874214];
//マップの中心にする座標



function Boxes(map,panpan,tenten,Name){
    
    var S_width=window.innerWidth;
    var S_height=window.innerHeight;
    
    if(S_width<S_height){
	var M_width=S_width;
	var M_height=S_height/2;
	//console.log("unko");
    }else{
	var M_width=S_width/2;
	var M_height=S_height-200;
    };
    
    map.on('popupopen', function(o) {	
	$(function(){
	    $('.movie').colorbox({
		onOpen:function(){
		    map.closePopup();
		},
		onLoad:function(){
	    	    map.setZoom(17);
		},
		iframe: true,
		title:"unko",
		//  titleで祭の名前とレストランの名前を表示		
		width:M_width,
		height: M_height,
		rel:'movie', //同じクラス名のものをスライド表示
		//width:s_width-100,
		onClosed:function(){
		    var pan=$.colorbox.element().context.attributes.id.nodeValue;
		    var lat=panpan[pan][1],lng=panpan[pan][0];
		    var pan_to=[lat,lng];
		    map.flyTo(pan_to);
		    tenten[pan].openPopup();
		}
		
	    });
	});
    });
};

function Set_Contents(str){
    //contents replace
    var desc="";
    str=str.split(/\n/);
    for(i=0; i<str.length; i++){
	if(str[i].match(/^{{{/)){
	    var Mov=str[i].replace(/{{{/g, "");
	    Mov=Mov.replace(/}}}/g, "");
	}else if(str[i].match(/^{{/)){
	    var Pic=str[i].replace(/{{/g, "<img src=\"");
	    Pic=Pic.replace(/}}/g, "\">");
	}else if(str[i].match(/^\[\[/)){
	    var Link=str[i].replace(/^\[\[/g, "<a href=\"")
	    Link=Link.replace(/\|/g, "\">");
	    Link=Link.replace(/]]/g, "</a>");
	}else{
	    desc=desc.concat(str[i]);
	}
    };
    
    return [desc,Mov,Pic,Link];
};

var osmTile =
    L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
	attribution:
	'&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> \
contributors'
    });

var gsiTile = 
    L.tileLayer('//cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
	attribution:
	'<a href="http://maps.gsi.go.jp/development/ichiran.html">国土地理院</a>'
    });

var haru=L.layerGroup([]);
var natu=L.layerGroup([]);
var akii=L.layerGroup([]);
var huyu=L.layerGroup([]);

var mymap= L.map("mymap", {
    layers: [osmTile,haru,natu,akii,huyu], //最初に指定するタイルレイヤー
    center: ltlg, zoom: 17, scrollWheelZoom: false
    //中心座標とズームレベルとマウスのホイールでのズームをしないよう設定
});

//var time= document.getElementById("time");

var baseLayers = {'OpenStreetMap': osmTile, '国土地理院': gsiTile};
//レイヤーの内容

var kasyo=[],naiyo=[],iro=[],k_type=[],ten=[],coments=[],usepan=[],mkname=[];



var count=0;
var customLayer=L.geoJson(null,{
    style: function(feature) {
    	if (feature.properties._storage_options && feature.properties._storage_options.color){
	    switch (feature.properties._storage_options.color) {
		//alert(feature.properties._storege_opions);
    	    case 'Red': return {color: "red"};
	    case 'brown': return {color: "brown"};
	    case 'Cyan': return {color: "cyan"};
	    case 'lime': return {color: "lime"};
            }    
	}
	if (feature.properties._storage_options && feature.properties._storage_options.weight){
	    var hutosa=feature.properties._storage_options.weight;
    	    return {weight: hutosa};
        }
	if (feature.properties._storage_options && feature.properties._storage_options.dashArray){
	    var hakai=feature.properties._storage_options.dashArray;
	    return {dashArray: hakai};   
        }
    },
    onEachFeature: (function unji(feature, layer){
	var propert= feature.properties, geomet=feature.geometry;
	// 予めfeature.propertisをletで宣言。(varでも可)
	if (propert && geomet) {
	    if (propert.name){
		var name=propert.name
	    } else {
		var name="";
	    }
	    if (propert.description){
		var tose=propert.description;
	    } else {
		var tose="";
	    }
	    if (propert._storage_options){
		if (propert._storage_options.color){
		    var color=propert._storage_options.color;
		    iro.push(color);
		}else {
		    color="";
		    iro.push(color);
		}
		if (propert._storage_options.iconClass){
		    var katati=propert._storage_options.iconClass;
		}else {
		    katati="";
		}
		
	    }

	    var season=propert.Season;
	    var period=propert.period;
	    var address=propert.address;
	    var type=geomet.type, m=geomet.coordinates;
	    
	    k_type.push(type);
	    
	    //alert(k_type);
	    
	    
	    if (propert){
		if(type=="Point"){
		    var Point_id=type+count;
		    var SMC=Set_Contents(tose);
		    //alert(SMC[1]);
		    if(SMC[1]==undefined){
			var coment="<div id="+Point_id+"><h1>"+name+"</h1><h2>"+SMC[0]+"</h2></div>";
			count++;
			coments.push(coment);
			usepan.push(m);
			mkname.push(name);
			
			var PM=/spring/i;
			 
		    }else{
			var coment="<div id="+Point_id+"><h1>"+name+"</h1><h3>"+SMC[0]+"</h3>"+SMC[3]+""+SMC[2]+"</div>";
			var movie=SMC[1];
			count++;
			coments.push(movie);
			usepan.push(m);
			mkname.push(name);
		
		    }
		    //console.log(haru);
		    //alert(coment);
		    //console.log(coments);
		}else{
		    var coment="<h1>"+name+"</h1><div>"+tose+"</div>";
		}
	    }
	    var mak=layer.bindPopup(coment);
	    /*
	    if (color=="Red" && type=="Point" && katati==""){
	    	mak.setIcon(r_Icon);
	    }else if (color=="Yellow" && type=="Point" || color=="Gold" && type=="Point" ){
	    	mak.setIcon(y_Icon);	
	    }else if (color=="lightpink" && type=="Point" || color=="LightPink" && type=="Point"){
	    	mak.setIcon(lp_Icon);
	    }else if (color=="lime" && type=="Point" || color=="Lime" && type=="Point"){
	    	mak.setIcon(lime_Icon);
	    }else if (color=="DarkSlateGray" && type=="Point" || color=="darkslategray" && type=="Point" ){
	    	mak.setIcon(DSG_Icon);
	    }else if (katati=="Drop"){
	    	mak.setIcon(hinanjo);
	    }
	    */
	    if(season=="Spring" || season=="spring"){
		haru.addLayer(mak);
	    }else if(season=="Summar" || season=="summar"){
		//console.log(layer);
		natu.addLayer(mak);
		//console.log(m);
	    }else if(season=="Fall" || season=="fall"){
		akii.addLayer(mak);
	    }else{
		huyu.addLayer(mak);
	    }
	    
	    //natu.addTo(mymap);
	    if (type=="LineString"){
		for(i=0; i<m.length; i++){
		    //alert(m[i]);
		    kasyo.push(m[i]);
		    naiyo.push(tose);
		    ten.push(mak);
		    //alert(naiyo);
		};
		// LineStringでの座標を細かくとる
	    }else {
		kasyo.push(m); //この関数外に変数を持って行くために使用
		naiyo.push(tose);
		ten.push(mak);
	    }
	    
	    //kasyo.push(m); //この関数外に変数を持って行くために使用
	    //naiyo.push(tose);
	    
	}
    })
});

var gpxLayer = omnivore.geojson('kisetuwake.geojson', null, customLayer).on('ready', function() {  
    //var lec=document.getElementById("all_coment");
    //lec.innerHTML=coments;
    //console.log(coments.length);
    var getel_c=document.getElementsByClassName("leaflet-marker-icon");

for(i=0; i<getel_c.length; i++){
    if(coments[i].match(/youtu/)){
	getel_c[i].classList.add("movie");
	getel_c[i].setAttribute("href",coments[i]);
	getel_c[i].setAttribute("id",i);
    };
    // getel_c is array. Because I use 'for'
    
};
    
    
    Boxes(mymap,usepan,ten,mkname);
    
    
    //L.control.layers(unko,usepan[3]).addTo(mymap);
    //console.log();
    //unko.addTo(mymap);
}).addTo(mymap);

//geojsonファイルを読みだし
/*
var bound=L.latLng(usepan[0]);
var bound2=L.latLng(usepan[1]);
var layers={'unko':bound,'anko':bound2};
L.control.layers(layers).addTo(mymap);
*/

//レイヤー変更オプション
var late_season={'SP':haru,'SM':natu,'FA':akii,'WI':huyu};
L.control.layers(baseLayers,late_season).addTo(mymap);