Skip to content

Commit

Permalink
Indicar nova URL geocodificador
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelfb committed Apr 25, 2024
1 parent 0c3e5cc commit 27100fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Visor Proves Geocodificador</title>
<title>Visor Geocodificador ICGC - exemple ESRI</title>
<style>
html,
body,
Expand Down Expand Up @@ -78,10 +78,12 @@

// WIDGET de TOGGLE
view.ui.add(toggle, "top-right"); //Afegeixo widget de toggle a dalt a la dreta

});

function zoomToScale(zoom) {
// Pas de nivells de zoom a escala. E zoom no funciona amb webmaps coma mapa base
console.info("dins zoomToScale "+zoom);
var scale;
switch (zoom) {
case '20': scale = 1128.497220;break;
Expand Down
3 changes: 2 additions & 1 deletion js/capes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ var construirCapes = {} = function(MapView,WebMap,Layer,MapImageLayer,Portal,Bas
});
var xcenter = 1.677472;
var ycenter = 41.761689;
console.info(xcenter + " " + ycenter);
var view = new MapView({
container: "viewDiv",
map: map,
center: [xcenter, ycenter], // longitude, latitude
//zoom: zoom, ---> Si utilitzes com base un WebMap posa sempre el zoom inicial de tot el mapa
scale: zoomToScale(12)
scale: zoomToScale('10')
});

var toggle = new BasemapToggle({
Expand Down
25 changes: 16 additions & 9 deletions js/cercadorPelias.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@


var customSearchSource = function(Graphic,esriRequest,MapView,Search,SearchSource,geometryEngine,Point) {
var url = "https://aws.icgc.cat/cerca_pelias/autocomplete";
//var url = "https://aws.icgc.cat/cerca_pelias/autocomplete";
var url = "https://eines.icgc.cat/geocodificador/autocompletar";

return new SearchSource({
// Objecte SearchSource https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html
// Property: placeholder, getResults, getSuggestions ...
placeholder: "example: Nou 3,Blanes",
placeholder: "example: Nou 3,girona",

getSuggestions: function(params) {
// Utilitza el GetSuggestionsParameters -> objecte 'params' https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html#GetSuggestionsParameters
Expand All @@ -23,14 +24,15 @@
// GEOCODIFCADOR PELIAS: Parametres de cosulta . Ex.: https://aws.icgc.cat/cerca_pelias/autocomplete?text=nou%203%2Cblanes&layers=mun%2Caddress%2Ctopo%2Cpois%2Ccom%2Cpk&size=50
query: {
text: params.suggestTerm.replace(/ /g, "+"),
layers: 'mun,address,topo,pois,com,pk',
size: 50
layers: 'topo1,topo2,address',
size: 5

},

responseType: "json"

}).then(function(results) {
}).then(function(results) {
console.info(results);
// Exemple resposta:
// results.data = {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[2.179517,42.369386]},"properties":{"layer":"topo","label":"Salt del Grill, Queralbs","mun":"Queralbs","topo":"Salt del Grill"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.181295,42.369894]},"properties":{"layer":"topo","label":"Solaneta del Salt del Grill, Queralbs","mun":"Queralbs","topo":"Solaneta del Salt del Grill"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.176289,42.379413]},"properties":{"layer":"topo","label":"Torrent del Salt del Grill","mun":"(null)","topo":"Torrent del Salt del Grill"}}],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}
return results.data.features.map(function(feature) {
Expand All @@ -48,17 +50,20 @@
getResults: function(params) {
// Utilitza el getResultsHandle -> obejcte 'params' https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html#GetResultsHandler
// Amb 'params' capturem el que ha escollit l'usuari despres de llistar els resultats en el droplist de la caixeta de cerca o el text que hi ha a ala caixeta i hem fet clic al botó de cerca de la caixa.

console.info(params);

var query = {};

if (params.location) {
query.lat = params.location.latitude;
query.lon = params.location.longitude;
} else {
query.text = params.suggestResult.text.replace(/ /g, "+"); //fem la consulta a Pellias sobre el suggrest triat per l'usuari en el droplist. https://aws.icgc.cat/cerca_pelias/autocomplete?text=salt%20del%20grill
query.layers = 'mun,address,topo,pois,com,pk';
query.size = 50;
}
// query.layers = 'mun,address,topo,pois,com,pk';
query.layers = 'topo1,topo2,address';
query.size = 5;
}
console.info(url);
return esriRequest(url, {
// Utilitzem esri.request (retorna un Promise) -> https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html
// i Request options: -> https://developers.arcgis.com/javascript/latest/api-reference/esri-request.html#RequestOptions
Expand All @@ -67,6 +72,8 @@
query: query,
responseType: "json"
}).then(function(results) {
console.info(results);

// Exemple resposta:
// results.data = {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[2.179517,42.369386]},"properties":{"layer":"topo","label":"Salt del Grill, Queralbs","mun":"Queralbs","topo":"Salt del Grill"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.181295,42.369894]},"properties":{"layer":"topo","label":"Solaneta del Salt del Grill, Queralbs","mun":"Queralbs","topo":"Solaneta del Salt del Grill"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.176289,42.379413]},"properties":{"layer":"topo","label":"Torrent del Salt del Grill","mun":"(null)","topo":"Torrent del Salt del Grill"}}],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}
var searchResults = results.data.features.map(function(feature) {
Expand Down

0 comments on commit 27100fb

Please sign in to comment.