1 // Copyright 2008, Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without
13 // specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26 // This sample program creates shared style selectors.
27
28 #include <iostream>
29 #include "kml/dom.h"
30 #include "kml/convenience/convenience.h"
31
32 using kmldom::DocumentPtr;
33 using kmldom::IconStylePtr;
34 using kmldom::KmlFactory;
35 using kmldom::KmlPtr;
36 using kmldom::PairPtr;
37 using kmldom::PlacemarkPtr;
38 using kmldom::StylePtr;
39 using kmldom::StyleMapPtr;
40
main(int argc,char ** argv)41 int main(int argc, char** argv) {
42 KmlFactory* kml_factory = KmlFactory::GetFactory();
43
44 DocumentPtr document = kml_factory->CreateDocument();
45
46 StylePtr normal = kml_factory->CreateStyle();
47 normal->set_id("normal");
48 IconStylePtr iconstyle = kml_factory->CreateIconStyle();
49 iconstyle->set_scale(1.1);
50 normal->set_iconstyle(iconstyle);
51 document->add_styleselector(normal);
52
53 StylePtr highlight = kml_factory->CreateStyle();
54 highlight->set_id("highlight");
55 iconstyle = kml_factory->CreateIconStyle();
56 iconstyle->set_scale(2.3);
57 highlight->set_iconstyle(iconstyle);
58 document->add_styleselector(highlight);
59
60 StyleMapPtr stylemap = kml_factory->CreateStyleMap();
61 stylemap->set_id("stylemap");
62 PairPtr pair = kml_factory->CreatePair();
63 pair->set_key(kmldom::STYLESTATE_NORMAL);
64 pair->set_styleurl("#normal");
65 stylemap->add_pair(pair);
66
67 pair = kml_factory->CreatePair();
68 pair->set_key(kmldom::STYLESTATE_HIGHLIGHT);
69 pair->set_styleurl("#highlight");
70 stylemap->add_pair(pair);
71
72 document->add_styleselector(stylemap);
73
74 PlacemarkPtr placemark =
75 kmlconvenience::CreatePointPlacemark("Roll", 32.751645, -113.987817);
76 placemark->set_styleurl("#stylemap");
77
78 document->add_feature(placemark);
79
80 KmlPtr kml = kml_factory->CreateKml();
81 kml->set_feature(document);
82
83 std::cout << kmldom::SerializePretty(kml);
84
85 return 0;
86 }
87