1 | %
|
---|
2 | % definition for the kml_feature super (base) and sub (derived) class.
|
---|
3 | %
|
---|
4 | % [kml]=kml_feature(varargin)
|
---|
5 | %
|
---|
6 | % where the optional varargin and defaults are:
|
---|
7 | % id (char, feature id, '')
|
---|
8 | % name (char, name, '')
|
---|
9 | % visibility (logical, visibility, true)
|
---|
10 | % open (logical, open, false)
|
---|
11 | % snippet (char, snippet, '')
|
---|
12 | % descript (char, description, '')
|
---|
13 | % styleurl (char, style url, '')
|
---|
14 | % style (cell array, styles)
|
---|
15 | %
|
---|
16 | % note that zero arguments constructs a default instance; one
|
---|
17 | % argument of the class copies the instance; and two or more
|
---|
18 | % arguments constructs a new instance from the arguments.
|
---|
19 | %
|
---|
20 | classdef kml_feature < kml_object
|
---|
21 | properties
|
---|
22 | name ='';
|
---|
23 | visibility=true;
|
---|
24 | open =false;
|
---|
25 | snippet ='';
|
---|
26 | descript ='';
|
---|
27 | styleurl ='';
|
---|
28 | style ={};
|
---|
29 | end
|
---|
30 |
|
---|
31 | methods
|
---|
32 | function [kml]=kml_feature(varargin)
|
---|
33 |
|
---|
34 | kml=kml@kml_object(varargin{:});
|
---|
35 |
|
---|
36 | switch nargin
|
---|
37 |
|
---|
38 | % create a default object
|
---|
39 |
|
---|
40 | case 0
|
---|
41 |
|
---|
42 | % copy the object or create the object from the input
|
---|
43 |
|
---|
44 | otherwise
|
---|
45 | if (nargin == 1) && isa(varargin{1},class(kml))
|
---|
46 | kml=varargin{1};
|
---|
47 |
|
---|
48 | else
|
---|
49 | fnames=fieldnames(kml);
|
---|
50 |
|
---|
51 | for i=length(fieldnames(kml_object()))+1:min(nargin,length(fnames))
|
---|
52 | if isa(varargin{i},class(kml.(fnames{i})))
|
---|
53 | if ~isempty(varargin{i})
|
---|
54 | kml.(fnames{i})=varargin{i};
|
---|
55 | end
|
---|
56 | else
|
---|
57 | if ~isempty(inputname(i))
|
---|
58 | warning('Argument ''%s'' for field ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
59 | inputname(i),fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
60 | else
|
---|
61 | warning('Argument %d for field ''%s'' is a ''%s'' class object, not ''%s''.',...
|
---|
62 | i ,fnames{i},class(varargin{i}),class(kml.(fnames{i})));
|
---|
63 | end
|
---|
64 | end
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | end
|
---|
69 |
|
---|
70 | end
|
---|
71 |
|
---|
72 | % display the object
|
---|
73 |
|
---|
74 | function []=disp(kml)
|
---|
75 |
|
---|
76 | for i=1:numel(kml)
|
---|
77 | if strcmp(class(kml),'kml_feature')
|
---|
78 | disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
|
---|
79 | class(kml),inputname(1),string_dim(kml,i)));
|
---|
80 | end
|
---|
81 | disp@kml_object(kml(i));
|
---|
82 | disp(sprintf(' name: ''%s''' ,kml(i).name));
|
---|
83 | disp(sprintf(' visibility: %g' ,kml(i).visibility));
|
---|
84 | disp(sprintf(' open: %g' ,kml(i).open));
|
---|
85 | disp(sprintf(' snippet: ''%s''' ,kml(i).snippet));
|
---|
86 | disp(sprintf(' descript: ''%s''' ,kml(i).descript));
|
---|
87 | disp(sprintf(' styleurl: ''%s''' ,kml(i).styleurl));
|
---|
88 | if strcmp(class(kml),'kml_feature')
|
---|
89 | disp(sprintf(' style: %s %s\n' ,string_size(kml(i).style),...
|
---|
90 | class(kml(i).style)));
|
---|
91 | else
|
---|
92 | disp(sprintf(' style: %s %s' ,string_size(kml(i).style),...
|
---|
93 | class(kml(i).style)));
|
---|
94 | end
|
---|
95 | end
|
---|
96 |
|
---|
97 | end
|
---|
98 |
|
---|
99 | % write the object
|
---|
100 |
|
---|
101 | function []=kml_write(kml,fid,indent)
|
---|
102 |
|
---|
103 | if ~exist('fid','var') || isempty(fid)
|
---|
104 | fid=1;
|
---|
105 | end
|
---|
106 | if ~exist('indent','var') || isempty(indent)
|
---|
107 | indent='';
|
---|
108 | end
|
---|
109 |
|
---|
110 | % loop over the features
|
---|
111 |
|
---|
112 | for i=1:numel(kml)
|
---|
113 | if strcmp(class(kml),'kml_feature')
|
---|
114 | if ~isempty(kml(i).id)
|
---|
115 | fprintf(fid,'%s<!Feature id="%s">\n',indent,kml(i).id);
|
---|
116 | else
|
---|
117 | fprintf(fid,'%s<!Feature>\n',indent);
|
---|
118 | end
|
---|
119 | end
|
---|
120 | kml_write@kml_object(kml(i),fid,indent);
|
---|
121 | if ~isempty(kml(i).name)
|
---|
122 | fprintf(fid,'%s <name>%s</name>\n',indent,kml(i).name);
|
---|
123 | end
|
---|
124 | fprintf(fid,'%s <visibility>%d</visibility>\n',indent,kml(i).visibility);
|
---|
125 | fprintf(fid,'%s <open>%d</open>\n',indent,kml(i).open);
|
---|
126 | if ~isempty(kml(i).snippet)
|
---|
127 | fprintf(fid,'%s <Snippet maxLines="2">%s</Snippet>\n',indent,kml(i).snippet);
|
---|
128 | end
|
---|
129 | if ~isempty(kml(i).descript)
|
---|
130 | fprintf(fid,'%s <description>%s</description>\n',indent,kml(i).descript);
|
---|
131 | end
|
---|
132 | if ~isempty(kml(i).styleurl)
|
---|
133 | fprintf(fid,'%s <styleUrl>%s</styleUrl>\n',indent,kml(i).styleurl);
|
---|
134 | end
|
---|
135 |
|
---|
136 | % loop over the styles for each feature
|
---|
137 |
|
---|
138 | for j=1:numel(kml(i).style)
|
---|
139 | if ~isempty(kml(i).style{j})
|
---|
140 | if isa(kml(i).style{j},'kml_styleselector')
|
---|
141 | kml_write(kml(i).style{j},fid,[indent ' ']);
|
---|
142 | else
|
---|
143 | warning('kml(%d).style{%d} is a ''%s'' class object, not ''%s''.',...
|
---|
144 | i,j,class(kml(i).style{j}),'kml_styleselector');
|
---|
145 | end
|
---|
146 | end
|
---|
147 | end
|
---|
148 |
|
---|
149 | if strcmp(class(kml),'kml_feature')
|
---|
150 | fprintf(fid,'%s<!/Feature>\n',indent);
|
---|
151 | end
|
---|
152 | end
|
---|
153 |
|
---|
154 | end
|
---|
155 |
|
---|
156 | end
|
---|
157 |
|
---|
158 | end
|
---|
159 |
|
---|