Widget:MerialueOL
<script type="text/javascript" src="//www.jarviwiki.fi/api/common/OpenLayers-2.12/OpenLayers.js"></script> <script type="text/javascript" src="//www.jarviwiki.fi/api/common/OpenLayers-2.12/lib/OpenLayers/Lang/fi.js"></script> <script type="text/javascript" src="//www.jarviwiki.fi/api/common/OpenLayers-2.12/lib/OpenLayers/Lang/sv-SE.js"></script> <script type="text/javascript">
var target = document.getElementById();
var ajaxRequests = 0;
var map; var epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection var mapProjStr = "3857"; var projectTo = new OpenLayers.Projection("EPSG:" + mapProjStr); //The map projection
var searchStr = "action=ask&q=[[]]"; searchStr += "&po=|KoordPohjMin|KoordItaMin|KoordPohjMax|KoordItaMax|Tunnus&format=json"; ajaxRequests++; jQuery.ajax({
type: 'GET', url: '//www.jarviwiki.fi/w/api.php', data: searchStr, success: success, dataType: 'jsonp', cache: true
});
//map object var options = {
projection: "EPSG:" + mapProjStr,
units: "m", controls: [ new OpenLayers.Control.Navigation({zoomWheelEnabled : false}), new OpenLayers.Control.Zoom(), new OpenLayers.Control.LayerSwitcher({'ascending':false}), new OpenLayers.Control.Attribution() ] };
map = new OpenLayers.Map( , options );
//OpenStreetMap osm = new OpenLayers.Layer.OSM("OpenStreetMap", null, {
sphericalMercator: true, projection: projectTo, transitionEffect: "resize", attribution: "© <a href='//www.openstreetmap.org/copyright'>OpenStreetMapin tekijät</a>"
});
map.addLayer(osm);
//Peruskartta map.addLayer(new OpenLayers.Layer.WMS("Peruskartta", "//tiles.kartat.kapsi.fi/peruskartta?", {layers: 'peruskartta'}, {projection: 'EPSG:900913', attribution: "asdf" }));
//Ortoilmakuvat map.addLayer(new OpenLayers.Layer.WMS("Ortoilmakuvat", "//tiles.kartat.kapsi.fi/ortokuva?", {layers: 'ortokuva'}, {projection: 'EPSG:900913', attribution: "asdforto" }));
//Ortoilmakuvat map.addLayer(new OpenLayers.Layer.WMS("Taustakartta", "//tiles.kartat.kapsi.fi/taustakartta?", {layers: 'taustakartta'}, {projection: 'EPSG:900913', attribution: "asdforto" }));
function success(request) {
var props = request.ask.results.items[0].properties; var jnum = new Array(); if (jQuery.isArray(props.tunnus)) {
jnum = props.tunnus;
} else {
jnum = [props.tunnus];
}
vpdQueryStr = ""; vpdQueryStr2 = ""; for (j=0; j<jnum.length; j++) {
vpdQueryStr += '+OR+VPDTunnus+%3D+%27' + jnum[j].split(' ').join('_') + '%27'; vpdQueryStr2 += " OR VPDTunnus = '" + jnum[j].split(' ').join('_') + "'";
} vpdQueryStr = vpdQueryStr.substring(4); vpdQueryStr2 = vpdQueryStr2.substring(4);
///////////////////// Merialueen rajaus jQuery.ajax({
type: 'GET', url: '//paikkatieto.ymparisto.fi/arcgis/rest/services/INSPIRE/' + 'SYKE_AlueidenHallintaJaRajoitukset1/MapServer/3/query', data: '&where=' + vpdQueryStr + '&returnCountOnly=true&f=pjson', success: function(request) { if (request.count != 0) { var lr = new OpenLayers.Layer.ArcGIS93Rest( 'Merialueen raja', '//paikkatieto.ymparisto.fi/arcgis/rest/services/INSPIRE/' + 'SYKE_AlueidenHallintaJaRajoitukset1/MapServer/export', { layers: "show:3", version: '1.3.0', crs: mapProjStr, TRANSPARENT: true }, { isBaseLayer: false, opacity: 0.5 } ); lr.setLayerFilter(3, vpdQueryStr2); map.addLayer(lr); } }, dataType: 'jsonp'
}); /////////////////////
var lonMin = parseFloat(props.koorditamin.replace(',', '.')); var lonMax = parseFloat(props.koorditamax.replace(',', '.')); var latMin = parseFloat(props.koordpohjmin.replace(',', '.')); var latMax = parseFloat(props.koordpohjmax.replace(',', '.'));
bounds = new OpenLayers.Bounds(); bounds.extend(new OpenLayers.LonLat(lonMin,latMin).transform(epsg4326, projectTo)); bounds.extend(new OpenLayers.LonLat(lonMax,latMax).transform(epsg4326, projectTo)); map.zoomToExtent(bounds);
ajaxRequests--;
}
</script>