openlayers polygon displays difference not union -



openlayers polygon displays difference not union -

in openlayers, create polygon consisting of 2 linearring objects, using code of form (this in java+gwt, same principle applies js):

list<linearring> linearringlist = new arraylist<linearring>(); list<point> points1 = new arraylist<point>(); ... populate points1 ...; linearringlist.add(new linearring(points1.toarray(new point[points.size()]))); list<point> points2 = new arraylist<point>(); ... populate points2 ...; linearringlist.add(new linearring(points2.toarray(new point[points.size()]))); polygon poly = new polygon(linearringlist.toarray(new linearring[linearringlist.size()])); vectorfeature feature = new vectorfeature(poly); mylayer.addfeature(feature);

when view layer on map, if polygons defined points1 , points2 overlap, see hole:

i'm seeing "xor" of 2 polygons, want see "or" of them instead, ie hole in middle filled in green.

how do this? i'm sure it's display issue in openlayers, can't find flag command anywhere.

the original 2 polygons as:

if displayed on single layer overlap, openlayers not filling in intersecting parts.

the problem adding both linearrings same polygon. rings, after first, defined inner rings of polygon (ie, internal holes), explains unusual intersection behavior seeing -- effort draw inner ring, not in fact inside. see components in documentation. prepare problem, need create 2 separate geometry.polygons , 2 separate feature.vectors , add together both of these layer.vector.

var linearring1 = new openlayers.geometry.linearring(pointlist1); var feature1 = new openlayers.feature.vector( new openlayers.geometry.polygon([linearring1])); var linearring2 = new openlayers.geometry.linearring(pointlist2); var feature2 = new openlayers.feature.vector( new openlayers.geometry.polygon([linearring2])); var layer = new openlayers.layer.vector("layername"); layer.addfeatures([feature1, feature2]);

where create point lists before. can add together attributes , styles each feature vector, or style layer vector, left out clarity.

there no explicit check in openlayers geometry correct, ie, inner rings within outer ring, if hand array of line strings polygon constructor, effort made convert appropriate svg or vml objects, unpredictable results.

openlayers polygon gwt-openlayers

Comments