1- L . ObjectsLayer = L . GeoJSON . extend ( {
1+ L . ObjectsLayer = L . GeoJSONTileLayer . extend ( {
22 options : {
33 indexing : true ,
44 highlight : true ,
@@ -12,7 +12,7 @@ L.ObjectsLayer = L.GeoJSON.extend({
1212
1313 includes : L . Mixin . Events ,
1414
15- initialize : function ( geojson , options ) {
15+ initialize : function ( url , options ) {
1616 // Pointers to all layers by pk - immutable
1717 this . _objects = { } ;
1818 // Hold the currently visible layers (subset of _objects)
@@ -44,14 +44,15 @@ L.ObjectsLayer = L.GeoJSON.extend({
4444 this . options . styles = L . Util . extend ( { } , this . options . styles ) ;
4545 this . options . styles [ 'default' ] = L . Util . extend ( { } , this . options . style ) ;
4646
47+ L . GeoJSONTileLayer . prototype . initialize . call ( this , url , this . options ) ;
4748
4849 // Highlight on mouse over, using global events
4950 if ( this . options . highlight ) {
50- this . on ( 'mouseover' , function ( e ) {
51+ this . layer . on ( 'mouseover' , function ( e ) {
5152 var pk = this . getPk ( e . layer ) ;
5253 $ ( window ) . trigger ( 'entity:mouseover' , { pk : pk , modelname : options . modelname } ) ;
5354 } , this ) ;
54- this . on ( 'mouseout' , function ( e ) {
55+ this . layer . on ( 'mouseout' , function ( e ) {
5556 var pk = this . getPk ( e . layer ) ;
5657 $ ( window ) . trigger ( 'entity:mouseout' , { pk : pk , modelname : options . modelname } ) ;
5758 } , this ) ;
@@ -69,29 +70,12 @@ L.ObjectsLayer = L.GeoJSON.extend({
6970 }
7071 } , this ) ) ;
7172
72-
7373 // Optionnaly make them clickable
7474 if ( this . options . objectUrl ) {
75- this . on ( 'click' , function ( e ) {
76- window . location = this . options . objectUrl ( e . layer . properties , e . layer ) ;
75+ this . layer . on ( 'click' , function ( e ) {
76+ window . location = this . options . objectUrl ( e . layer . feature . id ) ;
7777 } , this ) ;
7878 }
79-
80- var dataurl = null ;
81- if ( typeof ( geojson ) == 'string' ) {
82- dataurl = geojson ;
83- geojson = null ;
84- }
85- L . GeoJSON . prototype . initialize . call ( this , geojson , this . options ) ;
86-
87- // Fire Leaflet.Spin events
88- this . on ( 'loaded loading' , function ( e ) {
89- this . fire ( 'data:' + e . type ) ;
90- } , this ) ;
91-
92- if ( dataurl ) {
93- this . load ( dataurl ) ;
94- }
9579 } ,
9680
9781 _mapObjects : function ( geojson , layer ) {
@@ -109,29 +93,6 @@ L.ObjectsLayer = L.GeoJSON.extend({
10993 }
11094 } ,
11195
112- load : function ( url ) {
113- console . log ( "load" , url )
114- var jsonLoad = function ( data ) {
115- var features = jQuery . grep ( data . features , function ( obj , i ) {
116- return obj . geometry !== null ;
117- } ) ;
118- data . features = features ;
119- this . addData ( data ) ;
120- this . loading = false ;
121- this . fire ( 'loaded' ) ;
122- } ;
123- var jsonError = function ( ) {
124- this . loading = false ;
125- this . fire ( 'loaded' ) ;
126- console . error ( "Could not load url '" + url + "'" ) ;
127- if ( this . _map ) $ ( this . _map . _container ) . addClass ( 'map-error' ) ;
128- } ;
129- this . loading = true ;
130- this . fire ( 'loading' ) ;
131- $ . getJSON ( url , L . Util . bind ( jsonLoad , this ) )
132- . error ( L . Util . bind ( jsonError , this ) ) ;
133- } ,
134-
13596 getLayer : function ( pk ) {
13697 return this . _objects [ pk ] ;
13798 } ,
@@ -149,32 +110,7 @@ L.ObjectsLayer = L.GeoJSON.extend({
149110
150111 // Show all layers matching the pks
151112 updateFromPks : function ( pks ) {
152- var self = this ,
153- new_objects = { } ,
154- already_added_layer ,
155- to_add_layer ;
156-
157- // Gather all layer to see in new objects
158- // Remove them from _current_objects if they are already shown
159- // This way _current_objects will only contain layer to be removed
160- $ . each ( pks , function ( idx , to_add_pk ) {
161- already_added_layer = self . _current_objects [ to_add_pk ] ;
162- if ( already_added_layer ) {
163- new_objects [ to_add_pk ] = already_added_layer ;
164- delete self . _current_objects [ to_add_pk ] ;
165- } else {
166- to_add_layer = new_objects [ to_add_pk ] = self . _objects [ to_add_pk ] ;
167- // list can be ready before map, on first load
168- if ( to_add_layer ) self . addLayer ( to_add_layer ) ;
169- }
170- } ) ;
171-
172- // Remove all remaining layers
173- $ . each ( self . _current_objects , function ( pk , layer ) {
174- self . removeLayer ( layer ) ;
175- } ) ;
176-
177- self . _current_objects = new_objects ;
113+ console . log ( "Should filter map features again" ) ;
178114 } ,
179115
180116 getCurrentLayers : function ( ) {
@@ -202,7 +138,7 @@ L.ObjectsLayer = L.GeoJSON.extend({
202138 this . fire ( 'highlight' , { layer : layer } ) ;
203139 }
204140 else {
205- this . resetStyle ( layer ) ;
141+ this . layer . resetStyle ( layer ) ;
206142 }
207143 } ,
208144
0 commit comments