Ero sivun ”Widget:Ol3SeaBodyMapX” versioiden välillä
Järvi-meriwikistä
Rivi 39: | Rivi 39: | ||
var page = '<!--{$page|escape:'urlpathinfo'}-->'; | var page = '<!--{$page|escape:'urlpathinfo'}-->'; | ||
+ | |||
+ | function gotCoords(request) { | ||
+ | |||
+ | for (var x in request.query.results) { | ||
+ | var resultItem = request.query.results[x].printouts; break; | ||
+ | } | ||
− | + | var lon = resultItem.KoordIta[0]; | |
+ | var lat = resultItem.KoordPohj[0]; | ||
+ | var zoom = parseInt(resultItem.Zoom[0]); | ||
+ | |||
+ | if (typeof resultItem.Base[0] != 'undefined') { | ||
+ | var base = resultItem.Base[0] | ||
+ | } else { | ||
+ | var base = 'osm'; | ||
+ | } | ||
+ | |||
+ | var vpdArr = resultItem.VPDTunnus; | ||
+ | |||
+ | console.log(vpdArr); | ||
+ | |||
+ | var searchForVPDs = ''; | ||
+ | for (li in vpdArr) { | ||
+ | if (searchForVPDs.length > 0) { searchForVPDs += ' OR '; } | ||
+ | searchForVPDs += "VPDTunnus = '" + vpdArr[li] + "'"; | ||
+ | } | ||
+ | console.log( searchForVPDs ); | ||
+ | var layersArr = []; | ||
layersArr.push({ | layersArr.push({ | ||
'type': 'seabody', | 'type': 'seabody', | ||
'name': 'Merialue', | 'name': 'Merialue', | ||
− | 'search': "", | + | 'search': searchForVPDs, |
+ | //'attribution': '<a href="//wwwp2.ymparisto.fi/kayttoehdot.html">Ympäristöhallinnon paikkatietoaineistot</a>', | ||
'visible': true, | 'visible': true, | ||
'opacitySlider': true, | 'opacitySlider': true, | ||
'showLabels': false, | 'showLabels': false, | ||
+ | 'selectable': false, | ||
+ | 'zoomToExtent': true | ||
+ | }); | ||
+ | |||
+ | layersArr.push({ | ||
+ | 'type': 'sitesNobses', | ||
+ | 'name': 'Paikat ja havainnot', | ||
+ | 'siteSearch': "[[Alue::" + decodeURI(page) + "]]", | ||
+ | 'obsSearch': "[[Alue::" + decodeURI(page) + "]][[obsCode::ice||snow||temp||alg]]", | ||
+ | 'obsDays': 10, | ||
+ | 'opacitySlider': false, | ||
'selectable': true, | 'selectable': true, | ||
− | 'zoomToExtent': false, | + | 'zoomToExtent': false |
− | ' | + | }); |
− | + | ||
+ | //layersArr.push({ 'type': 'geoloc', 'name': 'Sijaintisi', 'show': true, 'center': false, 'zoom': 12, 'track': false }); | ||
// do the base map with these settings | // do the base map with these settings | ||
var map = ol3_jwMakeMap({ | var map = ol3_jwMakeMap({ | ||
'container': '<!--{$id|default:CommonObsMap|escape:'html'}-->_container', | 'container': '<!--{$id|default:CommonObsMap|escape:'html'}-->_container', | ||
− | 'base': | + | 'base': base, |
− | 'lon': | + | 'lon': lon, |
− | 'lat': | + | 'lat': lat, |
− | 'zoom': | + | 'zoom': zoom, |
'layers': layersArr, | 'layers': layersArr, | ||
'memo': memo | 'memo': memo | ||
}); | }); | ||
− | } | + | } |
+ | |||
+ | var searchStr = 'action=ask&query=[[' + page + ']]'; | ||
+ | searchStr += encodeURI('|?KoordPohj|?KoordIta|?Zoom|?Base|?VPDTunnus'); | ||
+ | searchStr += '&format=json'; | ||
+ | |||
+ | jQuery.ajax({ | ||
+ | type: 'GET', | ||
+ | url: queryApi, | ||
+ | data: searchStr, | ||
+ | success: gotCoords, | ||
+ | dataType: 'jsonp', | ||
+ | cache: true | ||
+ | }); | ||
+ | |||
+ | } | ||
+ | |||
</script> | </script> | ||
</includeonly> | </includeonly> |