Skip to content
Browse files

Merge branch 'addcache'

  • Loading branch information...
2 parents 28d360a + da9870d commit 0cd9ed850de4595a74237cf34fcafa8d0d360584 @smacfarlane smacfarlane committed Feb 8, 2012
Showing with 616 additions and 143 deletions.
  1. +2 −0 .gitignore
  2. +11 −4 Gemfile
  3. +63 −51 Gemfile.lock
  4. +24 −5 app/assets/javascripts/application.js
  5. +17 −17 app/assets/javascripts/makemap/controller/Controls.js
  6. +17 −7 app/assets/javascripts/makemap/controller/Makemap.js
  7. +48 −18 app/assets/javascripts/makemap/controller/Map.js
  8. +5 −0 app/assets/javascripts/makemap/model/SavedMap.js
  9. +12 −0 app/assets/javascripts/makemap/store/SavedMaps.js
  10. +16 −19 app/assets/javascripts/makemap/view/controls.js
  11. +31 −0 app/assets/javascripts/makemap/view/savedlist.js
  12. +9 −0 app/assets/javascripts/makemap/view/savedmap.js
  13. +26 −0 app/assets/javascripts/makemap/view/wizard.js
  14. +33 −0 app/assets/stylesheets/application.css.scss
  15. +29 −3 app/controllers/makemaps_controller.rb
  16. +28 −0 app/models/map_save.rb
  17. +56 −0 app/uploaders/mapimage_uploader.rb
  18. +6 −0 app/views/layouts/makemaps.html.haml
  19. +18 −0 app/views/makemaps/_image.html.erb
  20. +5 −0 app/views/makemaps/index.html.erb
  21. +2 −0 app/views/makemaps/show.html.erb
  22. +6 −6 config/application.rb
  23. +1 −1 config/environments/development.rb
  24. +1 −1 config/routes.rb
  25. +14 −0 db/migrate/20120125195009_create_map_saves.rb
  26. +5 −0 db/migrate/20120126022832_add_layers_to_map_save.rb
  27. +6 −0 db/migrate/20120126023036_add_fields_to_map_save.rb
  28. +8 −0 db/migrate/20120126023702_change_field_names_in_map_save.rb
  29. +5 −0 db/migrate/20120126204106_add_field_to_map_save.rb
  30. +6 −0 db/migrate/20120126213330_rename_field_wmsurl_to_wms_in_map_save.rb
  31. +5 −0 db/migrate/20120127180251_add_mapimage_to_map_save.rb
  32. +9 −0 db/migrate/20120208182547_remove_zoom_level_from_map_save.rb
  33. +30 −0 db/schema.rb
  34. +38 −11 extras/make_map_wms.rb
  35. +17 −0 test/fixtures/map_saves.yml
  36. +7 −0 test/unit/map_save_test.rb
