Skip to content

Commit

Permalink
add implementation of WellKnownName type svgpath:// reusing existin…
Browse files Browse the repository at this point in the history
…g batik dependency

includes documentation and unit test
  • Loading branch information
stephanr committed Oct 10, 2022
1 parent 7191348 commit d98e284
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<gml:FeatureCollection id="FC_1"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns="http://deegree.org/app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/gml/3.2 https://schemas.opengis.net/gml/3.2.1/gml.xsd">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:25832">
<gml:lowerCorner>0.0 0.0</gml:lowerCorner>
<gml:upperCorner>100.0 100.0</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<Object gml:id="FEATURE_1">
<id>1</id>
<name>dummy</name>
<geom>
<gml:Point xmlns:gml="http://www.opengis.net/gml/3.2" gml:id="GML_1">
<gml:pos>50.000000 50.000000</gml:pos>
</gml:Point>
</geom>
</Object>
</gml:featureMember>
</gml:FeatureCollection>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<FeatureTypeStyle xmlns="http://www.opengis.net/se"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:app="http://www.deegree.org/app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/se http://schemas.opengis.net/se/1.1.0/FeatureStyle.xsd">

<Rule>
<PointSymbolizer><Graphic><Mark><WellKnownName>svgpath://m 8,14 0,-6 h -4.5 c 0,0 0,-7.5 6.6,-7.5 6,0 6.5,7.5 6.6,7.5 l -4.5,0 0,6 z m -4,0 v -2 h 2 v 2 z</WellKnownName><Fill><SvgParameter name="fill">#FF0000</SvgParameter><SvgParameter name="fill-opacity">0.4</SvgParameter></Fill><Stroke><SvgParameter name="stroke">#000000</SvgParameter><SvgParameter name="stroke-width">1</SvgParameter></Stroke></Mark><Size>40</Size>
<Displacement><DisplacementX>0</DisplacementX><DisplacementY>0</DisplacementY></Displacement></Graphic></PointSymbolizer>
</Rule>
</FeatureTypeStyle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2022 by:
- grit graphische Informationstechnik Beratungsgesellschaft mbH -
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact information:
grit graphische Informationstechnik Beratungsgesellschaft mbH
Landwehrstr. 143, 59368 Werne
Germany
http://www.grit.de/
lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/
Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/
e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.style.styling.wkn;

import java.awt.Shape;
import java.net.URL;
import java.util.function.Function;

import org.apache.batik.parser.AWTPathProducer;
import org.apache.batik.parser.ParseException;
import org.apache.batik.parser.PathParser;
import org.deegree.style.styling.mark.WellKnownNameLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SvgPathLoader implements WellKnownNameLoader {

private static final Logger LOG = LoggerFactory.getLogger( SvgPathLoader.class );

public static final String PREFIX = "svgpath://";

@Override
public Shape parse( String wellKnownName, Function<String, URL> resolver ) {
if ( wellKnownName == null || !wellKnownName.startsWith( PREFIX ) )
return null;

String wkn = wellKnownName.substring( PREFIX.length() );

Shape s = null;
AWTPathProducer pathProducer = new AWTPathProducer();
PathParser pp = new PathParser();
pp.setPathHandler( pathProducer );
try {
pp.parse( wkn );
s = pathProducer.getShape();
} catch ( ParseException ex ) {
LOG.warn( "Could not Parse SVGPath {}: {}", wkn, ex.getMessage() );
LOG.trace( "Exception", ex );
}

return s;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.deegree.style.styling.wkn.ShapeLoader
org.deegree.style.styling.wkn.ExtShapeLoader
org.deegree.style.styling.wkn.TrueTypeFontLoader
org.deegree.style.styling.wkn.QGisShapeLoader
#org.deegree.style.styling.wkn.SvgPathLoader
org.deegree.style.styling.wkn.SvgPathLoader
#org.deegree.style.styling.wkn.WKTLoader
#org.deegree.style.styling.wkn.WKTLinearizeLoader
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,18 @@ image::se_wkn_example/extshape_arrow_t_00_10.png[]
<WellKnownName>extshape://arrow?t=0.2&amp;hr=2&amp;ab=0.5</WellKnownName>
----

====== Custom Symbol from SVG path svg://

It is also possible to define a symbol from a SVG path data.
The syntax of SVG path data is described at https://www.w3.org/TR/SVG/paths.html#PathData

.Example of custom symbol with \`svgpath://`
[cols="10,90"]
|===
a|image::se_wkn_example/svgpath_example.png[]
a|`svgpath://m 8,14 0,-6 h -4.5 c 0,0 0,-7.5 6.6,-7.5 6,0 6.5,7.5 6.6,7.5 l -4.5,0 0,6 z m -4,0 v -2 h 2 v 2 z`
|===

====== Use Symbol from character code ttf://

Also TrueType font files can be used as source for symbols.
Expand Down

0 comments on commit d98e284

Please sign in to comment.