Commit eaef7387 authored by Rodrigo Tapia-McClung's avatar Rodrigo Tapia-McClung

Fixed map bounds and view. Fixed logic for clicking regions

parent 381c0f14
...@@ -20,8 +20,9 @@ let dateArray = [], ...@@ -20,8 +20,9 @@ let dateArray = [],
timeLayer, timeLayer,
layerControl; layerControl;
let isZoomed = undefined, let bboxes = {},
bboxes = {}; previousClick,
currentClick;
const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090" const baseUrl = new URL(window.location.href).origin; // returns "http://localhost:8090"
// use `${baseUrl}/something` // use `${baseUrl}/something`
...@@ -86,13 +87,11 @@ const setupMap = (dates) => { ...@@ -86,13 +87,11 @@ const setupMap = (dates) => {
attribution: "Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL." attribution: "Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL."
}); });
//let bounds = cuencaBufferMask.getBounds(); let southWest = L.latLng(19.65, -103.10),
let southWest = L.latLng(19.87, -102.87), northEast = L.latLng(22.65, -99.12),
northEast = L.latLng(23.02, -99.31),
bounds = L.latLngBounds(southWest, northEast); bounds = L.latLngBounds(southWest, northEast);
map = L.map("mexmap", { map = L.map("mexmap", {
//center: [17.22, -92.28],
minZoom: 8, minZoom: 8,
zoom: 6, zoom: 6,
attributionControl: false, attributionControl: false,
...@@ -128,7 +127,7 @@ const setupMap = (dates) => { ...@@ -128,7 +127,7 @@ const setupMap = (dates) => {
scrollWheelZoom: true, scrollWheelZoom: true,
attributionControl: false, attributionControl: false,
zoomAnimation: true zoomAnimation: true
}).setView([16.96, -92.97], 8); }).setView([21.15, -100.94], 8);
cartoDarkLayerOverlay.addTo(overlay); cartoDarkLayerOverlay.addTo(overlay);
L.control.attribution({ position: "bottomright" }).addTo(overlay); L.control.attribution({ position: "bottomright" }).addTo(overlay);
...@@ -255,26 +254,24 @@ const populateMap = async (mapData) => { ...@@ -255,26 +254,24 @@ const populateMap = async (mapData) => {
let region = feature.properties.Region; let region = feature.properties.Region;
// populate bboxes object // populate bboxes object
bboxes[region] = layer.getBounds(); bboxes[region] = layer.getBounds();
// what to do when clicking on polygons // what to do when clicking on regions
layer.on( "click", () => { layer.on( "click", () => {
if (!isZoomed) { currentClick = region;
if (currentClick != previousClick) {
map.fitBounds(layer.getBounds()); map.fitBounds(layer.getBounds());
isZoomed = true; $("#regionSelect").val(region).change();
$('#regionSelect').val(region).change();
} else { } else {
map.setView([16.96, -92.97], 8) map.setView([21.15, -100.94], 8);
isZoomed = false; $("#regionSelect")[0].selectedIndex = 0;
$('#regionSelect')[0].selectedIndex = 0 currentClick = undefined;
} }
// TODO: what to do if user clicks, pans, and then clicks another polygon previousClick = currentClick;
// right now it zooms out...
// need to check if clicked polygon is the same as before.
}); });
} }
}); });
let periurbanoBajio = omnivore.geojson("data/periurbanoBajio.geojson", null, periurbanoBajioLayer) let periurbanoBajio = omnivore.geojson("data/periurbanoBajio.geojson", null, periurbanoBajioLayer)
.on('ready', () => { .on("ready", () => {
// populate combobox // populate combobox
$("#regionSelect").append("<option disabled value=\"0\"> -- Selecciona una regi&oacute;n --</option>"); $("#regionSelect").append("<option disabled value=\"0\"> -- Selecciona una regi&oacute;n --</option>");
Object.keys(bboxes).forEach( region => { Object.keys(bboxes).forEach( region => {
...@@ -286,7 +283,7 @@ const populateMap = async (mapData) => { ...@@ -286,7 +283,7 @@ const populateMap = async (mapData) => {
$("#regionSelect").on("change", () => { $("#regionSelect").on("change", () => {
let region = $("#regionSelect").val(); let region = $("#regionSelect").val();
map.fitBounds(bboxes[region]); map.fitBounds(bboxes[region]);
isZoomed = true; previousClick = region;
}); });
}); });
periurbanoBajio.addTo(map); periurbanoBajio.addTo(map);
...@@ -321,7 +318,7 @@ const populateMap = async (mapData) => { ...@@ -321,7 +318,7 @@ const populateMap = async (mapData) => {
if (layer == userFiles[0]) { if (layer == userFiles[0]) {
glmap.getMapboxMap().setPaintProperty(layer, "fill-opacity", 0.7); glmap.getMapboxMap().setPaintProperty(layer, "fill-opacity", 0.7);
} }
}) });
/* glmap.getMapboxMap().addSource("munisLayer", { /* glmap.getMapboxMap().addSource("munisLayer", {
//type: "vector", //type: "vector",
...@@ -350,9 +347,9 @@ const populateMap = async (mapData) => { ...@@ -350,9 +347,9 @@ const populateMap = async (mapData) => {
"line-color": "grey", "line-color": "grey",
"line-width": 5, "line-width": 5,
}, },
'layout': { "layout": {
'line-join': 'round', "line-join": "round",
'line-cap': 'round' "line-cap": "round"
}, },
}); });
*/ */
...@@ -516,7 +513,7 @@ L.TimeDimension.Layer.Tile = L.TimeDimension.Layer.extend({ ...@@ -516,7 +513,7 @@ L.TimeDimension.Layer.Tile = L.TimeDimension.Layer.extend({
} else { } else {
glmap.getMapboxMap().setPaintProperty(layer, "fill-opacity", 0.7); glmap.getMapboxMap().setPaintProperty(layer, "fill-opacity", 0.7);
} }
}) });
} }
}); });
......
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