Created
February 2, 2015 19:21
-
-
Save workmaster2n/9eda8d0bd20c29eb5a88 to your computer and use it in GitHub Desktop.
collection not updating on fetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@App.module "Entities", (Entities, App, Backbone, Marionette, $, _) -> | |
class Entities.Map extends Backbone.Model | |
initialize: (id) -> | |
window.SweetMap = @ | |
@openLayersMap = new OpenLayers.Map(null) | |
@openLayersMap.units = "dd" | |
@openLayersMap.numZoomLevels = 25 | |
@openLayersMap.fractionalZoom = true | |
@openLayersMap.allOverlays = true | |
this.location = new Entities.Location({id: id}) | |
this.location.fetch | |
async: false | |
success: => | |
rotation = this.location.get("open_layers_rotation") || 0 | |
rotation = rotation * Math.PI/180 * -1 | |
this.setupMap() | |
setupMap: -> | |
location_id = this.location.get("id") | |
@zoneCollection = new Entities.ZoneCollection(location_id) | |
@zoneLayerView = new App.ZoneApp.Show.ZoneCollectionView | |
collection: @zoneCollection | |
openLayersMap: @openLayersMap | |
rotation: @location.get("open_layers_rotation") || 0 | |
@zoneCollection.fetch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@App.module "ZoneApp.Show", (Show, App, Backbone, Marionette, $, _) -> | |
class Show.ZoneView extends Marionette.ItemView | |
template: "zone/templates/zone" | |
initialize: (options)-> | |
debugger | |
options = options || {} | |
this.layer = options.layer | |
this.rotation = options.rotation | |
closeZonePopup: () -> | |
this.layer.map.removePopup(this.feature.popup) | |
this.feature.popup.destroy() | |
this.feature.popup = null | |
zonePopup: () -> | |
feature = this.feature | |
content = "<div><strong>Rules: </strong><a href = '" + this.model.get("rules_url") + "'>Rules</a><br /></strong><strong>Feature:</strong> "+ this.model.get("id") + "<br/><strong>Name: </strong>" + this.model.get("name") + "<br></div>" | |
popup = new OpenLayers.Popup.FramedCloud( | |
feature.id + "_popup", | |
feature.geometry.getBounds().getCenterLonLat(), | |
new OpenLayers.Size(100, 100), | |
content, | |
null, | |
false, | |
null) | |
feature.popup = popup | |
this.layer.map.addPopup(popup) | |
render: () -> | |
debugger | |
zone = this.model | |
geometries = zone.get("geometries") | |
if geometries.length > 0 | |
for geometry in geometries | |
this.feature = new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT(geometry.geom)) | |
origin = new OpenLayers.Geometry.Point(0,0) | |
this.feature.geometry.rotate(this.rotation, origin) | |
this.layer.addFeatures(this.feature) | |
_(this.feature).extend(Backbone.Events) | |
this.feature.on('featureselected', this.zonePopup, this) | |
this.feature.on('featureunselected', this.closeZonePopup, this) | |
class Show.ZoneCollectionView extends Marionette.CollectionView | |
childView: Show.ZoneView | |
initialize: (options) -> | |
options = options || {} | |
@openLayersMap = options.openLayersMap | |
@rotation = options.rotation | |
@initLayer() | |
initLayer: -> | |
zoneDefaultStyle: | |
new OpenLayers.Style | |
'fillColor': '#EAEDC2' | |
'strokeColor': '#8A9676' | |
'fillOpacity': .9 | |
zoneSelectStyle: | |
new OpenLayers.Style | |
'fillColor': '#37FDFC' | |
'strokeColor': '#00CDCD' | |
'fillOpacity': .5 | |
zoneStyleMap: | |
new OpenLayers.StyleMap | |
'default': @zoneDefaultStyle | |
'select': @zoneSelectStyle | |
@layer = new OpenLayers.Layer.Vector("zones", styleMap: @zoneStyleMap) | |
@openLayersMap.addLayer(@layer) | |
zoom_to_original_extent: -> | |
b = @layer.getDataExtent() | |
b.top = b.top + 2 | |
b.bottom = b.bottom - 2 | |
b.right = b.right + 2 | |
b.left = b.left - 2 | |
debugger | |
@openLayersMap.zoomToExtent(b) | |
itemViewOptions: ()-> | |
{ | |
layer: @layer | |
rotation: @rotation | |
} | |
onAfterItemAdded: ()-> | |
@zoom_to_original_extent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@App.module "Entities", (Entities, App, Backbone, Marionette, $, _) -> | |
class Entities.Zone extends Backbone.Model | |
class Entities.ZoneCollection extends Backbone.Collection | |
model: Entities.Zone | |
url: -> | |
"/locations/#{this.id}/geometries" | |
initialize: (id)-> | |
@id = id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment