예제 #1
0
func (m *Map) newClass(r mss.Rule, layerType string) (b *Block, styled bool) {
	b = &Block{Name: "CLASS"}

	if r.Zoom != mss.AllZoom {
		b.Add("", "# "+r.Zoom.String())
	}
	if l := r.Zoom.First(); l > 0 {
		b.Add("MaxScaleDenom", zoomRanges[l])
	}
	if l := r.Zoom.Last(); l < 22 {
		b.Add("MinScaleDenom", zoomRanges[l+1])
	}
	filter := fmtFilters(r.Filters)
	if filter != "" {
		b.Add("Expression", filter)
	}

	prefixes := mss.SortedPrefixes(r.Properties, []string{"line-", "polygon-", "polygon-pattern-", "text-", "shield-", "marker-", "point-", "building-"})

	for _, p := range prefixes {
		prefixStyled := false
		hidden := false
		r.Properties.SetDefaultInstance(p.Instance)
		switch p.Name {
		case "line-":
			if layerType == "POLYGON" {
				prefixStyled, hidden = m.addPolygonOutlineSymbolizer(b, r)
			} else if layerType == "LINE" {
				prefixStyled, hidden = m.addLineSymbolizer(b, r)
			}
		case "polygon-":
			if layerType == "POLYGON" {
				prefixStyled = m.addPolygonSymbolizer(b, r)
			}
		case "polygon-pattern-":
			prefixStyled = m.addPolygonPatternSymbolizer(b, r)
		case "text-":
			prefixStyled = m.addTextSymbolizer(b, r, layerType == "LINE")
		case "shield-":
			prefixStyled = m.addShieldSymbolizer(b, r)
		case "marker-":
			prefixStyled = m.addMarkerSymbolizer(b, r, layerType == "LINE")
		case "point-":
			prefixStyled = m.addPointSymbolizer(b, r)
		case "building-":
			prefixStyled = m.addBuildingSymbolizer(b, r)
		default:
			log.Println("invalid prefix", p)
		}
		if prefixStyled {
			styled = true
		}
		if hidden {
			b.Add("", NewBlock("STYLE"))
		}

		r.Properties.SetDefaultInstance("")
	}
	return
}
예제 #2
0
func (m *Map) newRule(r mss.Rule) *Rule {
	result := &Rule{}

	if r.Zoom != mss.AllZoom {
		result.Zoom = r.Zoom.String()
	}
	if l := r.Zoom.First(); l > 0 {
		result.MaxScaleDenom = zoomRanges[l]
	}
	if l := r.Zoom.Last(); l < 22 {
		result.MinScaleDenom = zoomRanges[l+1]
	}

	result.Filter = fmtFilters(r.Filters)
	prefixes := mss.SortedPrefixes(r.Properties, []string{"line-", "polygon-", "polygon-pattern-", "text-", "shield-", "marker-", "point-", "building-", "raster-"})

	for _, p := range prefixes {
		r.Properties.SetDefaultInstance(p.Instance)
		switch p.Name {
		case "line-":
			m.addLineSymbolizer(result, r)
		case "line-pattern-":
			m.addLinePatternSymbolizer(result, r)
		case "polygon-":
			m.addPolygonSymbolizer(result, r)
		case "polygon-pattern-":
			m.addPolygonPatternSymbolizer(result, r)
		case "text-":
			m.addTextSymbolizer(result, r)
		case "shield-":
			m.addShieldSymbolizer(result, r)
		case "marker-":
			m.addMarkerSymbolizer(result, r)
		case "point-":
			m.addPointSymbolizer(result, r)
		case "building-":
			m.addBuildingSymbolizer(result, r)
		case "dot-":
			m.addDotSymbolizer(result, r)
		case "raster-":
			m.addRasterSymbolizer(result, r)
		default:
			log.Println("invalid prefix", p)
		}
	}
	r.Properties.SetDefaultInstance("")
	return result
}