1 | $(document).ready(function () { |
---|
2 | $('#id_coordenadas_div_map').attr({ |
---|
3 | 'class': 'col-md-10 col-md-offset-2 text-center' |
---|
4 | }); |
---|
5 | |
---|
6 | var clearFeatures = $('.clear_features a'); |
---|
7 | clearFeatures.text('Eliminar selección'); |
---|
8 | clearFeatures.attr({ |
---|
9 | class: 'btn btn-warning' |
---|
10 | }); |
---|
11 | $("#id_map_cartografico").fileinput({ |
---|
12 | showCaption: true, |
---|
13 | previewFileType: "image", |
---|
14 | browseClass: "btn btn-danger", |
---|
15 | browseLabel: "Subir Imagen del mapa cartográfico", |
---|
16 | browseIcon: "<i class=\"glyphicon glyphicon-picture\"></i> ", |
---|
17 | removeLabel: "Eliminar", |
---|
18 | uploadLabel: "Actualizar" |
---|
19 | }); |
---|
20 | |
---|
21 | map = new ol.Map('id_coordenadas_map'); |
---|
22 | }); |
---|
23 | |
---|
24 | /** |
---|
25 | * @brief Función que permite cargar los datos geográficos de una comunidad seleccionada |
---|
26 | * |
---|
27 | * @author Ing. Roldan Vargas <rvargas@cenditel.gob.ve> |
---|
28 | * @copyright <a href='http://www.gnu.org/licenses/gpl-2.0.html'>GNU Public License versión 2 (GPLv2)</a> |
---|
29 | * @param data_selected Identificador de la comunidad seleccionada |
---|
30 | * @return Retorna falso en caso de que no se haya seleccionado ninguna comunidad |
---|
31 | */ |
---|
32 | function cargar_datos_ubicacion(data_selected) { |
---|
33 | if (data_selected) { |
---|
34 | var image = new ol.style.Circle({ |
---|
35 | radius: 5, |
---|
36 | fill: null, |
---|
37 | stroke: new ol.style.Stroke({color: 'red', width: 1}) |
---|
38 | }); |
---|
39 | var styles = { |
---|
40 | 'Point': new ol.style.Style({ |
---|
41 | image: image |
---|
42 | }), |
---|
43 | 'LineString': new ol.style.Style({ |
---|
44 | stroke: new ol.style.Stroke({ |
---|
45 | color: 'green', |
---|
46 | width: 1 |
---|
47 | }) |
---|
48 | }), |
---|
49 | 'MultiLineString': new ol.style.Style({ |
---|
50 | stroke: new ol.style.Stroke({ |
---|
51 | color: 'green', |
---|
52 | width: 1 |
---|
53 | }) |
---|
54 | }), |
---|
55 | 'MultiPoint': new ol.style.Style({ |
---|
56 | image: image |
---|
57 | }), |
---|
58 | 'MultiPolygon': new ol.style.Style({ |
---|
59 | stroke: new ol.style.Stroke({ |
---|
60 | color: 'yellow', |
---|
61 | width: 1 |
---|
62 | }), |
---|
63 | fill: new ol.style.Fill({ |
---|
64 | color: 'rgba(255, 255, 0, 0.1)' |
---|
65 | }) |
---|
66 | }), |
---|
67 | 'Polygon': new ol.style.Style({ |
---|
68 | stroke: new ol.style.Stroke({ |
---|
69 | color: 'blue', |
---|
70 | lineDash: [4], |
---|
71 | width: 3 |
---|
72 | }), |
---|
73 | fill: new ol.style.Fill({ |
---|
74 | color: 'rgba(0, 0, 255, 0.1)' |
---|
75 | }) |
---|
76 | }), |
---|
77 | 'GeometryCollection': new ol.style.Style({ |
---|
78 | stroke: new ol.style.Stroke({ |
---|
79 | color: 'magenta', |
---|
80 | width: 2 |
---|
81 | }), |
---|
82 | fill: new ol.style.Fill({ |
---|
83 | color: 'magenta' |
---|
84 | }), |
---|
85 | image: new ol.style.Circle({ |
---|
86 | radius: 10, |
---|
87 | fill: null, |
---|
88 | stroke: new ol.style.Stroke({ |
---|
89 | color: 'magenta' |
---|
90 | }) |
---|
91 | }) |
---|
92 | }), |
---|
93 | 'Circle': new ol.style.Style({ |
---|
94 | stroke: new ol.style.Stroke({ |
---|
95 | color: 'red', |
---|
96 | width: 2 |
---|
97 | }), |
---|
98 | fill: new ol.style.Fill({ |
---|
99 | color: 'rgba(255,0,0,0.2)' |
---|
100 | }) |
---|
101 | }) |
---|
102 | }; |
---|
103 | var styleFunction = function(feature) { |
---|
104 | console.log(feature.getGeometry().getType()) |
---|
105 | return styles[feature.getGeometry().getType()]; |
---|
106 | }; |
---|
107 | axios.get('/cargar-geometria?comunidad_id='+data_selected) |
---|
108 | .then(function (response) { |
---|
109 | //console.log(document.getElementById('id_coordenadas_div_map')) |
---|
110 | var geojsonObject = { |
---|
111 | 'type': 'FeatureCollection', |
---|
112 | 'crs': { |
---|
113 | 'type': 'name', |
---|
114 | 'properties': { |
---|
115 | 'name': 'EPSG:3857' |
---|
116 | } |
---|
117 | }, |
---|
118 | 'features': [{ |
---|
119 | 'type': 'Feature', |
---|
120 | 'geometry': JSON.parse(response.data.coordenadas), |
---|
121 | 'properties': { |
---|
122 | 'name': 'Comunidad [' + response.data.comunidad + ']' |
---|
123 | } |
---|
124 | }] |
---|
125 | }; |
---|
126 | //console.log(geojsonObject); |
---|
127 | /*var map = new ol.Map({ |
---|
128 | layers: [new ol.layer.Vector({ |
---|
129 | source: new ol.source.Vector({ |
---|
130 | features: (new ol.format.GeoJSON()).readFeatures(geojsonObject) |
---|
131 | }), |
---|
132 | style: styleFunction |
---|
133 | })], |
---|
134 | target: 'id_coordenadas_div_map', |
---|
135 | controls: ol.control.defaults({ |
---|
136 | attributionOptions: { |
---|
137 | collapsible: false |
---|
138 | } |
---|
139 | }), |
---|
140 | view: new ol.View({ |
---|
141 | center: [0, 0], |
---|
142 | zoom: 2 |
---|
143 | }) |
---|
144 | });*/ |
---|
145 | var map = new ol.Map('id_coordenadas_div_map'); |
---|
146 | map.addLayer(new ol.layer.Vector({ |
---|
147 | source: new ol.source.Vector({ |
---|
148 | features: (new ol.format.GeoJSON()).readFeatures(geojsonObject) |
---|
149 | }), |
---|
150 | style: ol.style.Style({ |
---|
151 | stroke: new ol.style.Stroke({ |
---|
152 | color: 'blue', |
---|
153 | lineDash: [4], |
---|
154 | width: 3 |
---|
155 | }), |
---|
156 | fill: new ol.style.Fill({ |
---|
157 | color: 'rgba(0, 0, 255, 0.1)' |
---|
158 | }) |
---|
159 | }) |
---|
160 | })); |
---|
161 | //console.log(response.data.coordenadas); |
---|
162 | }) |
---|
163 | .catch(function (error) { |
---|
164 | // handle error |
---|
165 | console.log(error); |
---|
166 | }); |
---|
167 | |
---|
168 | } |
---|
169 | } |
---|