/** Utility Methods **/ /** FeatureInfo_XML_to_DOM Create the DOM from the GetFeatureInfo XML **/ function FeatureInfo_XML_to_DOM ( url ) { $$("cf1-resizer").show(); $$("cf1").show(); map.updateSize(); $.ajax ({ url: '/webgis/xml-parser', method: 'POST', data: { url: url[0] }, success: function (data) { var nc = null; var tab_id_linker = { tab: nc, id: Q_COUNTER, position: V_COUNTER-1 } VISIBLE_TABS_ARRAY.push(nc); VISIBLE_TABS_TABBAR_ARRAY.push(tab_id_linker); change_active_marker(V_COUNTER-1); // save the result for new interrogation on the same object QUERY_DATA_ARRAY.push(data); if(V_COUNTER != 5) { map.addInteraction(DRAW); } var html_res = '
' + ''+ V_COUNTER +'' + data + '
'; QUERYABLE_STRING += html_res; $("#confronto").html(QUERYABLE_STRING); changeActiveMarker (V_COUNTER); } }); } /** * query_popup_activation * Activate query on map with popup */ function query_popup_activation () { POPUP_QUERY = true; } /** * query_popup_deactivation * Deactivate query on map with popup */ function query_popup_deactivation () { POPUP_QUERY = false; popup.hide(); } /** * show_popup * Show popup contents on map */ function show_popup (url , coordinate){ //console.log(url); $('#map').css('cursor','wait'); $.ajax({ url: '/webgis/popup', data: { url: url}, method: 'POST', success: function (data) { popup.show(coordinate, data); $('#map').css('cursor','pointer'); } }); } /** query_point_activation Activate the point drawing for user point selection check **/ function query_point_activation () { DRAW = new ol.interaction.Draw({ source: DRAW_VECTOR_SOURCE, type: /** @type {ol.geom.GeometryType} */ ('Point'), style: overlayMarkerStyleGlyph }); map.addInteraction(DRAW); DRAW.on('drawend', function(e) { map.removeInteraction(DRAW); Q_COUNTER = update_counter(); V_COUNTER++; e.feature.setProperties({ 'tabid': Q_COUNTER.toString(), 'color': '#A4B4BF' }) // FeatureInfoUrl generation var URLS = []; var viewResolution = /** @type {number} */ (map.getView().getResolution()); for ( var i in VISIBLE_LAYERS_SOURCES ) { var url = VISIBLE_LAYERS_SOURCES[i].getGetFeatureInfoUrl( e.feature.getGeometry().getCoordinates(), viewResolution, 'EPSG:3857', { 'INFO_FORMAT': 'text/xml', 'FI_POINT_TOLERANCE': '30' }); URLS.push ( url ); } FeatureInfo_XML_to_DOM ( URLS ); }); } /** query_point_deactivation Activate the point drawing for user point selection check **/ function query_point_deactivation () { DRAW_VECTOR_SOURCE.clear(); map.removeInteraction(DRAW); QUERY_DATA_ARRAY = []; /** for (vt in VISIBLE_TABS_ARRAY) { $$("tw1").removeView(VISIBLE_TABS_ARRAY[vt]); } */ VISIBLE_TABS_ARRAY = []; VISIBLE_TABS_TABBAR_ARRAY = []; ACTIVE_TAB = 0; Q_COUNTER = 0; V_COUNTER = 0; $$("cf1-resizer").hide(); $$("cf1").hide(); QUERYABLE_STRING = ''; ACTIVE_MARKER = 0; //$$("hori").hide(); map.updateSize(); } /** add_sw_interaction Activate street view interaction **/ function add_sw_interaction () { SW = new ol.interaction.Draw({ source: SW_VECTOR_SOURCE, type: /** @type {ol.geom.GeometryType} */ ('Point'), style: overlayMarkerSW }); map.addInteraction(SW); SW.on('drawend', function(e) { map.removeInteraction(SW); var lonlat = ol.proj.transform( e.feature.getGeometry().getCoordinates() , 'EPSG:3857' , 'EPSG:4326' ); show_streetView(lonlat[1],lonlat[0]); }); } /** rem_sw_interaction Activate the point drawing for user point selection check **/ function rem_sw_interaction () { SW_VECTOR_SOURCE.clear(); map.removeInteraction(SW); } /** * changeMarkerStyleGlyph * Used for change visible number on * markers */ function changeMarkerStyleGlyph(feature){ var style = new ol.style.Style({ image: new ol.style.FontSymbol({ glyph: feature.getProperties().tabid, form: 'circle', radius: 10, fontSize: 1, offset: true, gradient: false, shadow: true, fill: new ol.style.Fill({ color: feature.getProperties().color }), stroke: new ol.style.Stroke({ color: 'white', width: 3 }) }) }) return [ style ] } /** * overlayMarkerStyleGlyph * Used for change visible number on * markers */ function overlayMarkerStyleGlyph(feature){ var style = new ol.style.Style({ image: new ol.style.FontSymbol({ glyph: '?', form: 'circle', radius: 10, fontSize: 1, offset: true, gradient: false, shadow: true, fill: new ol.style.Fill({ color: '#ffcc33' }), stroke: new ol.style.Stroke({ color: 'white', width: 3 }) }) }) return [ style ] } /** * overlayMarkerSW * Used for change visible number on * markers */ function overlayMarkerSW(feature){ return new ol.style.Style({ image: new ol.style.FontSymbol({ form: 'circle', gradient: false, glyph: "", fontSize: 1, radius: 10, //offsetX: -15, color: "white", fill: new ol.style.Fill( { color: '#3498DB' }), stroke: new ol.style.Stroke( { color: "white", width: 3 }) }), stroke: new ol.style.Stroke( { width: 2, color: '#f80' }), fill: new ol.style.Fill( { color: [255, 136, 0, 0.6] }) }); } /** * update_counter * Function that evalutate the correct * value of Q_COUNTER */ function update_counter(){ var trovato = false; var iterator = 1; while (!trovato) { prev_iterator = iterator; for ( var x in VISIBLE_TABS_TABBAR_ARRAY ) { if( iterator == VISIBLE_TABS_TABBAR_ARRAY[x].id ) { iterator++; } } if ( prev_iterator == iterator ) { return Number(iterator) } } } /** * change_active_marker * Change the active marker icon on map * Depends on "position" */ function change_active_marker(p){ DRAW_VECTOR_SOURCE.getFeatures()[ACTIVE_TAB].set('color','#A4B4BF'); DRAW_VECTOR_SOURCE.getFeatures()[p].set('color','#ffcc33'); ACTIVE_TAB = p; } /** * update_overlay_layers * Turnaround caused by zIndex problem * due to Webix */ function update_overlay_layers () { map.removeLayer(ACTUAL_MAP_OVERLAY); map.addLayer(ACTUAL_MAP_OVERLAY); } /** * remove_j2_from_visible_layers * Turnaround to remove j2 layers * due to ThreeJS problem */ function remove_j2_from_visible_layers ( A ) { // tmp = A; // to_rem = []; // for ( var i in A ) { // if ( A[i].substring(0,2) === 'j2') { // to_rem.push(i); // } // } // console.log(A); // console.log(to_rem); // A.splice ( to_rem[0] , to_rem.length); for ( var i in A ) { if ( A[i].substring(0,2) === 'j2') { A[i] = ''; } } return A; } /** * Show streetview by lon/lat * @param {number} lat * @param {number} lon */ var show_streetView = function ( lat, lon){ $('#street-view-frame').attr('src','https://www.google.com/maps/embed/v1/streetview?key=AIzaSyC61Wn460QfwHGfh5e9fK_ThdnZMr-vMhY&location='+lat+','+lon+'&heading=210&pitch=10&fov=35'); sw_popup.show(); } /** * Change map to current view * @param {string} uri */ var change_map = function ( uri ) { var url = window.location.href; var path = window.location.pathname; url = url.split('#')[1]; path = path.split('/')[1] location.href = uri + '#' + url; } /** * Change active marker logic * @param {number} id */ var changeActiveMarker = function ( id ) { $('#badge_' + ACTIVE_MARKER).removeClass('badge-primary').addClass('badge-default'); $('#badge_' + id).removeClass('badge-default').addClass('badge-primary'); ACTIVE_MARKER = id; } var changeActiveMarkerByClick = function ( id ) { changeActiveMarker(id); change_active_marker(id-1); } /** * Identify feature on map (orange function) */var identifyFeatureOnMap = function ( layer_name , feature_id ) { fid = Number ( feature_id ); // IDENTIFY_ON_MAP_SOURCE is the source of "identifyOnMapLayer" IDENTIFY_ON_MAP_SOURCE.clear(); layer_name = layer_name.replace(/ /g,'_'); feature_id = layer_name + '.' + feature_id; var extent = map.getView().calculateExtent(); proj4.defs("EPSG:32633","+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs"); extent = ol.proj.transformExtent( extent , 'EPSG:3857' , 'EPSG:32633' ); $.ajax({ url: MAP_WMS, data: { service: 'WFS', version: '1.0.0', request: 'GetFeature', typename: layer_name, featureid: feature_id, srsname: 'EPSG:32633', bbox: extent.join(',') + ',EPSG:32633' }, success: function(data){ try { var gml_features = new ol.format.GML2().readFeatures(data, { dataProjection: 'EPSG:32633', featureProjection: 'EPSG:3857', zindex: 2 }); IDENTIFY_ON_MAP_SOURCE.addFeatures ( gml_features ); var extent = IDENTIFY_ON_MAP_SOURCE.getExtent(); map.getView().fit(extent, map.getSize()); } catch(error) { alert ( "Layer non selezionabile tramite questa operazione." ) } } }); }