1- import L from " leaflet" ;
2- import { MapvLayer } from " ../MapvLayer" ;
1+ import L from ' leaflet' ;
2+ import { MapvLayer } from ' ../MapvLayer' ;
33
44/**
55 * @class MapvStreamLayer
@@ -12,70 +12,69 @@ import { MapvLayer } from "../MapvLayer";
1212 * @param {Object } options.field - geojson的唯一标识字段,请确保该字段的唯一性。
1313 */
1414export var MapvStreamLayer = MapvLayer . extend ( {
15- initialize : function ( map , url , options ) {
16- options = options || { } ;
15+ initialize : function ( map , url , options ) {
16+ options = options || { } ;
1717
18- L . Util . setOptions ( this , options ) ;
19-
20- this . mapvOption = options . mapvOption || { } ;
21- this . data = [ ] ;
22- this . lastDate = new Date ( ) ;
23- this . url = url ;
24- this . fieldHash = { } ;
18+ L . Util . setOptions ( this , options ) ;
2519
26- this . fieldDeg = options . fieldDeg ;
27- this . iconUrl = options . iconUrl ;
28- this . timeSpeed = options . timeSpeed || 100 ;
29- this . createIcon ( ) ;
30-
31- MapvLayer . prototype . initialize . call ( this , map , new window . mapv . DataSet ( [ ] ) , this . mapvOption , options )
32- } ,
20+ this . mapvOption = options . mapvOption || { } ;
21+ this . data = [ ] ;
22+ this . lastDate = new Date ( ) ;
23+ this . url = url ;
24+ this . fieldHash = { } ;
3325
34- onMessage : function ( msg ) {
35- const feature = msg . feature ;
36- const field = msg . feature . properties [ this . options . field ] ;
26+ this . fieldDeg = options . fieldDeg ;
27+ this . iconUrl = options . iconUrl ;
28+ this . timeSpeed = options . timeSpeed || 100 ;
29+ this . createIcon ( ) ;
3730
38- let layer = this . parasIcon ( feature ) ;
31+ MapvLayer . prototype . initialize . call ( this , map , new window . mapv . DataSet ( [ ] ) , this . mapvOption , options ) ;
32+ } ,
3933
40- if ( field !== undefined && this . fieldHash [ field ] ) {
41- this . data [ this . fieldHash [ field ] ] = layer ;
42- } else {
43- if ( field !== undefined ) {
44- this . data . push ( layer ) ;
45- this . fieldHash [ field ] = this . data . length - 1 ;
46- }
47- }
34+ onMessage : function ( msg ) {
35+ const feature = msg . feature ;
36+ const field = msg . feature . properties [ this . options . field ] ;
37+
38+ let layer = this . parasIcon ( feature ) ;
4839
49- this . updateLayer ( ) ;
50- } ,
40+ if ( field !== undefined && this . fieldHash [ field ] ) {
41+ this . data [ this . fieldHash [ field ] ] = layer ;
42+ } else {
43+ if ( field !== undefined ) {
44+ this . data . push ( layer ) ;
45+ this . fieldHash [ field ] = this . data . length - 1 ;
46+ }
47+ }
5148
52- createIcon : function ( ) {
53- var iconUrl =
54- this . iconUrl || "http://client.snanyun.com:8899/img/leaflet/marker/bike.png" ;
55- this . icon = new Image ( ) ;
56- this . icon . src = iconUrl ;
57- } ,
49+ this . updateLayer ( ) ;
50+ } ,
5851
59- parasIcon : function ( feature ) {
60- this . mapvOption = {
61- draw : "icon"
62- } ;
63- var deg = feature . properties [ this . fieldDeg ] || 0 ;
64- var icon = {
65- geometry : {
66- type : "Point" ,
67- coordinates : feature . geometry . coordinates
68- } ,
69- deg : deg ,
70- icon : this . icon
71- } ;
72- return icon ;
73- } ,
52+ createIcon : function ( ) {
53+ var iconUrl = this . iconUrl || 'http://client.snanyun.com:8899/img/leaflet/marker/bike.png' ;
54+ this . icon = new Image ( ) ;
55+ this . icon . src = iconUrl ;
56+ } ,
7457
75- updateLayer : function ( ) {
76- var currentDate = new Date ( ) ;
77- if ( currentDate - this . lastDate < this . timeSpeed ) return ;
78- this . updateData ( this . data , this . mapvOption ) ;
79- this . lastDate = currentDate ;
80- }
58+ parasIcon : function ( feature ) {
59+ this . mapvOption = {
60+ draw : 'icon'
61+ } ;
62+ var deg = feature . properties [ this . fieldDeg ] || 0 ;
63+ var icon = {
64+ geometry : {
65+ type : 'Point' ,
66+ coordinates : feature . geometry . coordinates
67+ } ,
68+ deg : deg ,
69+ icon : this . icon
70+ } ;
71+ return icon ;
72+ } ,
73+
74+ updateLayer : function ( ) {
75+ var currentDate = new Date ( ) ;
76+ if ( currentDate - this . lastDate < this . timeSpeed ) return ;
77+ this . updateData ( this . data , this . mapvOption ) ;
78+ this . lastDate = currentDate ;
79+ }
8180} ) ;
0 commit comments