"use strict"; var netgis = netgis || {}; netgis.Menu = function() { this.client = null; this.root = null; this.sections = []; }; netgis.Menu.prototype.load = function() { this.root = document.createElement( "header" ); this.root.className = "netgis-menu netgis-primary netgis-shadow"; //TODO: refactor into abstract bar class (see toolbar) ? var wrapper = document.createElement( "div" ); this.root.appendChild( wrapper ); var toggle = this.createButton( 'Ebenen', true ); toggle.addEventListener( "click", this.onToggleClick.bind( this ) ); ////this.root.appendChild( toggle ); wrapper.appendChild( toggle ); var search = this.createButton( 'Suche', true ); search.addEventListener( "click", this.onSearchPlaceClick.bind( this ) ); ////this.root.appendChild( search ); wrapper.appendChild( search ); var searchParcel = this.createButton( 'Flurstücke', true ); searchParcel.addEventListener( "click", this.onSearchParcelClick.bind( this ) ); wrapper.appendChild( searchParcel ); /*var title = this.createButton( 'GeoPortal', false ); title.classList.remove( "netgis-hover-primary" ); //TODO: createText function? //title.style.padding = "0mm"; this.root.appendChild( title );*/ if ( this.client.editable ) { // Draw Menu var draw = this.createMenu( 'Zeichnen' ); var drawItems = draw.getElementsByTagName( "ul" )[ 0 ]; ////this.root.appendChild( draw ); wrapper.appendChild( draw ); drawItems.appendChild( this.createMenuItem( 'Punkte', this.onDrawPointClick.bind( this ) ) ); drawItems.appendChild( this.createMenuItem( 'Linien', this.onDrawLineClick.bind( this ) ) ); drawItems.appendChild( this.createMenuItem( 'Polygone', this.onDrawPolygonClick.bind( this ) ) ); // Edit Menu var edit = this.createMenu( 'Bearbeiten' ); var editItems = edit.getElementsByTagName( "ul" )[ 0 ]; ////this.root.appendChild( edit ); wrapper.appendChild( edit ); editItems.appendChild( this.createMenuItem( 'Ausschneiden', this.onCutFeatureClick.bind( this ) ) ); editItems.appendChild( this.createMenuItem( 'Verschieben', this.onModifyFeaturesClick.bind( this ) ) ); editItems.appendChild( this.createMenuItem( 'Löschen', this.onDeleteFeaturesClick.bind( this ) ) ); editItems.appendChild( this.createMenuItem( 'Puffern', this.onBufferFeatureClick.bind( this ) ) ); // Import Menu var importMenu = this.createMenu( 'Import' ); //this.root.appendChild( importMenu ); wrapper.appendChild( importMenu ); //fileItems.appendChild( this.createMenuItem( 'OWS-Context', this.onImportOWSClick.bind( this ) ) ); var importItem = importMenu.getElementsByTagName( "ul" )[ 0 ]; importItem.appendChild( this.createMenuItem( 'GeoJSON', this.onImportGeoJSONClick.bind( this ) ) ); //fileItems.appendChild( this.createMenuItem( 'KML', this.onImportKMLClick.bind( this ) ) ); importItem.appendChild( this.createMenuItem( 'GML', this.onImportGMLClick.bind( this ) ) ); importItem.appendChild( this.createMenuItem( 'Shapefile', this.onImportShapefileClick.bind( this ) ) ); importItem.appendChild( this.createMenuItem( 'Spatialite', this.onImportSpatialiteClick.bind( this ) ) ); importItem.appendChild( this.createMenuItem( 'GeoPackage', this.onImportGeopackageClick.bind( this ) ) ); // Export var exportMenu = this.createMenu( 'Export' ); ////this.root.appendChild( exportMenu ); wrapper.appendChild( exportMenu ); var exportItems = exportMenu.getElementsByTagName( "ul" )[ 0 ]; exportItems.appendChild( this.createMenuItem( 'PDF', this.onExportPDFClick.bind( this ) ) ); exportItems.appendChild( this.createMenuItem( 'JPEG', this.onExportJPEGClick.bind( this ) ) ); exportItems.appendChild( this.createMenuItem( 'PNG', this.onExportPNGClick.bind( this ) ) ); exportItems.appendChild( this.createMenuItem( 'GIF', this.onExportGIFClick.bind( this ) ) ); } // Search Menu /*var search = this.createMenu( 'Suche' ); var searchItems = search.getElementsByTagName( "ul" )[ 0 ]; this.root.appendChild( search ); searchItems.appendChild( this.createMenuItem( 'Ortssuche', this.onSearchPlaceClick.bind( this ) ) ); searchItems.appendChild( this.createMenuItem( 'Datensuche', this.onSearchDataClick.bind( this ) ) );*/ // Right Buttons /* var settings = this.createButton( '', true ); this.root.appendChild( settings ); var help = this.createButton( '', true ); this.root.appendChild( help ); */ this.client.root.appendChild( this.root ); }; netgis.Menu.prototype.createButton = function( label, right ) { var button = document.createElement( "button" ); button.setAttribute( "type", "button" ); button.className = "netgis-primary netgis-hover-primary"; if ( right ) button.className += " netgis-right"; button.innerHTML = label; return button; }; netgis.Menu.prototype.createMenu = function( title ) { var menu = document.createElement( "div" ); menu.className = "netgis-dropdown"; var button = document.createElement( "button" ); button.setAttribute( "type", "button" ); button.className = "netgis-primary netgis-hover-primary"; button.innerHTML = title; menu.appendChild( button ); var content = document.createElement( "ul" ); content.className = "netgis-dropdown-content netgis-dialog netgis-shadow"; menu.appendChild( content ); return menu; }; netgis.Menu.prototype.createMenuItem = function( title, callback ) { var item = document.createElement( "li" ); item.className = "netgis-hover-light"; var button = document.createElement( "button" ); button.setAttribute( "type", "button" ); button.innerHTML = title; button.addEventListener( "click", callback ); item.appendChild( button ); return item; }; netgis.Menu.prototype.onToggleClick = function( e ) { this.client.invoke( netgis.Events.LAYER_LIST_TOGGLE, null ); }; netgis.Menu.prototype.onDrawPointClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.DRAW_POINTS ); }; netgis.Menu.prototype.onDrawLineClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.DRAW_LINES ); }; netgis.Menu.prototype.onDrawPolygonClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.DRAW_POLYGONS ); }; netgis.Menu.prototype.onCutFeatureClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.CUT_FEATURE_BEGIN ); }; netgis.Menu.prototype.onModifyFeaturesClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.MODIFY_FEATURES ); }; netgis.Menu.prototype.onDeleteFeaturesClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.DELETE_FEATURES ); }; netgis.Menu.prototype.onBufferFeatureClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.BUFFER_FEATURE_BEGIN ); }; netgis.Menu.prototype.onSearchPlaceClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.SEARCH_PLACE ); }; netgis.Menu.prototype.onSearchParcelClick = function( e ) { this.client.invoke( netgis.Events.SET_MODE, netgis.Modes.SEARCH_PARCEL ); }; netgis.Menu.prototype.onSearchDataClick = function( e ) { alert( "TODO: data search interface" ); }; netgis.Menu.prototype.onImportOWSClick = function( e ) { alert( "TODO: ows import interface, try setting url parameter '?ows='" ); }; netgis.Menu.prototype.onImportShapefileClick = function( e ) { this.client.invoke( netgis.Events.IMPORT_SHAPEFILE_SHOW, null ); }; netgis.Menu.prototype.onImportGeoJSONClick = function( e ) { this.client.invoke( netgis.Events.IMPORT_GEOJSON_SHOW, null ); }; netgis.Menu.prototype.onImportKMLClick = function( e ) { alert( "TODO: kml import interface" ); }; netgis.Menu.prototype.onImportGMLClick = function( e ) { this.client.invoke( netgis.Events.IMPORT_GML_SHOW, null ); }; netgis.Menu.prototype.onImportSpatialiteClick = function( e ) { this.client.invoke( netgis.Events.IMPORT_SPATIALITE_SHOW, null ); }; netgis.Menu.prototype.onImportGeopackageClick = function( e ) { this.client.invoke( netgis.Events.IMPORT_GEOPACKAGE_SHOW, null ); }; netgis.Menu.prototype.onExportPDFClick = function( e ) { this.client.invoke( netgis.Events.EXPORT_PDF_SHOW, null ); }; netgis.Menu.prototype.onExportJPEGClick = function( e ) { this.client.invoke( netgis.Events.EXPORT_JPEG_SHOW, null ); }; netgis.Menu.prototype.onExportPNGClick = function( e ) { this.client.invoke( netgis.Events.EXPORT_PNG_SHOW, null ); }; netgis.Menu.prototype.onExportGIFClick = function( e ) { this.client.invoke( netgis.Events.EXPORT_GIF_SHOW, null ); };