Last active
April 13, 2016 16:31
-
-
Save alexanno/bb55a533af349d7c35958266262f7722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var globalCartoDB_SQL_Layer = null; | |
$("#btn_runquery").click(function() { | |
var query = $("#sqlcommand").text(); | |
var cartocss = $("#cartocss").text(); | |
runSQL_API(query); | |
updatemap(query, cartocss); | |
}) | |
function createMap() { | |
window.map = new L.Map('mapresult', { | |
center: [63.5, 10.5], | |
zoom: 4 | |
}); | |
window.cartodb_basemap = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { | |
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>' | |
}).addTo(map); | |
var url = "http://wms3.nve.no/map/services/SkredSnoAktR/MapServer/WmsServer"; | |
var layer = "Snoskred-Aktsomhetsomrader"; | |
var skredfare = L.tileLayer.wms(url, { | |
layers: layer, | |
format: 'image/png', | |
transparent: true, | |
attribution: "NVE eier alt dette" | |
}).addTo(map); | |
cartodb.createLayer(map, 'https://alexanno-test.cartodb.com/api/v2/viz/07773f86-ff57-11e5-bc60-0ecfd53eb7d3/viz.json') | |
.addTo(map) | |
.on('done', function(layer) { | |
window.cdblayer = layer; | |
globalCartoDB_SQL_Layer = layer.createSubLayer({ | |
sql: 'null', | |
cartocss: '#layer {}' | |
}); | |
}) | |
.on('error', function(err) { | |
alert("some error occurred: " + err); | |
}); | |
//add click => run sql-query on dwithin | |
} | |
createMap(); | |
function updatemap(sql, cartocss) { | |
globalCartoDB_SQL_Layer.setCartoCSS(cartocss); | |
globalCartoDB_SQL_Layer.setSQL(sql); | |
} | |
function runSQL_API(sql) { | |
console.log("run sql ", sql); | |
$.getJSON('https://alexanno-test.cartodb.com/api/v2/sql/?format=geojson&q=' + sql, function(data) { | |
console.log("data returnert fra sql api:", data); | |
$("#dataresult").text(JSON.stringify(data, null, 2).substr(0, 15000)); | |
Prism.highlightAll(); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment