diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2019-02-06 19:08:42 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:38:56 +0200 |
commit | b45b4353785924420078aad98ef5fb0fb26336fe (patch) | |
tree | 40856bb52074133833bb506a57118d11b96a0dfa /ishtar_common/static/js/ishtar-map.js | |
parent | 22a582672453c5ffcc1cd559e83414af1d2fe08c (diff) | |
download | Ishtar-b45b4353785924420078aad98ef5fb0fb26336fe.tar.bz2 Ishtar-b45b4353785924420078aad98ef5fb0fb26336fe.zip |
Sheet - Map: WIP - manage vector source for polygons
Diffstat (limited to 'ishtar_common/static/js/ishtar-map.js')
-rw-r--r-- | ishtar_common/static/js/ishtar-map.js | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index 226767914..ceef3a59e 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -52,6 +52,18 @@ var get_icon_style = function(feature){ }); }; +var get_vector_style = function(feature){ + return 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 cluster_get_style = function(feature, resolution){ feature.set('key', 'cluster'); var cluster_features = feature.get('features'); @@ -356,6 +368,9 @@ var proj_options = { var geojson_format = new ol.format.GeoJSON(proj_options); var wkt_format = new ol.format.WKT(proj_options); var link_template; +var vector_source; +var vector_layer; +var vector_features; var initialize_base_map = function(layers){ center = wkt_format.readGeometry(map_default_center).getCoordinates(); @@ -385,27 +400,56 @@ var redraw_map = function(layers){ }; -var display_map = function(current_map_id, points, layers){ - link_template = points['link_template']; +var display_map = function(current_map_id, points, lines_and_polys, layers){ + if (points){ + link_template = points['link_template']; + } else { + /// link_template = lines_and_polys['link_template']; + } map_id = current_map_id; if (map){ redraw_map(layers); } else { initialize_base_map(layers); } - point_features = geojson_format.readFeatures(points); + display_points(points); + display_lines_and_polys(lines_and_polys); - enable_clustering(); - cluster_source.getSource().addFeatures(point_features); init_popup(); + map.on('click', manage_click_on_map); + map.on('pointermove', manage_hover); +}; + +var display_points = function(points){ + if (!points) return; + point_features = geojson_format.readFeatures(points); + enable_clustering(); + cluster_source.getSource().addFeatures(point_features); if (points.features.length){ map_view.fit(cluster_source.getSource().getExtent()); if (map_view.getZoom() > 12){ map_view.setZoom(12); } } +}; - map.on('click', manage_click_on_map); - map.on('pointermove', manage_hover); -} +var display_lines_and_polys = function(lines_and_polys){ + if (!lines_and_polys) return; + vector_features = geojson_format.readFeatures(lines_and_polys); + vector_source = new ol.source.Vector(); + vector_layer = new ol.layer.Vector({ + source: vector_source, + style: get_vector_style + }); + vector_source.addFeatures(vector_features); + vector_source.addFeature(new ol.Feature( + new ol.geom.Circle([6.079860710813087, 43.11452983279191], 2))) ; + map_layers.push(vector_layer); + if (lines_and_polys.features.length){ + map_view.fit(vector_source.getExtent()); + if (map_view.getZoom() > 12){ + map_view.setZoom(12); + } + } +}; |