Package org.geoserver.kml.KMZMapResponse

Examples of org.geoserver.kml.KMZMapResponse.KMZMap


        Charset encoding = wms.getCharSet();
        transformer.setEncoding(encoding);
        // TODO: use GeoServer.isVerbose() to determine if we should indent?
        transformer.setIndentation(3);

        KMZMap map = new KMZMap(mapContext, transformer, MIME_TYPE);
        map.setContentDispositionHeader(mapContext, ".kmz");

        return map;
    }
View Full Code Here


        mapContext.setMapWidth(1024);

        // create the map producer
        KMZMapOutputFormat mapProducer = new KMZMapOutputFormat(getWMS());
        KMZMapResponse mapEncoder = new KMZMapResponse(getWMS());
        KMZMap kmzMap = mapProducer.produceMap(mapContext);
        try {
            // create the kmz
            File tempDir = IOUtils.createRandomDirectory("./target", "kmplacemark", "test");
            tempDir.deleteOnExit();

            File zip = new File(tempDir, "kmz.zip");
            zip.deleteOnExit();

            FileOutputStream output = new FileOutputStream(zip);
            mapEncoder.write(kmzMap, output, null);

            output.flush();
            output.close();

            assertTrue(zip.exists());

            // unzip and test it
            ZipFile zipFile = new ZipFile(zip);

            ZipEntry entry = zipFile.getEntry("wms.kml");
            assertNotNull(entry);
            assertNotNull(zipFile.getEntry("images/layer_0.png"));

            // unzip the wms.kml to file
            byte[] buffer = new byte[1024];
            int len;

            InputStream inStream = zipFile.getInputStream(entry);
            File temp = File.createTempFile("test_out", "kmz", tempDir);
            temp.deleteOnExit();
            BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(temp));

            while ((len = inStream.read(buffer)) >= 0)
                outStream.write(buffer, 0, len);
            inStream.close();
            outStream.close();

            // read in the wms.kml and check its contents
            Document document = dom(new BufferedInputStream(new FileInputStream(temp)));

            assertEquals("kml", document.getDocumentElement().getNodeName());
            if (doPlacemarks) {
                assertEquals(getFeatureSource(MockData.BASIC_POLYGONS).getFeatures().size(),
                        document.getElementsByTagName("Placemark").getLength());
            } else {
                assertEquals(0, document.getElementsByTagName("Placemark").getLength());
            }

            zipFile.close();
        } finally {
            kmzMap.dispose();
        }
    }
View Full Code Here

        Charset encoding = wms.getCharSet();
        transformer.setEncoding(encoding);
        // TODO: use GeoServer.isVerbose() to determine if we should indent?
        transformer.setIndentation(3);

        KMZMap map = new KMZMap(mapContent, transformer, MIME_TYPE);
        map.setContentDispositionHeader(mapContent, ".kmz");

        return map;
    }
View Full Code Here

        mapContent.setMapWidth(1024);

        // create the map producer
        KMZMapOutputFormat mapProducer = new KMZMapOutputFormat(getWMS());
        KMZMapResponse mapEncoder = new KMZMapResponse(getWMS());
        KMZMap kmzMap = mapProducer.produceMap(mapContent);
        try {
            // create the kmz
            File tempDir = IOUtils.createRandomDirectory("./target", "kmplacemark", "test");
            tempDir.deleteOnExit();

            File zip = new File(tempDir, "kmz.zip");
            zip.deleteOnExit();

            FileOutputStream output = new FileOutputStream(zip);
            mapEncoder.write(kmzMap, output, null);

            output.flush();
            output.close();

            assertTrue(zip.exists());

            // unzip and test it
            ZipFile zipFile = new ZipFile(zip);

            ZipEntry entry = zipFile.getEntry("wms.kml");
            assertNotNull(entry);
            assertNotNull(zipFile.getEntry("images/layer_0.png"));

            // unzip the wms.kml to file
            byte[] buffer = new byte[1024];
            int len;

            InputStream inStream = zipFile.getInputStream(entry);
            File temp = File.createTempFile("test_out", "kmz", tempDir);
            temp.deleteOnExit();
            BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(temp));

            while ((len = inStream.read(buffer)) >= 0)
                outStream.write(buffer, 0, len);
            inStream.close();
            outStream.close();

            // read in the wms.kml and check its contents
            Document document = dom(new BufferedInputStream(new FileInputStream(temp)));

            assertEquals("kml", document.getDocumentElement().getNodeName());
            if (doPlacemarks) {
                assertEquals(getFeatureSource(MockData.BASIC_POLYGONS).getFeatures().size(),
                        document.getElementsByTagName("Placemark").getLength());
            } else {
                assertEquals(0, document.getElementsByTagName("Placemark").getLength());
            }

            zipFile.close();
        } finally {
            kmzMap.dispose();
        }
    }
View Full Code Here

TOP

Related Classes of org.geoserver.kml.KMZMapResponse.KMZMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.