コード例 #1
0
ファイル: mapfile.go プロジェクト: nebulon42/magnacarto
func (m *Map) addPolygonOutlineSymbolizer(b *Block, r mss.Rule) (styled bool) {
	if width, ok := r.Properties.GetFloat("line-width"); ok {
		style := NewBlock("STYLE")
		style.AddNonNil("Width", fmtFloat(width*LineWidthFactor*m.scaleFactor, true))
		if c, ok := r.Properties.GetColor("line-color"); ok {
			if opacity, ok := r.Properties.GetFloat("line-opacity"); ok {
				c = color.FadeOut(c, 1-opacity)
			}
			style.AddNonNil("OutlineColor", fmtColor(c, true))
		}
		if v, ok := r.Properties.GetFloatList("line-dasharray"); ok {
			style.Add("", fmtPattern(v, m.scaleFactor, true))
		}
		style.AddDefault("Linecap", fmtKeyword(r.Properties.GetString("line-cap")), "BUTT")
		style.AddDefault("Linejoin", fmtKeyword(r.Properties.GetString("line-join")), "MITER")
		b.Add("", style)
		return true
	}
	return false
}
コード例 #2
0
ファイル: mapfile.go プロジェクト: nebulon42/magnacarto
func (m *Map) addMarkerSymbolizer(b *Block, r mss.Rule, isLine bool) (styled bool) {
	if markerFile, ok := r.Properties.GetString("marker-file"); ok {
		style := NewBlock("STYLE")

		size, sizeOk := r.Properties.GetFloat("marker-height")
		style.AddNonNil("Opacity", fmtFloat(r.Properties.GetFloat("marker-opacity")))
		if avoidEdges, ok := r.Properties.GetBool("marker-avoid-edges"); ok {
			style.AddNonNil("Partials", fmtBool(!avoidEdges, true))
		}

		symOpts := symbolOptions{}

		if transform, ok := r.Properties.GetString("marker-transform"); ok {
			width, wOk := r.Properties.GetFloat("marker-width")
			height, hOk := r.Properties.GetFloat("marker-height")
			if wOk && hOk {
				width *= m.scaleFactor
				height *= m.scaleFactor
				tr, err := parseTransform(transform)
				if err != nil {
					log.Println(err)
				}
				if tr.rotate != 0.0 {
					style.AddNonNil("Angle", fmtFloat(tr.rotate, true))
				}
				if sizeOk && tr.scale != 0.0 {
					size *= tr.scale
				}
				if tr.hasRotateAnchor {
					symOpts.hasAnchor = true
					symOpts.anchorX = (tr.rotateAnchor[0]*m.scaleFactor + width/2) / width
					symOpts.anchorY = (tr.rotateAnchor[1]*m.scaleFactor + height/2) / height
				}
			}
		}
		style.AddNonNil("Size", fmtFloat(size*m.scaleFactor, sizeOk))
		style.Add("SYMBOL", *m.symbolName(markerFile, symOpts))

		// style.AddNonNil("Force", fmtBool(r.Properties.GetBool("marker-allow-overlap")))

		b.Add("", style)
		return true
	}

	if markerType, ok := r.Properties.GetString("marker-type"); ok {
		style := NewBlock("STYLE")

		var size float64
		if markerType == "arrow" {
			style.Add("SYMBOL", *m.arrowSymbol())
			size = 12.0 // matches arrow of mapnik default size
		} else if markerType == "ellipse" {
			style.Add("SYMBOL", *m.ellipseSymbol())
			size = 10.0 // matches arrow of mapnik default size
		} else {
			log.Printf("marker-type %s not supported", markerType)
			return false
		}
		// emulate marker-opacity by fading marker-fill
		if fill, ok := r.Properties.GetColor("marker-fill"); ok {
			if opacity, ok := r.Properties.GetFloat("marker-opacity"); ok {
				style.AddNonNil("Color", fmtColor(color.FadeOut(fill, opacity), true))
			} else {
				style.AddNonNil("Color", fmtColor(fill, true))
			}
		}
		// emulate marker-opacity by fading marker-line-color
		if linecolor, ok := r.Properties.GetColor("marker-line-color"); ok {
			if opacity, ok := r.Properties.GetFloat("marker-opacity"); ok {
				style.AddNonNil("OutlineColor", fmtColor(color.FadeOut(linecolor, opacity), true))
			} else {
				style.AddNonNil("OutlineColor", fmtColor(linecolor, true))
			}
		}

		style.AddNonNil("Width", fmtColor(r.Properties.GetColor("marker-line-width")))

		if transform, ok := r.Properties.GetString("marker-transform"); ok {
			tr, err := parseTransform(transform)
			if err != nil {
				log.Println(err)
			}
			if tr.rotate != 0.0 {
				style.AddNonNil("Angle", fmtFloat(tr.rotate, true))
			}
			if tr.scale != 0.0 {
				size *= tr.scale
			}
		}
		style.AddNonNil("Size", fmtFloat(size*m.scaleFactor, true))

		if isLine {
			if spacing, ok := r.Properties.GetFloat("marker-spacing"); ok {
				style.AddNonNil("Gap", fmtFloat(-spacing*m.scaleFactor, true))
				style.AddNonNil("InitialGap", fmtFloat(spacing*0.5*m.scaleFactor, true))

			} else {
				style.AddNonNil("Gap", fmtFloat(-100*m.scaleFactor, true)) // mapnik default
			}
		}

		b.Add("", style)
		return true
	}

	return false
}
コード例 #3
0
ファイル: mapfile.go プロジェクト: kaiCu/magnacarto
func (m *Map) addMarkerSymbolizer(b *Block, r mss.Rule, isLine bool) (styled bool) {
	if markerFile, ok := r.Properties.GetString("marker-file"); ok {
		style := NewBlock("STYLE")

		style.Add("SYMBOL", *m.symbolName(markerFile))
		style.AddNonNil("Size", fmtFloat(r.Properties.GetFloat("marker-width")))
		style.AddNonNil("Opacity", fmtFloat(r.Properties.GetFloat("marker-opacity")))
		// style.AddNonNil("Force", fmtBool(r.Properties.GetBool("marker-allow-overlap")))

		b.Add("", style)
		return true
	}
	if markerType, ok := r.Properties.GetString("marker-type"); ok {
		style := NewBlock("STYLE")

		var size float64
		if markerType == "arrow" {
			style.Add("SYMBOL", *m.arrowSymbol())
			size = 12.0 // matches arrow of mapnik default size
		} else if markerType == "ellipse" {
			style.Add("SYMBOL", *m.ellipseSymbol())
			size = 10.0 // matches arrow of mapnik default size
		} else {
			log.Printf("marker-type %s not supported", markerType)
			return false
		}
		// emulate marker-opacity by fading marker-fill
		if fill, ok := r.Properties.GetColor("marker-fill"); ok {
			if opacity, ok := r.Properties.GetFloat("marker-opacity"); ok {
				style.AddNonNil("Color", fmtColor(color.FadeOut(fill, opacity), true))
			} else {
				style.AddNonNil("Color", fmtColor(fill, true))
			}
		}
		// emulate marker-opacity by fading marker-line-color
		if linecolor, ok := r.Properties.GetColor("marker-line-color"); ok {
			if opacity, ok := r.Properties.GetFloat("marker-opacity"); ok {
				style.AddNonNil("OutlineColor", fmtColor(color.FadeOut(linecolor, opacity), true))
			} else {
				style.AddNonNil("OutlineColor", fmtColor(linecolor, true))
			}
		}

		style.AddNonNil("Width", fmtColor(r.Properties.GetColor("marker-line-width")))

		if transform, ok := r.Properties.GetString("marker-transform"); ok {
			tr, err := parseTransform(transform)
			if err != nil {
				log.Println(err)
			}
			if tr.rotate != 0.0 {
				style.AddNonNil("Angle", fmtFloat(tr.rotate, true))
			}
			if tr.scale != 0.0 {
				size *= tr.scale
			}
		}
		style.AddNonNil("Size", fmtFloat(size, true))

		if isLine {
			if spacing, ok := r.Properties.GetFloat("marker-spacing"); ok {
				style.AddNonNil("Gap", fmtFloat(-spacing, true))
			} else {
				style.AddNonNil("Gap", fmtFloat(-100, true)) // mapnik default
			}
		}

		b.Add("", style)
		return true
	}

	return false
}