View
2 .gitignore
@@ -6,3 +6,5 @@ tmp/
.idea/
config/database.yml
Capfile
+public/uploads/
+*.swp
View
15 Gemfile
@@ -1,20 +1,22 @@
source 'http://rubygems.org'
-gem 'rails', '3.1.3'
+gem 'rails', '3.2.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-#gem 'sqlite3'
+gem 'sqlite3'
gem 'haml'
gem 'compass', '~> 0.12.alpha.2'
gem 'capistrano'
+gem 'nofxx-georuby', :require => 'geo_ruby'
+
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'sass-rails', '~> 3.1.4'
- gem 'coffee-rails', '~> 3.1.1'
+ gem 'sass-rails', '~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
@@ -36,3 +38,8 @@ group :test do
# Pretty printed test output
gem 'turn', :require => false
end
+
+# Carrierwave/imagemagick gems for image cache
+gem 'carrierwave', :git => "git://github.com/jnicklas/carrierwave.git"
+gem 'rmagick'
+
View
114 Gemfile.lock
@@ -1,36 +1,43 @@
+GIT
+ remote: git://github.com/jnicklas/carrierwave.git
+ revision: 719a13ce976940fd793d4ed70db1c4fb1c705ff4
+ specs:
+ carrierwave (0.6.0.beta)
+ activemodel (>= 3.2.0)
+ activesupport (>= 3.2.0)
+
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.1.3)
- actionpack (= 3.1.3)
- mail (~> 2.3.0)
- actionpack (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
+ actionmailer (3.2.0)
+ actionpack (= 3.2.0)
+ mail (~> 2.4.0)
+ actionpack (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- i18n (~> 0.6)
- rack (~> 1.3.5)
+ journey (~> 1.0.0)
+ rack (~> 1.4.0)
rack-cache (~> 1.1)
- rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.0.3)
- activemodel (3.1.3)
- activesupport (= 3.1.3)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.0)
+ activesupport (= 3.2.0)
builder (~> 3.0.0)
- i18n (~> 0.6)
- activerecord (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
- arel (~> 2.2.1)
+ activerecord (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
+ arel (~> 3.0.0)
tzinfo (~> 0.3.29)
- activeresource (3.1.3)
- activemodel (= 3.1.3)
- activesupport (= 3.1.3)
- activesupport (3.1.3)
+ activeresource (3.2.0)
+ activemodel (= 3.2.0)
+ activesupport (= 3.2.0)
+ activesupport (3.2.0)
+ i18n (~> 0.6)
multi_json (~> 1.0)
ansi (1.4.1)
- arel (2.2.1)
+ arel (3.0.0)
builder (3.0.0)
capistrano (2.9.0)
highline
@@ -39,9 +46,9 @@ GEM
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
chunky_png (1.2.5)
- coffee-rails (3.1.1)
+ coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
- railties (~> 3.1.0)
+ railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
@@ -51,18 +58,19 @@ GEM
fssm (>= 0.2.7)
sass (~> 3.1)
erubis (2.7.0)
- execjs (1.2.13)
+ execjs (1.3.0)
multi_json (~> 1.0)
fssm (0.2.8.1)
haml (3.1.4)
- highline (1.6.9)
+ highline (1.6.11)
hike (1.2.1)
i18n (0.6.0)
- jquery-rails (1.0.19)
- railties (~> 3.0)
+ journey (1.0.1)
+ jquery-rails (2.0.0)
+ railties (>= 3.2.0.beta, < 5.0)
thor (~> 0.14)
json (1.6.5)
- mail (2.3.0)
+ mail (2.4.1)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
@@ -75,44 +83,44 @@ GEM
net-ssh (2.3.0)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
+ nofxx-georuby (1.9.2)
polyglot (0.3.3)
- rack (1.3.6)
+ rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
- rack-mount (0.8.3)
- rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.1.3)
- actionmailer (= 3.1.3)
- actionpack (= 3.1.3)
- activerecord (= 3.1.3)
- activeresource (= 3.1.3)
- activesupport (= 3.1.3)
+ rails (3.2.0)
+ actionmailer (= 3.2.0)
+ actionpack (= 3.2.0)
+ activerecord (= 3.2.0)
+ activeresource (= 3.2.0)
+ activesupport (= 3.2.0)
bundler (~> 1.0)
- railties (= 3.1.3)
- railties (3.1.3)
- actionpack (= 3.1.3)
- activesupport (= 3.1.3)
+ railties (= 3.2.0)
+ railties (3.2.0)
+ actionpack (= 3.2.0)
+ activesupport (= 3.2.0)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rmagick (2.13.1)
sass (3.1.12)
- sass-rails (3.1.5)
- actionpack (~> 3.1.0)
- railties (~> 3.1.0)
- sass (~> 3.1.10)
- tilt (~> 1.3.2)
- sprockets (2.0.3)
+ sass-rails (3.2.4)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
+ sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -130,11 +138,15 @@ PLATFORMS
DEPENDENCIES
capistrano
- coffee-rails (~> 3.1.1)
+ carrierwave!
+ coffee-rails (~> 3.2.1)
compass (~> 0.12.alpha.2)
haml
jquery-rails
- rails (= 3.1.3)
- sass-rails (~> 3.1.4)
+ nofxx-georuby
+ rails (= 3.2.0)
+ rmagick
+ sass-rails (~> 3.2.3)
+ sqlite3
turn
uglifier (>= 1.0.3)
View
29 app/assets/javascripts/application.js
@@ -14,8 +14,9 @@ Ext.application({
appFolder: 'makemap',
- views: ['map','controls'],
+ views: ['map','controls','savedlist'],
controllers: ['Map','Controls','Makemap'],
+ stores: ['SavedMaps'],
launch: function() {
Ext.create('Ext.container.Viewport', {
@@ -34,11 +35,29 @@ Ext.application({
itemId: 'content',
border: false
},{
- xtype: 'mapcontrols',
+ xtype: 'panel',
width: 300,
- split: true,
- region: "east",
- id: "sidebar"
+ layout: {
+ type: 'vbox',
+ align: 'stretch'
+ },
+ region: 'east',
+ items: [{
+ xtype: 'mapcontrols',
+ split: true,
+ id: "sidebar"
+ },{
+ xtype: 'panel',
+ id: 'savedlist',
+ layout: 'fit',
+ title: 'Saved Maps',
+ items: [{
+ xtype: 'savedlist',
+ store: this.getStore("SavedMaps")
+ }],
+
+ flex: 1
+ }]
},{
xtype: 'panel',
height: 20,
View
34 app/assets/javascripts/makemap/controller/Controls.js
@@ -16,14 +16,14 @@ Ext.define('MM.controller.Controls', {
"mapcontrols > form > field": {
blur: this.updateFields
},
- "mapcontrols > form > field[name='baselayer']": {
+ "mapcontrols field[inputId='baselayer']": {
change: {
fn: this.changeBaseLayer,
buffer: 500
}
},
"mapcontrols > form numberfield": {
- change: {
+ spin: {
fn: this.updateFields,
buffer: 500
}
@@ -32,6 +32,7 @@ Ext.define('MM.controller.Controls', {
},
updateFields: function( field, newValue, oldValue ) {
+ console.log("Update Fields", field);
var panel = Ext.ComponentQuery.query("mapcontrols form")[0];
var fields = panel.getForm().getFieldValues();
@@ -44,31 +45,32 @@ Ext.define('MM.controller.Controls', {
var values = {};
switch( field.name ) {
- case 'imagewidth':
+ case 'image[width]':
var imageheight = Math.round(field.value / fields.ratio);
Ext.apply( values, {
- imageheight: imageheight
+ 'image[height]': imageheight
});
break;
- case 'imageheight':
+ case 'image[height]':
var imagewidth = Math.round(field.value * fields.ratio);
Ext.apply( values, {
- imagewidth: imagewidth
+ 'image[width]': imagewidth
});
break;
}
-
+
panel.getForm().setValues( values );
//Make sure we're using the update form values
- var pixelsize = this.calcPixelSize(gWidth, panel.getForm().getValues().imagewidth);
-
+ var pixelsize = this.calcPixelSize(gWidth, panel.getForm().getValues()['image[width]']);
this.updateInfo( geom, pixelsize );
},
changeBaseLayer: function( field, newValue, oldValue) {
- var layer = field.getValue();
- if( this.getMap().getMap().getLayersByName( layer )) {
- this.getMap().getMap().setBaseLayer( layer );
+ var layer = field.rawValue;
+ var map = this.getMap().getMap();
+ console.log( field.rawValue );
+ if( map.getLayersByName( layer ) ) {
+ map.setBaseLayer( map.getLayersByName(layer)[0] );
}
},
@@ -100,10 +102,10 @@ Ext.define('MM.controller.Controls', {
pixelsize = this.calcPixelSize( gHeight, height);
width = this.calcImageLength( gWidth, pixelsize);
}
-
+
panel.getForm().setValues({
- imagewidth: Math.round( width ),
- imageheight: Math.round( height ),
+ 'image[width]': Math.round( width ),
+ 'image[height]': Math.round( height ),
ratio: ratio
});
this.updateInfo(geom, pixelsize);
@@ -118,15 +120,13 @@ Ext.define('MM.controller.Controls', {
}
geom.transform( this.getMap().getMap().getProjectionObject(), this.getMap().getMap().displayProjection);
-
var data = {
centerLat: geom.getCentroid().x,
centerLon: geom.getCentroid().y,
area: area,
pixelsize: pixelsize,
coords: geom.getVertices()
};
-
var panel = Ext.ComponentQuery.query("mapcontrols")[0];
panel.updateInfo(data);
}
View
24 app/assets/javascripts/makemap/controller/Makemap.js
@@ -11,7 +11,7 @@ Ext.define('MM.controller.Makemap', {
init: function() {
this.control( {
- "mapcontrols > form button[itemId='makemap']": {
+ "mapcontrols button[itemId='makemaps']": {
click: this.buildMapQuery
}
@@ -23,17 +23,28 @@ Ext.define('MM.controller.Makemap', {
var map = this.getMap().getMap();
var aoi = map.getLayersByName("aoi")[0].features[0];
var geom = aoi.geometry.clone();
- var bbox = geom.getVertices();
var layers = this.getActiveLayers(map);
var values = form.getValues();
+ var baselayer = this.getBaseLayer(map);
Ext.apply(values, {
- 'baseLayer[]': this.getBaseLayer(map),
- bbox: bbox[0].x+","+bbox[0].y+","+bbox[2].x+","+bbox[2].y
+ 'image[wms]': baselayer[0],
+ // 'image[baselayer]': baselayer[1],
+ 'image[bbox]': geom.toString()
+ });
+ console.log(form.getValues());
+
+ form.submit({
+ method: "POST",
+ url: "/makemaps",
+ params: values,
+ success: function() {
+ Ext.data.StoreMgr.lookup("SavedMaps").load();
+ }
});
- window.open("/makemap?"+Ext.Object.toQueryString(values));
+ return false;
},
getBaseLayer: function(map) {
@@ -44,7 +55,6 @@ Ext.define('MM.controller.Makemap', {
return false;
}
}, this);
- console.log(index, map.layers[index]);
wms = Gina.Layers.get( map.layers[index].options.wmsId, true);
return [wms.url, wms.wmsOptions.layers];
},
@@ -62,4 +72,4 @@ Ext.define('MM.controller.Makemap', {
return layers;
}
-});
+});
View
66 app/assets/javascripts/makemap/controller/Map.js
@@ -22,13 +22,17 @@ Ext.define('MM.controller.Map', {
toggle: this.aoiAdd
},
+ "savedlist": {
+ itemclick: this.changeAoi
+ },
"map": {
aoiadd: function( map, feature ) {
var geom = feature.geometry.clone();
Ext.ComponentQuery.query("map > toolbar > button[itemId='select']")[0].toggle(true);
geom.transform( map.getMap().getProjectionObject(), map.getMap().displayProjection);
+ this.zoomToAOI( feature );
},
buildLayerComboBox: this.buildLayerComboBox
}
@@ -58,30 +62,28 @@ Ext.define('MM.controller.Map', {
buildLayerComboBox: function() {
var data = { baseLayers: [], overlays: [] };
-
+ var map = this.getMap();
+
+ this.getControls().layersStore.removeAll();
+
Ext.each(this.getMap().getMap().layers, function(item) {
if(!item.displayInLayerSwitcher) { return; }
- if(item.isBaseLayer) {
- if(item.getVisibility()) { this.activeBaseLayer = item; }
+ wms = Gina.Layers.get( item.options.wmsId, true);
- data.baseLayers.push({
- text: item.name,
- layer: item
- });
- } else {
- data.overlays.push({
- text: item.name,
- layer: item
+ if(item.isBaseLayer) {
+ this.getControls().layersStore.add({
+ text: wms.name,
+ layer: wms.wmsOptions.layers
});
- }
+ if(item.getVisibility()) {
+ this.activeBaseLayer = wms.name;
+ this.getControls().down('form').getForm().setValues({
+ 'image[baselayer]': wms.wmsOptions.layers
+ });
+ }
+ }
}, this);
-
- this.getControls().layersStore.removeAll();
- this.getControls().layersStore.add(data.baseLayers);
- this.getControls().down('form').getForm().setValues({
- baselayer: this.activeBaseLayer
- });
},
baseMenuHandler: function( item ) {
@@ -90,6 +92,34 @@ Ext.define('MM.controller.Map', {
overlayMenuHandler: function( item ) {
item.layer.setVisibility( !item.layer.getVisibility() );
+ },
+
+ changeAoi: function( scope, record ) {
+ var form = Ext.ComponentQuery.query("mapcontrols form")[0];
+ values = {};
+ console.log(record);
+
+ //Set the values of the form
+ Ext.apply( values, {
+ 'image[width]': record.data.width,
+ 'image[height]': record.data.height,
+ 'image[baselayer]': record.data.baselayer,
+ 'image[format]': record.data.format,
+ 'ratio': record.data.width / record.data.height
+ });
+
+ //Create a new aoi and draw it on the map
+ var geom = new OpenLayers.Geometry.fromWKT( record.data.bbox );
+ var aoiFeature = new OpenLayers.Feature.Vector(geom);
+
+ this.getMap().aoiLayer.addFeatures( [aoiFeature] );
+ form.getForm().setValues(values);
+ form.enable();
+ this.zoomToAOI( aoiFeature );
+ },
+
+ zoomToAOI: function( feature ) {
+ this.getMap().getMap().zoomToExtent( feature.geometry.getBounds() )
}
});
View
5 app/assets/javascripts/makemap/model/SavedMap.js
@@ -0,0 +1,5 @@
+Ext.define('MM.model.SavedMap', {
+ extend: 'Ext.data.Model',
+ fields: [ 'id', 'name', 'format', 'zoomlevel', 'bbox','width','height',
+ 'wms', 'baselayer', 'overlays', 'url', 'imageUrl', 'thumbUrl' ]
+});
View
12 app/assets/javascripts/makemap/store/SavedMaps.js
@@ -0,0 +1,12 @@
+Ext.define('MM.store.SavedMaps', {
+ extend: 'Ext.data.Store',
+ model: 'MM.model.SavedMap',
+ storeId: "SavedMaps",
+ proxy: {
+ type: 'ajax',
+ url: '/makemaps.json',
+ timeout: 120000,
+ reader: { type: 'json', totalProperty: 'total', root: 'maps' }
+ },
+ autoLoad: true
+});
View
35 app/assets/javascripts/makemap/view/controls.js
@@ -1,35 +1,30 @@
Ext.define("MM.view.Controls",{
extend: "Ext.panel.Panel",
alias: "widget.mapcontrols",
- layout: {
- type: 'vbox',
- align: 'stretch'
- },
initComponent: function() {
var submitButton = {
xtype: "button",
- itemId: "makemap",
+ itemId: "makemaps",
scale: "large",
text: "Make Map!",
- layout: "hbox",
flex: 1,
- stretch: true,
- formBind: true
+ stretch: true
};
var imageFormats = Ext.create( 'Ext.data.Store', {
fields: ['imagetype','ext'],
data: [
{ 'imagetype':'JPEG', 'ext':'jpg' },
- { 'imagetype':'GeoTIFF', 'ext':'tiff' },
- { 'imagetype':'GeoTIFF w/ JPEG Compression', 'ext':'tiff_jpeg' }
+ { 'imagetype':'GeoTIFF', 'ext':'tiff' }
+ // { 'imagetype':'GeoTIFF w/ JPEG Compression', 'ext':'tiff_jpeg' }
]
});
var defaultFormat = imageFormats.first();
this.layersStore = Ext.create( 'Ext.data.Store', {
- fields: ['text', 'layer']
+ fields: ['text', 'layer'],
+ storeId: 'Layers'
});
var form = Ext.create( "Ext.form.Panel", {
fieldDefaults: {
@@ -38,11 +33,12 @@ Ext.define("MM.view.Controls",{
bodyStyle: 'padding: 3px;',
disabled: true,
border: false,
- standardSubmit: true,
+ standardSubmit: false,
items: [{
xtype: 'combobox',
fieldLabel: 'Layer',
- name: 'baselayer',
+ inputId: 'baselayer',
+ name: 'image[baselayer]',
store: this.layersStore,
queryMode: 'local',
displayField: 'text',
@@ -52,17 +48,17 @@ Ext.define("MM.view.Controls",{
minValue: 200,
maxValue: 10000,
fieldLabel: "Image Width",
- name: 'imagewidth'
+ name: 'image[width]'
},{
xtype: 'numberfield',
minValue: 200,
maxValue: 10000,
fieldLabel: "Image Height",
- name: 'imageheight'
+ name: 'image[height]'
},{
xtype: 'combobox',
fieldLabel: 'Image Format',
- name: 'imageformat',
+ name: 'image[format]',
store: imageFormats,
queryMode: 'local',
displayField: 'imagetype',
@@ -73,7 +69,7 @@ Ext.define("MM.view.Controls",{
},{
xtype: 'textfield',
fieldLabel: "Image Name",
- name: 'name',
+ name: 'image[name]',
value: this.default_filename(),
regex: /^\w+$/,
regexText: "Name must be one or more of a letter, number or _",
@@ -86,7 +82,8 @@ Ext.define("MM.view.Controls",{
xtype: "toolbar",
dock: "bottom",
ui: 'footer',
- formBind: true,
+ formBind: false,
+ height: 50,
items: [submitButton]
}]
});
@@ -127,4 +124,4 @@ Ext.define("MM.view.Controls",{
return "MM" + Today.getUTCFullYear() + this.pad(Today.getUTCMonth() + 1) + this.pad(Today.getUTCDay())
}
-});
+});
View
31 app/assets/javascripts/makemap/view/savedlist.js
@@ -0,0 +1,31 @@
+Ext.define("MM.view.savedlist",{
+ extend: "Ext.view.View",
+ alias: "widget.savedlist",
+ title: 'Your Saved Maps',
+ cls: "savedlist",
+
+ tpl: new Ext.XTemplate(
+ '<tpl for=".">',
+ '<div class="saved_wrap" id="savedMap_{id}">',
+ '<div class="map_image"><img src={thumbUrl} class="saved_thumb"></div>',
+ '<div class="name">{name}</div>',
+ '<div class="link"><a href="{imageUrl}">Full size</a></div>',
+ '</div>',
+ '</tpl>'
+ ),
+
+ autoScroll: true,
+ autoRender: true,
+ trackOver: true,
+ overItemCls: 'x-item-over',
+ itemSelector: 'div.saved_wrap',
+ loadingTest: 'Loading saved maps',
+ singleSelect: true,
+ allowDeselect: true,
+ emptyText: "No saved maps available",
+ layout: 'fit',
+
+ initComponent: function() {
+ this.callParent(arguments);
+ }
+});
View
9 app/assets/javascripts/makemap/view/savedmap.js
@@ -0,0 +1,9 @@
+Ext.define("MM.view.saved",{
+ extend: "Ext.window.Window",
+ alias: "widget.saved_map",
+
+ initComponent: function() {
+
+ this.callParent(arguments);
+ }
+});
View
26 app/assets/javascripts/makemap/view/wizard.js
@@ -0,0 +1,26 @@
+Ext.define('MM.view.Wizard',{
+ extend: 'Ext.panel.Panel',
+ alias: 'widget.wizard',
+
+ layout: 'card',
+
+ initComponent: function() {
+ this.items = [{
+ id: 'card-0',
+ html: 'Welcome to MakeMap'
+ },{
+ id: 'card-1',
+ html: 'Zoom to your region of interest'
+ }];
+
+ this.bbar = [ '->', {
+ id: 'card-prev',
+ text: 'Previous'
+ },{
+ id: 'card-next',
+ text: 'Next'
+ }];
+
+ this.callParent(arguments);
+ }
+});
View
33 app/assets/stylesheets/application.css.scss
@@ -88,3 +88,36 @@ $panel-body-background-color: $gina-dark;
color: $gina-highlight;
}
}
+
+.savedlist {
+ font-size: 14px;
+
+ .saved_wrap {
+ position: relative;
+ display:block;
+ min-height: 32px;
+ clear: both;
+
+ .map_image {
+ float: left;
+ }
+ .name {
+ padding: 5px;
+ margin-right: 16px;
+ font-weight: bold;
+ }
+
+ .saved_thumb {
+ width: 100px;
+ height: 100px;
+ }
+
+ &.x-item-over {
+ background-color: #BBDDFF;
+ }
+
+ &.x-item-selected {
+ background-color: #AABBFF;
+ }
+ }
+}
View
32 app/controllers/makemaps_controller.rb
@@ -1,8 +1,34 @@
class MakemapsController < ApplicationController
+
def show
- map = MakeMapWMS.new params
- redirect_to map.to_s, :status => 302
+ @map = MapSave.where( :id => params["id"] ).first
+ logger.info @map.inspect
+ respond_to do |format|
+ format.html
+ format.json { render :json => @map }
+ end
+ end
+
+ def create
+ mapsave = MapSave.new params["image"]
+ map = MakeMapWMS.new params["image"]
+ # Cache in carrierwave
+ mapsave.mapimage.download! map.to_s
+ #logger.info params.inspect
+ if mapsave.save!
+ respond_to do |format|
+ format.js {render :json => {"success" => true}}
+ end
+ end
end
+ def index
+ @maps = MapSave.all
+
+ respond_to do |format|
+ format.html
+ format.json { render :json => @maps }
+ end
+ end
-end
+end
View
28 app/models/map_save.rb
@@ -0,0 +1,28 @@
+class MapSave < ActiveRecord::Base
+ mount_uploader :mapimage, MapimageUploader
+
+ validates :width, :numericality => { :only_integer => true,
+ :greater_than => 0, :less_than_or_equal_to => 10000 }
+ validates :height, :numericality => { :only_integer => true,
+ :greater_than => 0, :less_than_or_equal_to => 10000 }
+ validates :name, :baselayer, :wms, :presence => true
+ validates :format, :inclusion => { :in => %w( jpg tiff tiff_jpeg ) }
+
+ def as_json(opts = {})
+ {
+ :id => id,
+ :name => name,
+ :format => format,
+ :bbox => bbox,
+ :wms => wms,
+ :baselayer => baselayer,
+ :overlays => overlays,
+ :url => self.to_s,
+ :width => width,
+ :height => height,
+ :imageUrl => self.mapimage.url,
+ :thumbUrl => self.mapimage.url(:thumb)
+ }
+ end
+
+end
View
56 app/uploaders/mapimage_uploader.rb
@@ -0,0 +1,56 @@
+# encoding: utf-8
+
+class MapimageUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ include CarrierWave::RMagick
+ # include CarrierWave::MiniMagick
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ # def default_url
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ # end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ #process :brandImage
+
+ # Create different versions of your uploaded files:
+ version :thumb do
+ process :resize_to_fill => [200, 200]
+ convert :jpg
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+ def brandImage
+
+
+ end
+
+end
View
6 app/views/layouts/makemaps.html.haml
@@ -0,0 +1,6 @@
+%html
+ %head
+ %title MakeMAP Show
+ = stylesheet_link_tag "application"
+ %body
+ =yield
View
18 app/views/makemaps/_image.html.erb
@@ -0,0 +1,18 @@
+<div style="height: 280px;">
+ <h2>Saved Map <%= image.name %></h2>
+ <div style="float: left; padding-right: 10px;">
+ <a href="<%= image.mapimage.url %>">
+ <%= image_tag( image.mapimage.thumb.url ) %>
+ </a><br>
+ Click on thumbnail to see full image.
+ </div>
+ <table>
+ <tr><td width="100">Width</td><td><%= image.width %></td></tr>
+ <tr><td>Height</td><td><%= image.height %></td></tr>
+ <tr><td>Bounding Box</td><td><%= image.bbox %></td></tr>
+ <tr><td>Zoom Level</td><td><%= image.name %></td></tr>
+ <tr><td>Base Layer</td><td><%= image.baselayer %></td></tr>
+ <tr><td>Save Date</td><td><%= image.created_at %></td></tr>
+ </table>
+</div>
+
View
5 app/views/makemaps/index.html.erb
@@ -0,0 +1,5 @@
+<% @maps.each do |item| %>
+ <hr>
+ <%= render :partial => "image", :locals => { :image => item } %>
+<% end %>
+<hr>
View
2 app/views/makemaps/show.html.erb
@@ -0,0 +1,2 @@
+<%= render :partial => "image", :locals => { :image => @map } %>
+
View
12 config/application.rb
@@ -1,11 +1,11 @@
require File.expand_path('../boot', __FILE__)
-#require 'rails/all'
-require 'action_controller/railtie'
-require 'action_mailer/railtie'
-require 'active_resource/railtie'
-require 'rails/test_unit/railtie'
-require 'sprockets/railtie'
+require 'rails/all'
+#require 'action_controller/railtie'
+#require 'action_mailer/railtie'
+#require 'active_resource/railtie'
+#require 'rails/test_unit/railtie'
+#require 'sprockets/railtie'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
View
2 config/environments/development.rb
@@ -22,7 +22,7 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
- config.serve_static_assets = false
+ config.serve_static_assets = true
# Do not compress assets
View
2 config/routes.rb
@@ -2,7 +2,7 @@
# The priority is based upon order of creation:
# first created -> highest priority.
- resource :makemap
+ resources :makemaps
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
View
14 db/migrate/20120125195009_create_map_saves.rb
@@ -0,0 +1,14 @@
+class CreateMapSaves < ActiveRecord::Migration
+ def change
+ create_table :map_saves do |t|
+ t.text :name
+ t.text :imageformat
+ t.integer :imagewidth
+ t.integer :imageheight
+ t.text :bounds
+ t.integer :zoomlevel
+
+ t.timestamps
+ end
+ end
+end
View
5 db/migrate/20120126022832_add_layers_to_map_save.rb
@@ -0,0 +1,5 @@
+class AddLayersToMapSave < ActiveRecord::Migration
+ def change
+ add_column :map_saves, :foo, :integer
+ end
+end
View
6 db/migrate/20120126023036_add_fields_to_map_save.rb
@@ -0,0 +1,6 @@
+class AddFieldsToMapSave < ActiveRecord::Migration
+ def change
+ add_column :map_saves, :baselayer, :text
+ add_column :map_saves, :overlays, :text
+ end
+end
View
8 db/migrate/20120126023702_change_field_names_in_map_save.rb
@@ -0,0 +1,8 @@
+class ChangeFieldNamesInMapSave < ActiveRecord::Migration
+ change_table :map_saves do |t|
+ t.rename :imageformat, :format
+ t.rename :imagewidth, :width
+ t.rename :imageheight, :height
+ t.rename :bounds, :bbox
+ end
+end
View
5 db/migrate/20120126204106_add_field_to_map_save.rb
@@ -0,0 +1,5 @@
+class AddFieldToMapSave < ActiveRecord::Migration
+ def change
+ add_column :map_saves, :wmsurl, :text
+ end
+end
View
6 db/migrate/20120126213330_rename_field_wmsurl_to_wms_in_map_save.rb
@@ -0,0 +1,6 @@
+class RenameFieldWmsurlToWmsInMapSave < ActiveRecord::Migration
+ def change
+ rename_column :map_saves, :wmsurl, :wms
+ end
+
+end
View
5 db/migrate/20120127180251_add_mapimage_to_map_save.rb
@@ -0,0 +1,5 @@
+class AddMapimageToMapSave < ActiveRecord::Migration
+ def change
+ add_column :map_saves, :mapimage, :string
+ end
+end
View
9 db/migrate/20120208182547_remove_zoom_level_from_map_save.rb
@@ -0,0 +1,9 @@
+class RemoveZoomLevelFromMapSave < ActiveRecord::Migration
+ def up
+ remove_column :map_saves, :zoomlevel
+ end
+
+ def down
+ add_column :map_saves, :zoomlevel, :integer
+ end
+end
View
30 db/schema.rb
@@ -0,0 +1,30 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120208182547) do
+
+ create_table "map_saves", :force => true do |t|
+ t.text "name"
+ t.text "format"
+ t.integer "width"
+ t.integer "height"
+ t.text "bbox"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.text "baselayer"
+ t.text "overlays"
+ t.text "wms"
+ t.string "mapimage"
+ end
+
+end
View
49 extras/make_map_wms.rb
@@ -1,3 +1,5 @@
+require 'geo_ruby'
+
class MakeMapWMS
FORMATS = {
:jpg => {
@@ -15,22 +17,26 @@ class MakeMapWMS
}
WMS_BASE = "REQUEST=GetMap&SERVICE=WMS&STYLES=&VERSION=1.1.1&BGCOLOR=0xFFFFFF&TRANSPARENT=TRUE"
def initialize *opts
- opts = opts.first
- @wms = opts[:baseLayer].first || "http://wms.alaskamapped.org/bdl"
- @layers = opts[:baseLayer].last || "BestDataAvailableLayer"
- #@layers = [opts[:baseLayer][:wmsName], opts[:layers]].flatten.compact.join(',')
- @width = opts[:imagewidth] || 1024
- @height = opts[:imageheight] || 1024
- @bbox = opts[:bbox]
- @format = opts[:imageformat]
- @name = opts[:name]
+ if opts.first.is_a? MapSave
+ mapsaveconv( opts.first )
+ else
+ opts = opts.first
+ @wms = opts[:wms] || "http://wms.alaskamapped.org/bdl"
+ @layers = opts[:baselayer] || "BestDataAvailableLayer"
+ #@layers = [opts[:baseLayer][:wmsName], opts[:layers]].flatten.compact.join(',')
+ @width = opts[:width] || 1024
+ @height = opts[:height] || 1024
+ @bbox = opts[:bbox]
+ @format = opts[:format]
+ @name = opts[:name]
+ end
end
def to_s
query = [WMS_BASE,
"LAYERS=#{@layers}",
"FORMAT=#{type}",
- "BBOX=#{@bbox}",
+ "BBOX=#{bbox}",
"SRS=EPSG:3338",
"WIDTH=#{@width}",
"HEIGHT=#{@height}",
@@ -50,4 +56,25 @@ def type
def ext
FORMATS[@format.to_sym][:ext]
end
-end
+
+ def bbox
+ bounds = GeoRuby::SimpleFeatures::Geometry.from_ewkt(@bbox).envelope
+ [ bounds.lower_corner.x,
+ bounds.lower_corner.y,
+ bounds.upper_corner.x,
+ bounds.upper_corner.y ].join ","
+ end
+
+ #Convert MapSave object to variables
+ def mapsaveconv( map )
+ @wms = map.wms || "http://wms.alaskamapped.org/bdl"
+ @layers = map.baselayer || "BestDataAvailableLayer"
+ #@layers = [opts[:baseLayer][:wmsName], opts[:layers]].flatten.compact.join(',')
+ @width = map.width || 1024
+ @height = map.height || 1024
+ @bbox = map.bbox
+ @format = map.format
+ @name = map.name
+ end
+
+end
View
17 test/fixtures/map_saves.yml
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyText
+ imageformat: MyText
+ imagewidth: 1
+ imageheight: 1
+ bounds: MyText
+ zoomlevel: 1
+
+two:
+ name: MyText
+ imageformat: MyText
+ imagewidth: 1
+ imageheight: 1
+ bounds: MyText
+ zoomlevel: 1
View
7 test/unit/map_save_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class MapSaveTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 0cd9ed8

Please sign in to comment.
Something went wrong with that request. Please try again.