Ejemplo n.º 1
0
func (m *Map) AddLayer(l mml.Layer, rules []mss.Rule) {
	if l.ScaleFactor != 0.0 {
		prevScaleFactor := m.scaleFactor
		defer func() { m.scaleFactor = prevScaleFactor }()
		m.scaleFactor = l.ScaleFactor
	}
	styles := m.newStyles(rules)
	m.XML.Styles = append(m.XML.Styles, styles...)

	layer := Layer{}
	layer.SRS = &l.SRS
	layer.Name = l.ID
	if !l.Active {
		layer.Status = "off"
	}
	if l.GroupBy != "" {
		layer.GroupBy = l.GroupBy
	}

	if l.ClearLabelCache {
		layer.ClearLabelCache = "on"
	}
	if l.CacheFeatures {
		layer.CacheFeatures = "true"
	}

	z := mss.RulesZoom(rules)
	if z != mss.AllZoom {
		if l := z.First(); l > 0 {
			if m.mapnik2 {
				layer.MaxZoom = zoomRanges[l]
			} else {
				layer.MaxScaleDenom = zoomRanges[l]
			}
		}
		if l := z.Last(); l < 22 {
			if m.mapnik2 {
				layer.MinZoom = zoomRanges[l+1]
			} else {
				layer.MinScaleDenom = zoomRanges[l+1]
			}
		}
	}
	params := m.newDatasource(l.Datasource, rules)
	if params != nil {
		layer.Datasource = &params
	}
	for _, s := range styles {
		layer.StyleNames = append(layer.StyleNames, s.Name)
	}
	m.XML.Layers = append(m.XML.Layers, layer)
}
Ejemplo n.º 2
0
func (m *Map) AddLayer(l mml.Layer, rules []mss.Rule) {
	styles := m.newStyles(rules)
	m.XML.Styles = append(m.XML.Styles, styles...)

	layer := Layer{}
	layer.SRS = &l.SRS
	layer.Name = l.Name
	if !l.Active {
		layer.Status = "off"
	}
	if l.GroupBy != "" {
		layer.GroupBy = l.GroupBy
	}
	z := mss.RulesZoom(rules)
	if z != mss.AllZoom {
		if l := z.First(); l > 0 {
			if m.mapnik2 {
				layer.MaxZoom = zoomRanges[l]
			} else {
				layer.MaxScaleDenom = zoomRanges[l]
			}
		}
		if l := z.Last(); l < 22 {
			if m.mapnik2 {
				layer.MinZoom = zoomRanges[l+1]
			} else {
				layer.MinScaleDenom = zoomRanges[l+1]
			}
		}
	}
	params := m.newDatasource(l.Datasource, rules)
	if params != nil {
		layer.Datasource = &params
	}
	for _, s := range styles {
		layer.StyleNames = append(layer.StyleNames, s.Name)
	}
	m.XML.Layers = append(m.XML.Layers, layer)
}
Ejemplo n.º 3
0
func (m *Map) AddLayer(layer mml.Layer, rules []mss.Rule) {
	if len(rules) == 0 {
		return
	}

	if layer.ScaleFactor != 0.0 {
		prevScaleFactor := m.scaleFactor
		defer func() { m.scaleFactor = prevScaleFactor }()
		m.scaleFactor = layer.ScaleFactor
	}

	styles := []classGroup{}
	style := classGroup{}

	var t string
	if layer.Type == mml.LineString {
		t = "LINE"
	} else if layer.Type == mml.Polygon {
		t = "POLYGON"
	} else if layer.Type == mml.Point {
		t = "POINT"
	} else {
		log.Println("unknown geometry type for layer", layer.ID)
		return
	}

	for _, r := range rules {
		styleName := r.Layer
		if r.Attachment != "" {
			styleName += "-" + r.Attachment
		}
		if style.name != styleName {
			if len(style.classes) > 0 {
				styles = append(styles, style)
			}
			style = classGroup{name: styleName}
		}
		if v, ok := r.Properties.GetFloat("opacity"); ok {
			style.opacity = v
		}
		c, ok := m.newClass(r, t)
		if ok {
			style.classes = append(style.classes, *c)
		}
	}

	if len(style.classes) > 0 {
		styles = append(styles, style)
	}

	for _, style := range styles {
		l := NewBlock("LAYER")
		l.Add("name", style.name)

		z := mss.RulesZoom(rules)
		if z := z.First(); z > 0 {
			l.Add("MaxScaleDenom", zoomRanges[z])
		}
		if z := z.Last(); z < 22 {
			l.Add("MinScaleDenom", zoomRanges[z+1])
		}

		if style.opacity != 0 {
			l.AddNonNil("Opacity", fmtFloat(style.opacity*m.scaleFactor, true))
		}

		if layer.Active {
			l.Add("status", "ON")
		} else {
			l.Add("status", "OFF")
		}
		l.Add("type", t)

		if layer.PostLabelCache {
			l.Add("postlabelcache", "true")
		}

		m.addDatasource(&l, layer.Datasource, rules)
		for _, c := range style.classes {
			l.Add("", c)
		}
		m.Layers.Add("", l)
	}
}
Ejemplo n.º 4
0
func (m *Map) AddLayer(layer mml.Layer, rules []mss.Rule) {
	if len(rules) == 0 {
		return
	}

	styles := []classGroup{}
	style := classGroup{}

	var t string
	if layer.Type == mml.LineString {
		t = "LINE"
	} else if layer.Type == mml.Polygon {
		t = "POLYGON"
	} else if layer.Type == mml.Point {
		t = "POINT"
	} else {
		log.Println("unknown geometry type for layer", layer.Name)
		return
	}

	for _, r := range rules {
		styleName := r.Layer
		if r.Attachment != "" {
			styleName += "-" + r.Attachment
		}
		if style.name != styleName {
			if len(style.classes) > 0 {
				styles = append(styles, style)
			}
			style = classGroup{name: styleName}
		}
		c, ok := m.newClass(r, t)
		if ok {
			style.classes = append(style.classes, *c)
		}
	}

	if len(style.classes) > 0 {
		styles = append(styles, style)
	}

	for _, style := range styles {
		l := NewBlock("LAYER")
		l.Add("name", style.name)

		z := mss.RulesZoom(rules)
		if z := z.First(); z > 0 {
			l.Add("MaxScaleDenom", zoomRanges[z])
		}
		if z := z.Last(); z < 22 {
			l.Add("MinScaleDenom", zoomRanges[z+1])
		}

		if layer.Active {
			l.Add("status", "ON")
		} else {
			l.Add("status", "OFF")
		}
		l.Add("type", t)

		m.addDatasource(&l, layer.Datasource, rules)
		for _, c := range style.classes {
			l.Add("", c)
		}
		m.Layers.Add("", l)
	}
}