summaryrefslogtreecommitdiff
path: root/chimere/static
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-11-17 19:18:01 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-11-17 19:18:01 +0100
commit36ce27b2341edc9c9377f87c677be707582dc81f (patch)
treee34152d8ba598fb566a4db901dc790921b060764 /chimere/static
parent2c542df05fa321655842872ed3a0412f780acdc7 (diff)
downloadChimère-36ce27b2341edc9c9377f87c677be707582dc81f.tar.bz2
Chimère-36ce27b2341edc9c9377f87c677be707582dc81f.zip
Manage JSON overlay
Diffstat (limited to 'chimere/static')
-rw-r--r--chimere/static/chimere/js/jquery.chimere.js111
1 files changed, 109 insertions, 2 deletions
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js
index 6dbe811..f586e7f 100644
--- a/chimere/static/chimere/js/jquery.chimere.js
+++ b/chimere/static/chimere/js/jquery.chimere.js
@@ -43,7 +43,82 @@ if (typeof language != 'undefined'){
}
}
-// Create a simple layer switcher
+var default_image = new ol.style.Circle({
+ radius: 5,
+ fill: null,
+ stroke: new ol.style.Stroke({ color: 'red', width: 1 })
+});
+
+var default_styles = {
+ 'Point': new ol.style.Style({
+ image: default_image
+ }),
+ 'LineString': new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'green',
+ width: 1
+ })
+ }),
+ 'MultiLineString': new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'green',
+ width: 1
+ })
+ }),
+ 'MultiPoint': new ol.style.Style({
+ image: default_image
+ }),
+ 'MultiPolygon': new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'yellow',
+ width: 1
+ }),
+ fill: new ol.style.Fill({
+ color: 'rgba(255, 255, 0, 0.1)'
+ })
+ }),
+ 'Polygon': new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'blue',
+ lineDash: [4],
+ width: 3
+ }),
+ fill: new ol.style.Fill({
+ color: 'rgba(0, 0, 255, 0.1)'
+ })
+ }),
+ 'GeometryCollection': new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'magenta',
+ width: 2
+ }),
+ fill: new ol.style.Fill({
+ color: 'magenta'
+ }),
+ image: new ol.style.Circle({
+ radius: 10,
+ fill: null,
+ stroke: new ol.style.Stroke({
+ color: 'magenta'
+ })
+ })
+ }),
+ 'Circle': new ol.style.Style({
+ stroke: new ol.style.Stroke({
+ color: 'red',
+ width: 2
+ }),
+ fill: new ol.style.Fill({
+ color: 'rgba(255,0,0,0.2)'
+ })
+ })
+};
+
+var defaultStyleFunction = function (feature) {
+ return default_styles[feature.getGeometry().getType()];
+};
+
+
var default_map_lbl = '';
@@ -1935,7 +2010,39 @@ function transformCoordToLonLat(coord) {
settings.editionSource.clear();
},
// add json layer
- addJSON: function(json_url){
+ addJSON: function(json_url, title, projection, style){
+ if (typeof projection == 'undefined' || !projection)
+ projection = EPSG_DISPLAY_PROJECTION;
+ if (projection.substring(0, 5) != "EPSG:")
+ projection = "EPSG:" + projection;
+
+ if (typeof style == 'undefined' || !style)
+ style = defaultStyleFunction;
+
+ var vector = new ol.layer.Vector({
+ title: title,
+ source: new ol.source.Vector(),
+ style: style
+ });
+
+ settings.map.addLayer(vector);
+ var format = new ol.format.GeoJSON();
+
+ if (json_url.substring(0, 4) != "http")
+ json_url = window.location.origin + json_url;
+ $.ajax({url: json_url,
+ dataType: "json",
+ success: function (data) {
+ vector.getSource().addFeatures(
+ format.readFeatures(
+ data, {
+ featureProjection: EPSG_PROJECTION,
+ dataProjection: projection}
+ )
+ );
+ }
+ });
+
// TODO ol3 : json
/*
var jsonStyle = new OpenLayers.Style({