summaryrefslogtreecommitdiff
path: root/ishtar_common/static
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-02-04 12:46:49 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-24 19:38:56 +0200
commit3f698444f50b2030d7feec21c6f8a60669484bb5 (patch)
treed7cf1f8c7d31f3a8a51d2c532c6b6ba82f440280 /ishtar_common/static
parentf530c2b19904787864b6a9cc1e988da11e524b4b (diff)
downloadIshtar-3f698444f50b2030d7feec21c6f8a60669484bb5.tar.bz2
Ishtar-3f698444f50b2030d7feec21c6f8a60669484bb5.zip
Map: manage default extent and zoom to current extent
Diffstat (limited to 'ishtar_common/static')
-rw-r--r--ishtar_common/static/js/ishtar-map.js64
1 files changed, 52 insertions, 12 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index a8e1a4fa5..ce8f9b616 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -4,6 +4,9 @@ var default_pointer = "../media/images/default-pointer.png";
var view_projection = 'EPSG:3857';
+var map_default_center = 'SRID=4326;POINT (2.4397 46.5528)';
+var map_default_zoom = '7';
+
var source_osm = function(options){
return new ol.layer.Tile({
source: new ol.source.OSM()
@@ -11,7 +14,7 @@ var source_osm = function(options){
};
-var map_layers = {
+var default_map_layers = {
'osm': source_osm
};
@@ -23,7 +26,7 @@ var get_layers = function(layers){
for (idx in layers){
var layer_attr = layers[idx];
ol_layers.push(
- map_layers[layer_attr['type']](layer_attr['options'])
+ default_map_layers[layer_attr['type']](layer_attr['options'])
);
}
return ol_layers;
@@ -67,17 +70,25 @@ var get_style = function(feature){
/* display map */
var vector_source;
var vector_layer;
-var map_layers;
+var center;
var map;
-var geojson_format = new ol.format.GeoJSON(
- {dataProjection:'EPSG:4326', featureProjection: view_projection});
+var map_view;
+var map_layers;
+var proj_options = {
+ dataProjection:'EPSG:4326', featureProjection: view_projection
+}
+var geojson_format = new ol.format.GeoJSON(proj_options);
+var wkt_format = new ol.format.WKT(proj_options);
+var initialize_map = function(map_id, layers){
+ center = wkt_format.readGeometry(map_default_center).getCoordinates();
-var display_map = function(map_id, points, layers){
+ /*
vector_source = new ol.source.Vector({
features: geojson_format.readFeatures(points)
});
-
+ */
+ vector_source = new ol.source.Vector();
vector_layer = new ol.layer.Vector({
source: vector_source,
style: get_style
@@ -85,15 +96,44 @@ var display_map = function(map_id, points, layers){
map_layers = get_layers(layers);
map_layers.push(vector_layer);
+
+ map_view = new ol.View({
+ projection: view_projection,
+ center: ol.proj.fromLonLat([center[0], center[1]]),
+ zoom: map_default_zoom
+ });
+
map = new ol.Map({
target: map_id,
layers: map_layers,
- view: new ol.View({
- projection: view_projection,
- center: ol.proj.fromLonLat([37.41, 8.82]),
- zoom: 4
- })
+ view: map_view
});
}
+var redraw_map = function(map_id, layers){
+ map.setTarget(null);
+ map = null;
+ initialize_map(map_id, layers);
+};
+
+
+var display_map = function(map_id, points, layers){
+ if (map){
+ redraw_map(map_id, layers);
+ } else {
+ initialize_map(map_id, layers);
+ }
+ vector_source.clear();
+ vector_source.addFeatures(geojson_format.readFeatures(points));
+
+ map.updateSize();
+ if (points.features.length){
+ map_view.fit(vector_source.getExtent());
+ if (map_view.getZoom() > 12){
+ map_view.setZoom(12);
+ }
+ }
+
+}
+