<commit_before>/*jslint browser: true*/
/*global _*/
/*global $*/
/*global GDP.util.BaseView*/
/*global GDP.util.SelectMenuView*/
/*global GDP.util.mapUtils*/
/*global GDP.OGC.WFS*/

var GDP = GDP || {};

GDP.ADVANCED = GDP.ADVANCED || {};

GDP.ADVANCED.view = GDP.ADVANCED.view || {};


(function() {
	"use strict";
	GDP.ADVANCED.view.SpatialView = GDP.util.BaseView.extend({

		events : {
			'change #select-aoi' : 'changeName',
			'change #select-attribute' : 'changeAttribute',
			'change #select-values' : 'changeValues'
		},

		render : function() {
			GDP.util.BaseView.prototype.render.apply(this, arguments);
			this.map.render('spatial-map');
			this.map.zoomToExtent(this.map.getMaxExtent(), true);
		},

		initialize : function(options) {
			var baseLayers = [GDP.util.mapUtils.createWorldStreetMapLayer()];
			var controls = [
				new OpenLayers.Control.Navigation(),
				new OpenLayers.Control.MousePosition({
					prefix: 'POS: ',
					numDigits: 2,
					displayProjection: GDP.util.mapUtils.WGS84_GEOGRAPHIC
				}),
				new OpenLayers.Control.ScaleLine({
					geodesic: true
				}),
				new OpenLayers.Control.Zoom()
			];

			this.aoiLayer = null;
			this.highlightLayer = null;

			this.map = GDP.util.mapUtils.createMap(baseLayers, controls);

			GDP.util.BaseView.prototype.initialize.apply(this, arguments);

			this.nameSelectMenuView = new GDP.util.SelectMenuView({
				el : '#select-aoi',
				emptyPlaceholder : true,
				sortOptions: true
			});
			this.attributeSelectMenuView = new GDP.util.SelectMenuView({
				el : '#select-attribute',
				emptyPlaceholder : true,
				sortOptions: true
			});
			this.attributeValuesSelectMenuView = new GDP.util.SelectMenuView({
				el : '#select-values',
				emptyPlaceholder : true,
				sortOptions: true
			});

			this.getAvailableFeatures().then(
				function() {
					return;
				},
				function() {
					GDP.logger.error('GDP.view.SpatialView getAvailableFeatures failed');
				}
			);
			this.updateAOILayer();
			this.listenTo(this.model, 'change:aoiName', this.updateAttributes);
			this.listenTo(this.model, 'change:aoiName', this.updateAOILayer);
			this.listenTo(this.model, 'change:aoiAttribute', this.updateValues);
			this.listenTo(this.model, 'change:aoiAttributeValues', this.highlightFeatures);
		},

		getAvailableFeatures : function() {
			var populateFeatureTypesSelectBox = _.bind(function(data) {
				var optionValues = [];
				this.nameSelectMenuView.$el.val(null);
				$(data).find('FeatureType').each(function() {
					optionValues.push($(this).find('Name').text());
				});
				this.nameSelectMenuView.updateMenuOptions(optionValues);
			}, this);

			return GDP.OGC.WFS.callWFS(
				{
					request : 'GetCapabilities'
				},
				false,
				populateFeatureTypesSelectBox
			);
		},

		changeName : function(ev) {
			this.model.set('aoiName', ev.target.value);
		},

		changeAttribute : function(ev) {
			this.model.set('aoiAttribute', ev.target.value);
		},

		changeValues : function(ev) {
			var aoiAttributeValues = _.pluck(ev.target.selectedOptions, 'value');
			this.model.set('aoiAttributeValues', aoiAttributeValues);
		},

		updateAOILayer : function() {
			var name = this.model.get('aoiName');
			if (name) {
				if (this.aoiLayer) {
					this.aoiLayer.mergeNewParams({
						layers : name
					});
				}
				else {
					this.aoiLayer = new OpenLayers.Layer.WMS(
						"Area of Interest",
						GDP.config.get('application').endpoints.geoserver + '/wms?',
						{
							layers : name,
							transparent : true
						},
						{<commit_msg>Fixed bug where the changeValues method was not picking up the text field for the option selected.<commit_after>/*jslint browser: true*/
/*global _*/
/*global $*/
/*global GDP.util.BaseView*/
/*global GDP.util.SelectMenuView*/
/*global GDP.util.mapUtils*/
/*global GDP.OGC.WFS*/

var GDP = GDP || {};

GDP.ADVANCED = GDP.ADVANCED || {};

GDP.ADVANCED.view = GDP.ADVANCED.view || {};


(function() {
	"use strict";
	GDP.ADVANCED.view.SpatialView = GDP.util.BaseView.extend({

		events : {
			'change #select-aoi' : 'changeName',
			'change #select-attribute' : 'changeAttribute',
			'change #select-values' : 'changeValues'
		},

		render : function() {
			GDP.util.BaseView.prototype.render.apply(this, arguments);
			this.map.render('spatial-map');
			this.map.zoomToExtent(this.map.getMaxExtent(), true);
		},

		initialize : function(options) {
			var baseLayers = [GDP.util.mapUtils.createWorldStreetMapLayer()];
			var controls = [
				new OpenLayers.Control.Navigation(),
				new OpenLayers.Control.MousePosition({
					prefix: 'POS: ',
					numDigits: 2,
					displayProjection: GDP.util.mapUtils.WGS84_GEOGRAPHIC
				}),
				new OpenLayers.Control.ScaleLine({
					geodesic: true
				}),
				new OpenLayers.Control.Zoom()
			];

			this.aoiLayer = null;
			this.highlightLayer = null;

			this.map = GDP.util.mapUtils.createMap(baseLayers, controls);

			GDP.util.BaseView.prototype.initialize.apply(this, arguments);

			this.nameSelectMenuView = new GDP.util.SelectMenuView({
				el : '#select-aoi',
				emptyPlaceholder : true,
				sortOptions: true
			});
			this.attributeSelectMenuView = new GDP.util.SelectMenuView({
				el : '#select-attribute',
				emptyPlaceholder : true,
				sortOptions: true
			});
			this.attributeValuesSelectMenuView = new GDP.util.SelectMenuView({
				el : '#select-values',
				emptyPlaceholder : true,
				sortOptions: true
			});

			this.getAvailableFeatures().then(
				function() {
					return;
				},
				function() {
					GDP.logger.error('GDP.view.SpatialView getAvailableFeatures failed');
				}
			);
			this.updateAOILayer();
			this.listenTo(this.model, 'change:aoiName', this.updateAttributes);
			this.listenTo(this.model, 'change:aoiName', this.updateAOILayer);
			this.listenTo(this.model, 'change:aoiAttribute', this.updateValues);
			this.listenTo(this.model, 'change:aoiAttributeValues', this.highlightFeatures);
		},

		getAvailableFeatures : function() {
			var populateFeatureTypesSelectBox = _.bind(function(data) {
				var optionValues = [];
				this.nameSelectMenuView.$el.val(null);
				$(data).find('FeatureType').each(function() {
					optionValues.push($(this).find('Name').text());
				});
				this.nameSelectMenuView.updateMenuOptions(optionValues);
			}, this);

			return GDP.OGC.WFS.callWFS(
				{
					request : 'GetCapabilities'
				},
				false,
				populateFeatureTypesSelectBox
			);
		},

		changeName : function(ev) {
			this.model.set('aoiName', ev.target.value);
		},

		changeAttribute : function(ev) {
			this.model.set('aoiAttribute', ev.target.value);
		},

		changeValues : function(ev) {
			var aoiAttributeValues = _.pluck(ev.target.selectedOptions, 'text');
			this.model.set('aoiAttributeValues', aoiAttributeValues);
		},

		updateAOILayer : function() {
			var name = this.model.get('aoiName');
			if (name) {
				if (this.aoiLayer) {
					this.aoiLayer.mergeNewParams({
						layers : name
					});
				}
				else {
					this.aoiLayer = new OpenLayers.Layer.WMS(
						"Area of Interest",
						GDP.config.get('application').endpoints.geoserver + '/wms?',
						{
							layers : name,
							transparent : true
						},
						{
{'fraction_non_alphanumeric': 0.14997209821428573, 'fraction_numerical': 0.0008370535714285714, 'mean_word_length': 3.408979089790898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808827', 'n_tokens_mistral': 3000, 'n_tokens_neox': 2359, 'n_words': 376}