draw states

parent 24a3b528
No preview for this file type
...@@ -61,16 +61,16 @@ $(document).ready(function () { ...@@ -61,16 +61,16 @@ $(document).ready(function () {
}, },
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
// console.log("DATA: ", data.polygonList); if (data.polygonList.length > 0) {
// data.forEach(function(polygon) { var polygon = data.polygonList[0]; // todos los posibles valores para una ciudad
// console.log(polygon); var coordinates = polygon.geojson.geometry.coordinates;
// // Create a new <option> element console.log("DATA: ", polygon);
// var option = document.createElement('option');
// // Set the value using the item in the JSON array coordinates.forEach(coor => {
// option.value = polygon.city + " " + polygon.state; osmap.addPolygon(coor[0]);
// // Add the <option> element to the <datalist>. })
// dataList.appendChild(option); }
// });
$('#ajax-input').autocomplete({ $('#ajax-input').autocomplete({
source: data.polygonList, source: data.polygonList,
minLength: 3 minLength: 3
......
...@@ -85,23 +85,28 @@ OpenStreetMapsClass.prototype.geolocation = function() ...@@ -85,23 +85,28 @@ OpenStreetMapsClass.prototype.geolocation = function()
* Draw a polygon in the map * Draw a polygon in the map
* @param jsonObj Longitude * @param jsonObj Longitude
*/ */
OpenStreetMapsClass.prototype.addPolygon = function(jsonObj) OpenStreetMapsClass.prototype.addPolygon = function(coords)
{ {
// formar coords
var polyCoords = []; var polyCoords = [];
var coords = "-93.69140625,21.371244370618314 -91.845703125,26.273714024406416 -84.462890625,21.207458730482657 -87.978515625,17.47643219719552 -93.69140625,21.371244370618314".split(' '); for (var index in coords) {
var c = coords[index];
for (var i in coords) {
var c = coords[i].split(',');
polyCoords.push(ol.proj.fromLonLat([parseFloat(c[0]), parseFloat(c[1])], 'EPSG:3857', 'EPSG:4326')); polyCoords.push(ol.proj.fromLonLat([parseFloat(c[0]), parseFloat(c[1])], 'EPSG:3857', 'EPSG:4326'));
} }
//todo: remove older features in map, if there is a feature
this.vectorLayer.getSource().clear();
// create feature
var feature = new ol.Feature({ var feature = new ol.Feature({
geometry: new ol.geom.Polygon([polyCoords]) geometry: new ol.geom.Polygon([polyCoords])
}) })
// add feature to map with zoom animation
this.map.getView().fit(feature.getGeometry(), {duration: 1000, padding: [0, 0, 70, 0]}); this.map.getView().fit(feature.getGeometry(), {duration: 1000, padding: [0, 0, 70, 0]});
this.vectorLayer.getSource().addFeature(feature); this.vectorLayer.getSource().addFeature(feature);
// show coords
document.getElementById("id_polygon").value = feature.getGeometry().clone().transform( 'EPSG:3857', 'EPSG:4326').getCoordinates(); document.getElementById("id_polygon").value = feature.getGeometry().clone().transform( 'EPSG:3857', 'EPSG:4326').getCoordinates();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
No preview for this file type
...@@ -53,7 +53,40 @@ def productList(request): ...@@ -53,7 +53,40 @@ def productList(request):
class SearchSubmitView(View): class SearchSubmitView(View):
template = 'map.html' template = 'map.html'
# template = 'search_submit.html' # template = 'search_submit.html'
state_parser = {'31': "Yucatán"} state_parser = {
'01': "Aguascalientes",
'02': "Baja California",
'03': "Baja California Sur",
'04': "Campeche",
'05': "Chiapas",
'06': "Chihuahua",
'07': "Ciudad de México",
'08': "Coahuila",
'09': "Colima",
'10': "Durango",
'11': "Guanajuato",
'12': "Guerrero",
'13': "Hidalgo",
'14': "Jalisco",
'15': "México",
'16': "Michoacán",
'17': "Morelos",
'18': "Nayarit",
'19': "Nuevo León",
'20': "Oaxaca",
'21': "Puebla",
'22': "Querétaro",
'23': "Quintana Roo",
'24': "San Luis Potosí",
'25': "Sinaloa",
'26': "Sonora",
'27': "Tabasco",
'28': "Tamaulipas",
'29': "Tlaxcala",
'30': "Veracruz",
'31': "Yucatán",
'32': "Zacatecas"
}
def post(self, request): def post(self, request):
template = loader.get_template(self.template) template = loader.get_template(self.template)
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment